diff --git a/.gitlabci/build.sh b/.gitlabci/build.sh new file mode 100644 index 0000000000000000000000000000000000000000..bd76f40e3b814ff957c6430977446855567bf15f --- /dev/null +++ b/.gitlabci/build.sh @@ -0,0 +1,175 @@ +#!/bin/bash + +# build.sh will build a Singularity container. It's not overly complicated. +# +# USAGE: build.sh --uri collection-name/container-name --cli registry Singularity +# build.sh --uri collection-name/container-name --cli registry +# build.sh Singularity + +# Copyright (C) 2017-2018 Vanessa Sochat. + +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or (at your +# option) any later version. + +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public +# License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +set -o errexit +set -o nounset + +function usage() { + + echo "USAGE: build [recipe] [options]" + echo "" + echo "OPTIONS: + + Image Format + --uri -u if uploading, a uri to give to sregistry + --cli -c the sregistry client to use (if uploading) + --help -h show this help and exit + " +} + +# --- Option processing -------------------------------------------------------- + +uri="" +cli="" +tag="" + +while true; do + case ${1:-} in + -h|--help|help) + usage + exit 0 + ;; + -u|-uri) + shift + uri="${1:-}" + shift + ;; + -t|--tag) + shift + tag="${1:-}" + shift + ;; + -c|--cli) + shift + cli="${1:-}" + shift + ;; + \?) printf "illegal option: -%s\n" "${1:-}" >&2 + usage + exit 1 + ;; + -*) + printf "illegal option: -%s\n" "${1:-}" >&2 + usage + exit 1 + ;; + *) + break; + ;; + esac +done + +################################################################################ +### Recipe File ################################################################ +################################################################################ + + +if [ $# == 0 ] ; then + recipe="Singularity" +else + recipe=$1 +fi + +echo "" +echo "Image Recipe: ${recipe}" + + +################################################################################ +### Storage Client ############################################################# +################################################################################ + +is_valid_client () { + local e match="$1" + shift + for e; do [[ "$e" == "$match" ]] && return 0; done + return 1 +} + +# Test if client is valid + +clients=("google-storage" "registry" "globus" "dropbox" "google-drive") + +if [ "${cli}" != "" ]; then + is_valid_client "${cli}" "${clients[@]}" + if [ $? -ne 0 ]; then + echo "${cli} is not a valid choice! Choose from ${clients[@]}"; + exit 1 + fi + echo "Storage Client: ${cli}" +else + echo "Storage Client: none" +fi + + +################################################################################ +### Build! ##################################################################### +################################################################################ + +# Continue if the image recipe is found + +if [ -f "$recipe" ]; then + + imagefile="${recipe}.simg" + + echo "Creating $imagefile using $recipe..." + singularity build $imagefile $recipe + + # If the image is successfully built, test it and upload (examples) + + if [ -f "${imagefile}" ]; then + + # Example testing using run (you could also use test command) + + echo "Testing the image... Marco!" + singularity exec $imagefile echo "Polo!" + + # Example sregistry commands to push to endpoints + + if [ "${cli}" != "" ]; then + + # If the uri isn't provided, he gets a robot name + if [ "${uri}" == "" ]; then + uri=$(python -c "from sregistry.logger.namer import RobotNamer; bot=RobotNamer(); print(bot.generate())") + fi + + # If a tag is provided, add to uri + if [ "${tag}" != "" ]; then + uri="${uri}:${tag}" + fi + + echo "Pushing ${uri} to ${cli}://" + echo "SREGISTRY_CLIENT=${cli} sregistry push --name ${uri} ${imagefile}" + SREGISTRY_CLIENT="${cli}" sregistry push --name "${uri}" "${imagefile}" + + else + echo "Skipping upload. Image $imagefile is finished!" + fi + + fi + +else + + echo "Singularity recipe ${recipe} not found!" + exit 1 + +fi diff --git a/.gitlabci/setup.sh b/.gitlabci/setup.sh new file mode 100644 index 0000000000000000000000000000000000000000..e151a8f612a6f9e081ea6168b251725481a1da4b --- /dev/null +++ b/.gitlabci/setup.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +apt-get update && apt-get install -y wget git \ + build-essential \ + squashfs-tools \ + libtool \ + autotools-dev \ + libarchive-dev \ + automake \ + autoconf \ + uuid-dev \ + libssl-dev + + +sed -i -e 's/^Defaults\tsecure_path.*$//' /etc/sudoers + +# Check Python + +echo "Python Version:" +python --version +pip install sregistry[all] +sregistry version + +echo "sregistry Version:" + +# Install Singularity + +cd /tmp && \ + git clone -b vault/release-2.5 https://www.github.com/sylabs/singularity.git + cd singularity && \ + ./autogen.sh && \ + ./configure --prefix=/usr/local && \ + make -j8 && make install diff --git a/.gitlabci/sregistry-gitlab.png b/.gitlabci/sregistry-gitlab.png new file mode 100644 index 0000000000000000000000000000000000000000..a14e917a20fb32011329af6bc6abd04012acd0d6 Binary files /dev/null and b/.gitlabci/sregistry-gitlab.png differ diff --git a/.gitlabci/sregistry-gitlab.xcf b/.gitlabci/sregistry-gitlab.xcf new file mode 100644 index 0000000000000000000000000000000000000000..f2742162bfc602f92d3d9c5cd573f29e334e042d Binary files /dev/null and b/.gitlabci/sregistry-gitlab.xcf differ