J.U.S.T. Singularity Functions

just_singularity_functions.bsh
singular_defaultify
just singularity import

Converts a docker image to a singularity image, writing the image to the just directory.

Arguments:
  • $1 - Singularity image path

  • [$2 …] - Additional arguments to pass along to singularity build (build spec). If no additional arguments are given, then the spec file is read in from stdin.

Parameters:
  • SINGULARITY_DOCKER_SOCKET - An array to specify a custom docker socket to connect to docker. If SINGULARITY_DOCKER_SOCKET is not an array, it is converted to an array where whitespaces will be split. Default: (--mount source=/var/run/docker.sock,destination=/var/run/docker.sock,type=bind)

  • SINGULARITY_IMAGE_UID - The user id to set the image to after it is built (as root). Default: current uid

  • SINGULARITY_IMAGE_GID - The group id to set the image to after it is built (as root). Default: current gid

  • SINGULARITY_CMD - Optional name for a singularity executable to use. If this is not set, the default behavior is to create a docker and install singularity in there. Using SINGULARITY_CMD ignores SINGULARITY_DOCKER_SOCKET, SINGULARITY_IMAGE_UID, and SINGULARITY_IMAGE_GID. Spaces are treated as multiple arguments.

  • SINGULARITY_IMPORT_FORCE - Setting this variable to anything other than null will add the --force flag to singularity build, overwriting the destination image if it already exists without prompting. Default behavior is to prompt and wait for user input, and defaults to “no” if there is no stdin.

just singularity exec
just singularity instance-start
just singularity run
just singularity shell
just singularity test

Starts a singularity container using singularity_functions.bsh Singularity.

just singular-compose

singular-compose take the equivalent place of docker compose, but for singularity. This does not use singularity-compose, instead it is a much simpler and plainer bash version.

Arguments:

[-f {filename} | --file {filename}] - Optionally specify one or more singular-compose files, and ignoring the default found singular-compose.env file.

A singular-compose file (default singular-compose.env) is written 100% in bash and gives you the freedom to do anything you need in it. It is designed to be sourced by singular-compose and has few requirements.

  • instances - must be an array of names of instances. If an instance name is not included here, it will be ignored by singular-compose. You should use the += operator when setting instances, so that multiple files can work together

  • {instance_name}_image - The filename of the singularity image.

  • [{instance_name}_volumes] - An array of bind mounts that will have the -B flag added to them.

  • [{instance_name}_environment] - A paired array of key/value pairs of environment variables that will be set in the singularity container. Even indexes are keys, odd indexes are values (if contiguous).

  • [{instance_name}_singular_flags] - List of extra flags to be passed to the singularity subcommand.

Example singular-compose.env

singular-compose.env
instances+=(django mysql)

# I can even include other compose files
source "${DJANGO_SOURCE_DIR}/singular-compose2.env"

django_environment=(
  TZ "${TZ}"
  DISPLAY "${DISPLAY}"
  JUSTFILE /src/docker/django.Justfile
  JUST_SETTINGS /src/django.env
)
django_volumes=(
  "${DJANGO_SOURCE_DIR}:${DJANGO_INSTALL_DIR_DOCKER}:ro"
  "${VSI_COMMON_DIR}:/vsi:ro"
)
django_singular_flags=(-c -e --nv)
: ${django_image=${DJANGO_CWD}/django_${DJANGO_USERNAME}.simg}

# I can even just copy other arrays (like an anchor)
mysql_environment=("${django_environment[@]}")
# Add a data dir, but copy all but the first volume from django
mysql_volumes=(
  "${DJANGO_SOURCE_DIR}/singular/data:/data:rw"
  "${django_volumes[@]:1}"
)
mysql_singular_flags=("${django_singular_flags[@]}")
: ${mysql_image=${DJANGO_CWD}/mysql_${DJANGO_USERNAME}.simg}

singular-compose currently supports a few subcommands: