Created
September 28, 2022 13:04
-
-
Save joao-aguizo/ea9cdaf924dc8990a423c9c8b59904e2 to your computer and use it in GitHub Desktop.
A documented example of a Singularity container recipe.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Bootstrap: docker | |
From: ubuntu | |
# Stage: build | |
# Setup during build process. | |
# NOTE: According to docs, this SHOULD NOT be used to | |
# copy files into the container, use '%files' section instead. | |
%setup | |
touch /file1 | |
touch ${SINGULARITY_ROOTFS}/file2 | |
# Provides a safer way of copying content to the container. | |
# NOTE: This is the recommended way of doing so. Better than using | |
# '%setup' section for the matter. | |
%files | |
/file1 | |
/file1 /opt | |
# Container RUNTIME setup of environment. | |
# NOTE: These variables are not made available during BUILD | |
# time, for define them as well in the '%post' section. | |
%environment | |
export LISTEN_PORT=12345 | |
export LC_ALL=C | |
# Tool downloading and installations, write configurations, create directories, etc. | |
# NOTE: Should be used to setup BUILD time environment variables. | |
%post | |
apt-get update && apt-get install -y netcat | |
NOW=`date` | |
echo "export NOW=\"${NOW}\"" >> $SINGULARITY_ENVIRONMENT | |
# Called upon container 'singularity run' command. | |
# NOTE: The content of this section is written in a file inside the container, so | |
# that it can be run once the aforementioned command is issued. | |
%runscript | |
echo "Container was created $NOW" | |
echo "Arguments received: $*" | |
exec echo "$@" | |
# Called upon container's 'singularity instance start' command. | |
# NOTE: The content of this section is written in a file inside the container, so | |
# that it can be run once the aforementioned command is issued. | |
%startscript | |
nc -lp $LISTEN_PORT | |
# Runs at the very end of the BUILD process and can be used to validate the container. | |
%test | |
grep -q NAME=\"Ubuntu\" /etc/os-release | |
if [ $? -eq 0 ]; then | |
echo "Container base is Ubuntu as expected." | |
else | |
echo "Container base is not Ubuntu." | |
fi | |
# Adds metadata to the container inside '/.singularity.d/labels.json'. | |
%labels | |
Author [email protected] | |
Version v0.0.1 | |
# Adds metadata into the container that can be accessed through | |
# 'singularity run-help' command. | |
%help | |
This is a demo container used to illustrate a def file that uses all | |
supported sections. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment