Last active
February 4, 2019 16:49
-
-
Save vsoch/49fa2de2adb7859347a4b9f26a767875 to your computer and use it in GitHub Desktop.
An example script to run a Singularity container for a user on the list
This file contains 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
#!/bin/bash | |
# Before you run this script, pull your container somewhere, and then provide | |
# the full path as an argument to this script | |
# If your $HOME is small, export to where you have more space like scratch | |
# export SINGULARITY_CACHEDIR=$SCRATCH/.singularity | |
# singularity pull --name antismash-standalone-4.2.0.sif docker://antismash/standalone:4.2.0 | |
# Then provide the full container path as the last argument. | |
set -o errexit | |
set -o nounset | |
function realpath() { | |
echo $(readlink -f $1 2>/dev/null || python -c "import sys; import os; print(os.path.realpath(os.path.expanduser(sys.argv[1])))" $1) | |
} | |
# handle input file | |
readonly INPUT_FILE=$(basename $1) | |
readonly INPUT_DIR=$(dirname $(realpath $1)) | |
shift | |
# Load singularity as module if you need to here, etc. | |
# module load singularity | |
# handle output file | |
readonly OUTPUT_DIR=$(realpath $1) | |
shift | |
# This is the container you pulled above, the full path, something like: | |
# $SCRATCH/.singularity/antismash-standalone-4.2.0.sif | |
CONTAINER_NAME=${1:-} | |
shift | |
if [ ! -f "${CONTAINER_NAME}" ]; then | |
echo "$CONTAINER_NAME not found."; | |
exit 1; | |
fi | |
# Links within the container | |
readonly CONTAINER_SRC_DIR=/input | |
readonly CONTAINER_DST_DIR=/output | |
if [ ! -d ${OUTPUT_DIR} ]; then | |
mkdir ${OUTPUT_DIR} | |
fi | |
singularity run --bind ${INPUT_DIR}:${CONTAINER_SRC_DIR} --bind ${OUTPUT_DIR}:${CONTAINER_DST_DIR} "${CONTAINER_NAME}" "${@}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment