#!/usr/bin/env bash # Helper script that builds and launches the Docker container. # --------------------------------------------------------------------- function print_help { echo "`basename "$0"` {options}" echo " Build and launch the \"vasl-templates\" container." echo echo " -p --port Web server port number." echo " -v --vasl-vmod Path to the VASL .vmod file." echo " -e --vasl-extensions Path to the VASL extensions directory." echo " -h --chapter-h Path to the Chapter H notes directory." echo " -u --user-files Path to the user files directory." echo echo " -t --tag Docker tag." echo " -d --detach Detach from the container and let it run in the background." echo " --no-build Launch the container as-is (i.e. without rebuilding it first)." echo " --build-network Docker network to use when building the container." echo " --run-network Docker network to use when running the container." echo cat <&2 exit 1 ;; esac done # check if a VASL .vmod file has been specified if [ -n "$VASL_MOD_LOCAL" ]; then if [ ! -f "$VASL_MOD_LOCAL" ]; then echo "Can't find the VASL .vmod file: $VASL_MOD_LOCAL" exit 1 fi VASL_MOD=/data/vasl.vmod VASL_MOD_VOLUME="--volume `readlink -f "$VASL_MOD_LOCAL"`:$VASL_MOD" VASL_MOD_ENV="--env VASL_MOD=$VASL_MOD" fi # check if a VASL extensions directory has been specified if [ -n "$VASL_EXTNS_LOCAL" ]; then if [ ! -d "$VASL_EXTNS_LOCAL" ]; then echo "Can't find the VASL extensions directory: $_EXTNS_DIR_LOCAL" exit 1 fi VASL_EXTNS=/data/vasl-extensions/ VASL_EXTNS_VOLUME="--volume `readlink -f "$VASL_EXTNS_LOCAL"`:$VASL_EXTNS" VASL_EXTNS_ENV="--env VASL_EXTNS_DIR=$VASL_EXTNS" fi # check if a Chapter H notes directory has been specified if [ -n "$CHAPTER_H_NOTES_LOCAL" ]; then if [ ! -d "$CHAPTER_H_NOTES_LOCAL" ]; then echo "Can't find the Chapter H notes directory: $CHAPTER_H_NOTES_LOCAL" exit 1 fi CHAPTER_H_NOTES=/data/chapter-h-notes/ CHAPTER_H_NOTES_VOLUME="--volume `readlink -f "$CHAPTER_H_NOTES_LOCAL"`:$CHAPTER_H_NOTES" CHAPTER_H_NOTES_ENV="--env CHAPTER_H_NOTES_DIR=$CHAPTER_H_NOTES" fi # check if a user files directory has been specified if [ -n "$USER_FILES_LOCAL" ]; then if [ ! -d "$USER_FILES_LOCAL" ]; then echo "Can't find the user files directory: $USER_FILES_LOCAL" exit 1 fi USER_FILES=/data/user-files/ USER_FILES_VOLUME="--volume `readlink -f "$USER_FILES_LOCAL"`:$USER_FILES" USER_FILES_ENV="--env USER_FILES_DIR=$USER_FILES" fi # build the container if [ -z "$NO_BUILD" ]; then echo Building the \"$TAG\" container... docker build $BUILD_NETWORK --tag vasl-templates:$TAG . 2>&1 \ | sed -e 's/^/ /' if [ ${PIPESTATUS[0]} -ne 0 ]; then exit 10 ; fi echo fi # launch the container echo Launching the \"$TAG\" container... docker run \ --publish $PORT:5010 \ --name vasl-templates \ $VASL_MOD_VOLUME $VASL_EXTNS_VOLUME $CHAPTER_H_NOTES_VOLUME $USER_FILES_VOLUME \ $VASL_MOD_ENV $VASL_EXTNS_ENV $CHAPTER_H_NOTES_ENV $USER_FILES_ENV \ $RUN_NETWORK $DETACH \ -it --rm \ vasl-templates:$TAG \ 2>&1 \ | sed -e 's/^/ /' exit ${PIPESTATUS[0]}