|
|
|
@ -3,96 +3,37 @@ |
|
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------- |
|
|
|
|
|
|
|
|
|
function get_target { |
|
|
|
|
local type=$1 |
|
|
|
|
local target=$2 |
|
|
|
|
function main |
|
|
|
|
{ |
|
|
|
|
# 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 |
|
|
|
|
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 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 |
|
|
|
|
# parse the command-line arguments |
|
|
|
|
if [ $# -eq 0 ]; then |
|
|
|
|
print_help |
|
|
|
|
exit 0 |
|
|
|
|
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" -- "$@")" |
|
|
|
|
if [ $? -ne 0 ]; then exit 1; fi |
|
|
|
|
eval set -- "$params" |
|
|
|
|
while true; do |
|
|
|
|
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" -- "$@")" |
|
|
|
|
if [ $? -ne 0 ]; then exit 1; fi |
|
|
|
|
eval set -- "$params" |
|
|
|
|
while true; do |
|
|
|
|
case "$1" in |
|
|
|
|
-p | --port) |
|
|
|
|
PORT=$2 |
|
|
|
@ -157,10 +98,10 @@ while true; do |
|
|
|
|
echo "Unknown option: $1" >&2 |
|
|
|
|
exit 1 ;; |
|
|
|
|
esac |
|
|
|
|
done |
|
|
|
|
done |
|
|
|
|
|
|
|
|
|
# check if a VASSAL directory has been specified |
|
|
|
|
if [ -n "$VASSAL" ]; then |
|
|
|
|
# check if a VASSAL directory has been specified |
|
|
|
|
if [ -n "$VASSAL" ]; then |
|
|
|
|
target=$( get_target DIR "$VASSAL" ) |
|
|
|
|
if [ -z "$target" ]; then |
|
|
|
|
echo "Can't find the VASSAL directory: $VASSAL" |
|
|
|
@ -169,10 +110,10 @@ if [ -n "$VASSAL" ]; then |
|
|
|
|
mpoint=/data/vassal/ |
|
|
|
|
VASSAL_VOLUME="--volume $target:$mpoint" |
|
|
|
|
VASSAL_ENV="--env VASSAL_DIR=$mpoint --env VASSAL_DIR_TARGET=$target" |
|
|
|
|
fi |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
# check if a VASL module file has been specified |
|
|
|
|
if [ -n "$VASL_MOD" ]; then |
|
|
|
|
# check if a VASL module file has been specified |
|
|
|
|
if [ -n "$VASL_MOD" ]; then |
|
|
|
|
target=$( get_target FILE "$VASL_MOD" ) |
|
|
|
|
if [ -z "$target" ]; then |
|
|
|
|
echo "Can't find the VASL .vmod file: $VASL_MOD" |
|
|
|
@ -181,10 +122,10 @@ if [ -n "$VASL_MOD" ]; then |
|
|
|
|
mpoint=/data/vasl.vmod |
|
|
|
|
VASL_MOD_VOLUME="--volume $target:$mpoint" |
|
|
|
|
VASL_MOD_ENV="--env VASL_MOD=$mpoint --env VASL_MOD_TARGET=$target" |
|
|
|
|
fi |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
# check if a VASL extensions directory has been specified |
|
|
|
|
if [ -n "$VASL_EXTNS" ]; then |
|
|
|
|
# check if a VASL extensions directory has been specified |
|
|
|
|
if [ -n "$VASL_EXTNS" ]; then |
|
|
|
|
target=$( get_target DIR "$VASL_EXTNS" ) |
|
|
|
|
if [ -z "$target" ]; then |
|
|
|
|
echo "Can't find the VASL extensions directory: $VASL_EXTNS" |
|
|
|
@ -193,10 +134,10 @@ if [ -n "$VASL_EXTNS" ]; then |
|
|
|
|
mpoint=/data/vasl-extensions/ |
|
|
|
|
VASL_EXTNS_VOLUME="--volume $target:$mpoint" |
|
|
|
|
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 |
|
|
|
|
if [ -n "$VASL_BOARDS" ]; then |
|
|
|
|
# check if a VASL boards directory has been specified |
|
|
|
|
if [ -n "$VASL_BOARDS" ]; then |
|
|
|
|
target=$( get_target DIR "$VASL_BOARDS" ) |
|
|
|
|
if [ -z "$target" ]; then |
|
|
|
|
echo "Can't find the VASL boards directory: $VASL_BOARDS" |
|
|
|
@ -205,10 +146,10 @@ if [ -n "$VASL_BOARDS" ]; then |
|
|
|
|
mpoint=/data/boards/ |
|
|
|
|
VASL_BOARDS_VOLUME="--volume $target:$mpoint" |
|
|
|
|
VASL_BOARDS_ENV="--env BOARDS_DIR=$mpoint --env BOARDS_DIR_TARGET=$target" |
|
|
|
|
fi |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
# check if a Chapter H notes directory has been specified |
|
|
|
|
if [ -n "$CHAPTER_H_NOTES" ]; then |
|
|
|
|
# check if a Chapter H notes directory has been specified |
|
|
|
|
if [ -n "$CHAPTER_H_NOTES" ]; then |
|
|
|
|
target=$( get_target DIR "$CHAPTER_H_NOTES" ) |
|
|
|
|
if [ -z "$target" ]; then |
|
|
|
|
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/ |
|
|
|
|
CHAPTER_H_NOTES_VOLUME="--volume $target:$mpoint" |
|
|
|
|
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 |
|
|
|
|
if [ -n "$USER_FILES" ]; then |
|
|
|
|
# check if a user files directory has been specified |
|
|
|
|
if [ -n "$USER_FILES" ]; then |
|
|
|
|
target=$( get_target DIR "$USER_FILES" ) |
|
|
|
|
if [ -z "$target" ]; then |
|
|
|
|
echo "Can't find the user files directory: $USER_FILES" |
|
|
|
@ -229,10 +170,10 @@ if [ -n "$USER_FILES" ]; then |
|
|
|
|
mpoint=/data/user-files/ |
|
|
|
|
USER_FILES_VOLUME="--volume $target:$mpoint" |
|
|
|
|
USER_FILES_ENV="--env USER_FILES_DIR=$mpoint --env USER_FILES_DIR_TARGET=$target" |
|
|
|
|
fi |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
# check if a template pack has been specified |
|
|
|
|
if [ -n "$TEMPLATE_PACK" ]; then |
|
|
|
|
# check if a template pack has been specified |
|
|
|
|
if [ -n "$TEMPLATE_PACK" ]; then |
|
|
|
|
# NOTE: The template pack can either be a file (ZIP) or a directory. |
|
|
|
|
target=$( get_target FILE-OR-DIR "$TEMPLATE_PACK" ) |
|
|
|
|
if [ -z "$target" ]; then |
|
|
|
@ -242,16 +183,16 @@ if [ -n "$TEMPLATE_PACK" ]; then |
|
|
|
|
mpoint=/data/template-pack |
|
|
|
|
TEMPLATE_PACK_VOLUME="--volume $target:$mpoint" |
|
|
|
|
TEMPLATE_PACK_ENV="--env DEFAULT_TEMPLATE_PACK=$mpoint --env DEFAULT_TEMPLATE_PACK_TARGET" |
|
|
|
|
fi |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
# check if testing has been enabled |
|
|
|
|
if [ -n "$CONTROL_TESTS_PORT" ]; then |
|
|
|
|
# check if testing has been enabled |
|
|
|
|
if [ -n "$CONTROL_TESTS_PORT" ]; then |
|
|
|
|
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" |
|
|
|
|
fi |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
# build the image |
|
|
|
|
if [ -z "$NO_BUILD" ]; then |
|
|
|
|
# build the image |
|
|
|
|
if [ -z "$NO_BUILD" ]; then |
|
|
|
|
echo Building the \"$IMAGE_TAG\" image... |
|
|
|
|
docker build \ |
|
|
|
|
--tag vasl-templates:$IMAGE_TAG \ |
|
|
|
@ -261,11 +202,11 @@ if [ -z "$NO_BUILD" ]; then |
|
|
|
|
| sed -e 's/^/ /' |
|
|
|
|
if [ ${PIPESTATUS[0]} -ne 0 ]; then exit 10 ; fi |
|
|
|
|
echo |
|
|
|
|
fi |
|
|
|
|
fi |
|
|
|
|
|
|
|
|
|
# launch the container |
|
|
|
|
echo Launching the \"$IMAGE_TAG\" image as \"$CONTAINER_NAME\"... |
|
|
|
|
docker run \ |
|
|
|
|
# launch the container |
|
|
|
|
echo Launching the \"$IMAGE_TAG\" image as \"$CONTAINER_NAME\"... |
|
|
|
|
docker run \ |
|
|
|
|
--name $CONTAINER_NAME \ |
|
|
|
|
--publish $PORT:5010 \ |
|
|
|
|
--env DOCKER_IMAGE_NAME="vasl-templates:$IMAGE_TAG" \ |
|
|
|
@ -280,4 +221,70 @@ docker run \ |
|
|
|
|
vasl-templates:$IMAGE_TAG \ |
|
|
|
|
2>&1 \ |
|
|
|
|
| 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 "$@" |
|
|
|
|