Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Singularity
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IMGW
Singularity
Commits
d9a9c953
Commit
d9a9c953
authored
2 years ago
by
Michael Blaschek
Browse files
Options
Downloads
Patches
Plain Diff
addedgitlab ci for singularity build and push to repo
parent
b8e5efe0
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.gitlab-ci.yml
+36
-0
36 additions, 0 deletions
.gitlab-ci.yml
.gitlabci/build.sh
+177
-0
177 additions, 0 deletions
.gitlabci/build.sh
with
213 additions
and
0 deletions
.gitlab-ci.yml
0 → 100644
+
36
−
0
View file @
d9a9c953
image
:
name
:
quay.io/singularity/singularity:v3.7.3
entrypoint
:
[
"
/bin/sh"
,
"
-c"
]
build
:
when
:
manual
script
:
-
/bin/bash .gitlabci/build.sh Singularity
# step 1. build the container!
# You can add any other sregistry push commands here, and specify a client
# (and make sure your define the encrypted environment credentials in gitlab
# to push to your storage locations of choice
-
mkdir -p build && cp *.sif build
-
mkdir -p build && cp Singularity* build
# Step 2. Take a look at "artifacts" below and add the paths you want added
# You can also add the entire build folder. You can also upload to storage
# clients defined by sregistry, here are some examples
# https://singularityhub.github.io/sregistry-cli/clients
# Environment variables must be defined in CI encrypted secrets/settings
# https://code.stanford.edu/help/ci/variables/README#variables).
#- /bin/bash build.sh --uri collection/container --cli google-storage Singularity
#- /bin/bash build.sh --uri collection/container --cli google-drive Singularity
#- /bin/bash build.sh --uri collection/container --cli globus Singularity
#- /bin/bash build.sh --uri collection/container --cli registry Singularity
# This is where you can save job artifacts
# https://docs.gitlab.com/ee/user/project/pipelines/job_artifacts.html
# You can specify the path to containers or the build folder to save.
# Don't forget to save your recipes too!
artifacts
:
paths
:
-
build/Singularity.sif
-
build/Singularity
This diff is collapsed.
Click to expand it.
.gitlabci/build.sh
0 → 100644
+
177
−
0
View file @
d9a9c953
#!/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-2020 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
}
.sif"
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
}
://"
# singularity
# 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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment