Tidied up the Docker launcher script.

master
Pacman Ghost 3 years ago
parent 48896113ae
commit bc5cd8db43
  1. 245
      run-container.sh

@ -3,96 +3,37 @@
# --------------------------------------------------------------------- # ---------------------------------------------------------------------
function get_target { function main
local type=$1 {
local target=$2 # initialize
cd `dirname "$0"`
PORT=5010
VASSAL=
VASL_MOD=
VASL_EXTNS=
VASL_BOARDS=
CHAPTER_H_NOTES=
USER_FILES=
TEMPLATE_PACK=
IMAGE_TAG=latest
CONTAINER_NAME=vasl-templates
DETACH=
NO_BUILD=
BUILD_NETWORK=
RUN_NETWORK=
CONTROL_TESTS_PORT=
TEST_DATA_VASSAL=
TEST_DATA_VASL_MODS=
# check that the target exists # parse the command-line arguments
if [ "$type" == "FILE" ]; then if [ $# -eq 0 ]; then
test -f "$target" || return
elif [ "$type" == "DIR" ]; then
test -d "$target" || return
elif [ "$type" == "FILE-OR-DIR" ]; then
ls "$target" >/dev/null 2>&1 || return
fi
# convert the target to a full path
# FUDGE! I couldn't get the "docker run" command to work with spaces in the volume targets (although printing
# the command out, then copy-and-pasting it into the terminal worked fine) (and no, using ${var@Q} didn't help).
# So, the next best thing is to allow users to create symlinks to the targets :-/
echo $(realpath --no-symlinks "$target" )
}
# ---------------------------------------------------------------------
function print_help {
echo "`basename "$0"` {options}"
cat <<EOM
Build and launch the "vasl-templates" container.
-p --port Web server port number.
--vassal VASSAL installation directory.
-v --vasl Path to the VASL module file (.vmod).
-e --vasl-extensions Path to the VASL extensions directory.
--boards Path to the VASL boards.
--chapter-h Path to the Chapter H notes directory.
--user-files Path to the user files directory.
-k --template-pack Path to a user-defined template pack.
-t --tag Docker image tag.
--name Docker container name.
-d --detach Detach from the container and let it run in the background.
--no-build Launch the container as-is (i.e. without rebuilding the image first).
--build-network Docker network to use when building the image.
--run-network Docker network to use when running the container.
Options for the test suite:
--control-tests-port Remote test control port number.
--test-data-vassal Directory containing VASSAL releases.
--test-data-vasl-mods Directory containing VASL modules.
NOTE: If the port the webapp server is listening on *inside* the container is different
to the port exposed *outside* the container, webdriver image generation (e.g. Shift-Click
on a snippet button, or Chapter H content as images) may not work properly. This is because
a web browser is launched internally with snippet HTML and a screenshot taken of it, but
the HTML will contain links to the webapp server that work from outside the container,
but if those links don't resolve from inside the container, you will get broken images.
In this case, you will need to make such links resolve from inside the container e.g. by
port-forwarding, or via DNS.
EOM
}
# ---------------------------------------------------------------------
# initialize
cd `dirname "$0"`
PORT=5010
VASSAL=
VASL_MOD=
VASL_EXTNS=
VASL_BOARDS=
CHAPTER_H_NOTES=
USER_FILES=
TEMPLATE_PACK=
IMAGE_TAG=latest
CONTAINER_NAME=vasl-templates
DETACH=
NO_BUILD=
BUILD_NETWORK=
RUN_NETWORK=
CONTROL_TESTS_PORT=
TEST_DATA_VASSAL=
TEST_DATA_VASL_MODS=
# parse the command-line arguments
if [ $# -eq 0 ]; then
print_help print_help
exit 0 exit 0
fi fi
params="$(getopt -o p:v:e:k:t:d -l port:,control-tests-port:,vassal:,vasl:,vasl-extensions:,boards:,chapter-h:,template-pack:,user-files:,tag:,name:,detach,no-build,build-network:,run-network:,test-data-vassal:,test-data-vasl-mods:,help --name "$0" -- "$@")" params="$(getopt -o p:v:e:k:t:d -l port:,control-tests-port:,vassal:,vasl:,vasl-extensions:,boards:,chapter-h:,template-pack:,user-files:,tag:,name:,detach,no-build,build-network:,run-network:,test-data-vassal:,test-data-vasl-mods:,help --name "$0" -- "$@")"
if [ $? -ne 0 ]; then exit 1; fi if [ $? -ne 0 ]; then exit 1; fi
eval set -- "$params" eval set -- "$params"
while true; do while true; do
case "$1" in case "$1" in
-p | --port) -p | --port)
PORT=$2 PORT=$2
@ -157,10 +98,10 @@ while true; do
echo "Unknown option: $1" >&2 echo "Unknown option: $1" >&2
exit 1 ;; exit 1 ;;
esac esac
done done
# check if a VASSAL directory has been specified # check if a VASSAL directory has been specified
if [ -n "$VASSAL" ]; then if [ -n "$VASSAL" ]; then
target=$( get_target DIR "$VASSAL" ) target=$( get_target DIR "$VASSAL" )
if [ -z "$target" ]; then if [ -z "$target" ]; then
echo "Can't find the VASSAL directory: $VASSAL" echo "Can't find the VASSAL directory: $VASSAL"
@ -169,10 +110,10 @@ if [ -n "$VASSAL" ]; then
mpoint=/data/vassal/ mpoint=/data/vassal/
VASSAL_VOLUME="--volume $target:$mpoint" VASSAL_VOLUME="--volume $target:$mpoint"
VASSAL_ENV="--env VASSAL_DIR=$mpoint --env VASSAL_DIR_TARGET=$target" VASSAL_ENV="--env VASSAL_DIR=$mpoint --env VASSAL_DIR_TARGET=$target"
fi fi
# check if a VASL module file has been specified # check if a VASL module file has been specified
if [ -n "$VASL_MOD" ]; then if [ -n "$VASL_MOD" ]; then
target=$( get_target FILE "$VASL_MOD" ) target=$( get_target FILE "$VASL_MOD" )
if [ -z "$target" ]; then if [ -z "$target" ]; then
echo "Can't find the VASL .vmod file: $VASL_MOD" echo "Can't find the VASL .vmod file: $VASL_MOD"
@ -181,10 +122,10 @@ if [ -n "$VASL_MOD" ]; then
mpoint=/data/vasl.vmod mpoint=/data/vasl.vmod
VASL_MOD_VOLUME="--volume $target:$mpoint" VASL_MOD_VOLUME="--volume $target:$mpoint"
VASL_MOD_ENV="--env VASL_MOD=$mpoint --env VASL_MOD_TARGET=$target" VASL_MOD_ENV="--env VASL_MOD=$mpoint --env VASL_MOD_TARGET=$target"
fi fi
# check if a VASL extensions directory has been specified # check if a VASL extensions directory has been specified
if [ -n "$VASL_EXTNS" ]; then if [ -n "$VASL_EXTNS" ]; then
target=$( get_target DIR "$VASL_EXTNS" ) target=$( get_target DIR "$VASL_EXTNS" )
if [ -z "$target" ]; then if [ -z "$target" ]; then
echo "Can't find the VASL extensions directory: $VASL_EXTNS" echo "Can't find the VASL extensions directory: $VASL_EXTNS"
@ -193,10 +134,10 @@ if [ -n "$VASL_EXTNS" ]; then
mpoint=/data/vasl-extensions/ mpoint=/data/vasl-extensions/
VASL_EXTNS_VOLUME="--volume $target:$mpoint" VASL_EXTNS_VOLUME="--volume $target:$mpoint"
VASL_EXTNS_ENV="--env VASL_EXTNS_DIR=$mpoint --env VASL_EXTNS_DIR_TARGET=$target" VASL_EXTNS_ENV="--env VASL_EXTNS_DIR=$mpoint --env VASL_EXTNS_DIR_TARGET=$target"
fi fi
# check if a VASL boards directory has been specified # check if a VASL boards directory has been specified
if [ -n "$VASL_BOARDS" ]; then if [ -n "$VASL_BOARDS" ]; then
target=$( get_target DIR "$VASL_BOARDS" ) target=$( get_target DIR "$VASL_BOARDS" )
if [ -z "$target" ]; then if [ -z "$target" ]; then
echo "Can't find the VASL boards directory: $VASL_BOARDS" echo "Can't find the VASL boards directory: $VASL_BOARDS"
@ -205,10 +146,10 @@ if [ -n "$VASL_BOARDS" ]; then
mpoint=/data/boards/ mpoint=/data/boards/
VASL_BOARDS_VOLUME="--volume $target:$mpoint" VASL_BOARDS_VOLUME="--volume $target:$mpoint"
VASL_BOARDS_ENV="--env BOARDS_DIR=$mpoint --env BOARDS_DIR_TARGET=$target" VASL_BOARDS_ENV="--env BOARDS_DIR=$mpoint --env BOARDS_DIR_TARGET=$target"
fi fi
# check if a Chapter H notes directory has been specified # check if a Chapter H notes directory has been specified
if [ -n "$CHAPTER_H_NOTES" ]; then if [ -n "$CHAPTER_H_NOTES" ]; then
target=$( get_target DIR "$CHAPTER_H_NOTES" ) target=$( get_target DIR "$CHAPTER_H_NOTES" )
if [ -z "$target" ]; then if [ -z "$target" ]; then
echo "Can't find the Chapter H notes directory: $CHAPTER_H_NOTES" echo "Can't find the Chapter H notes directory: $CHAPTER_H_NOTES"
@ -217,10 +158,10 @@ if [ -n "$CHAPTER_H_NOTES" ]; then
mpoint=/data/chapter-h-notes/ mpoint=/data/chapter-h-notes/
CHAPTER_H_NOTES_VOLUME="--volume $target:$mpoint" CHAPTER_H_NOTES_VOLUME="--volume $target:$mpoint"
CHAPTER_H_NOTES_ENV="--env CHAPTER_H_NOTES_DIR=$mpoint --env CHAPTER_H_NOTES_DIR_TARGET=$target" CHAPTER_H_NOTES_ENV="--env CHAPTER_H_NOTES_DIR=$mpoint --env CHAPTER_H_NOTES_DIR_TARGET=$target"
fi fi
# check if a user files directory has been specified # check if a user files directory has been specified
if [ -n "$USER_FILES" ]; then if [ -n "$USER_FILES" ]; then
target=$( get_target DIR "$USER_FILES" ) target=$( get_target DIR "$USER_FILES" )
if [ -z "$target" ]; then if [ -z "$target" ]; then
echo "Can't find the user files directory: $USER_FILES" echo "Can't find the user files directory: $USER_FILES"
@ -229,10 +170,10 @@ if [ -n "$USER_FILES" ]; then
mpoint=/data/user-files/ mpoint=/data/user-files/
USER_FILES_VOLUME="--volume $target:$mpoint" USER_FILES_VOLUME="--volume $target:$mpoint"
USER_FILES_ENV="--env USER_FILES_DIR=$mpoint --env USER_FILES_DIR_TARGET=$target" USER_FILES_ENV="--env USER_FILES_DIR=$mpoint --env USER_FILES_DIR_TARGET=$target"
fi fi
# check if a template pack has been specified # check if a template pack has been specified
if [ -n "$TEMPLATE_PACK" ]; then if [ -n "$TEMPLATE_PACK" ]; then
# NOTE: The template pack can either be a file (ZIP) or a directory. # NOTE: The template pack can either be a file (ZIP) or a directory.
target=$( get_target FILE-OR-DIR "$TEMPLATE_PACK" ) target=$( get_target FILE-OR-DIR "$TEMPLATE_PACK" )
if [ -z "$target" ]; then if [ -z "$target" ]; then
@ -242,16 +183,16 @@ if [ -n "$TEMPLATE_PACK" ]; then
mpoint=/data/template-pack mpoint=/data/template-pack
TEMPLATE_PACK_VOLUME="--volume $target:$mpoint" TEMPLATE_PACK_VOLUME="--volume $target:$mpoint"
TEMPLATE_PACK_ENV="--env DEFAULT_TEMPLATE_PACK=$mpoint --env DEFAULT_TEMPLATE_PACK_TARGET" TEMPLATE_PACK_ENV="--env DEFAULT_TEMPLATE_PACK=$mpoint --env DEFAULT_TEMPLATE_PACK_TARGET"
fi fi
# check if testing has been enabled # check if testing has been enabled
if [ -n "$CONTROL_TESTS_PORT" ]; then if [ -n "$CONTROL_TESTS_PORT" ]; then
CONTROL_TESTS_PORT_BUILD="--build-arg CONTROL_TESTS_PORT=$CONTROL_TESTS_PORT" CONTROL_TESTS_PORT_BUILD="--build-arg CONTROL_TESTS_PORT=$CONTROL_TESTS_PORT"
CONTROL_TESTS_PORT_RUN="--env CONTROL_TESTS_PORT=$CONTROL_TESTS_PORT --publish $CONTROL_TESTS_PORT:$CONTROL_TESTS_PORT" CONTROL_TESTS_PORT_RUN="--env CONTROL_TESTS_PORT=$CONTROL_TESTS_PORT --publish $CONTROL_TESTS_PORT:$CONTROL_TESTS_PORT"
fi fi
# build the image # build the image
if [ -z "$NO_BUILD" ]; then if [ -z "$NO_BUILD" ]; then
echo Building the \"$IMAGE_TAG\" image... echo Building the \"$IMAGE_TAG\" image...
docker build \ docker build \
--tag vasl-templates:$IMAGE_TAG \ --tag vasl-templates:$IMAGE_TAG \
@ -261,11 +202,11 @@ if [ -z "$NO_BUILD" ]; then
| sed -e 's/^/ /' | sed -e 's/^/ /'
if [ ${PIPESTATUS[0]} -ne 0 ]; then exit 10 ; fi if [ ${PIPESTATUS[0]} -ne 0 ]; then exit 10 ; fi
echo echo
fi fi
# launch the container # launch the container
echo Launching the \"$IMAGE_TAG\" image as \"$CONTAINER_NAME\"... echo Launching the \"$IMAGE_TAG\" image as \"$CONTAINER_NAME\"...
docker run \ docker run \
--name $CONTAINER_NAME \ --name $CONTAINER_NAME \
--publish $PORT:5010 \ --publish $PORT:5010 \
--env DOCKER_IMAGE_NAME="vasl-templates:$IMAGE_TAG" \ --env DOCKER_IMAGE_NAME="vasl-templates:$IMAGE_TAG" \
@ -280,4 +221,70 @@ docker run \
vasl-templates:$IMAGE_TAG \ vasl-templates:$IMAGE_TAG \
2>&1 \ 2>&1 \
| sed -e 's/^/ /' | sed -e 's/^/ /'
exit ${PIPESTATUS[0]} exit ${PIPESTATUS[0]}
}
# ---------------------------------------------------------------------
function get_target {
local type=$1
local target=$2
# check that the target exists
if [ "$type" == "FILE" ]; then
test -f "$target" || return
elif [ "$type" == "DIR" ]; then
test -d "$target" || return
elif [ "$type" == "FILE-OR-DIR" ]; then
ls "$target" >/dev/null 2>&1 || return
fi
# convert the target to a full path
# FUDGE! I couldn't get the "docker run" command to work with spaces in the volume targets (although
# copying the generated command into the terminal worked fine) (and no, using ${var@Q} didn't help).
# So, the next best thing is to allow users to create symlinks to the targets :-/
echo $( realpath --no-symlinks "$target" )
}
# ---------------------------------------------------------------------
function print_help {
echo "`basename "$0"` {options}"
cat <<EOM
Build and launch the "vasl-templates" container.
-p --port Web server port number.
--vassal VASSAL installation directory.
-v --vasl Path to the VASL module file (.vmod).
-e --vasl-extensions Path to the VASL extensions directory.
--boards Path to the VASL boards.
--chapter-h Path to the Chapter H notes directory.
--user-files Path to the user files directory.
-k --template-pack Path to a user-defined template pack.
-t --tag Docker image tag.
--name Docker container name.
-d --detach Detach from the container and let it run in the background.
--no-build Launch the container as-is (i.e. without rebuilding the image first).
--build-network Docker network to use when building the image.
--run-network Docker network to use when running the container.
Options for the test suite:
--control-tests-port Remote test control port number.
--test-data-vassal Directory containing VASSAL releases.
--test-data-vasl-mods Directory containing VASL modules.
NOTE: If the port the webapp server is listening on *inside* the container is different
to the port exposed *outside* the container, webdriver image generation (e.g. Shift-Click
on a snippet button, or Chapter H content as images) may not work properly. This is because
a web browser is launched internally with snippet HTML and a screenshot taken of it, but
the HTML will contain links to the webapp server that work from outside the container,
but if those links don't resolve from inside the container, you will get broken images.
In this case, you will need to make such links resolve from inside the container e.g. by
port-forwarding, or via DNS.
EOM
}
# ---------------------------------------------------------------------
main "$@"

Loading…
Cancel
Save