1
0
mirror of https://github.com/avatao-content/test-tutorial-framework synced 2024-11-15 08:07:18 +00:00
test-tutorial-framework/hack/libhack/challenge.sh

53 lines
1.7 KiB
Bash
Raw Normal View History

2018-06-15 13:18:46 +00:00
# Requires context:
# - TFW_PATH: absolute path of the parent directory of TFW repos
# - BASEIMAGE_PATH: absolute path of baseimage repo
# - CHALLENGE_PATH: absolute path of challenge repo
IMAGE_NAME="${IMAGE_NAME:-"$(basename "${CHALLENGE_PATH}")"}"
BUILD_CONTEXT="${BUILD_CONTEXT:-solvable}"
CHALLENGE_PORT="${CHALLENGE_PORT:-8888}"
AVATAO_SECRET="${AVATAO_SECRET:-secret}"
libhack_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
source "${libhack_dir}/common.sh"
challenge::build() {
pushd "${CHALLENGE_PATH}"
2018-06-15 13:47:06 +00:00
args="--build-arg NOFRONTEND=1" build_challenge_internal
2018-06-15 13:18:46 +00:00
popd
}
challenge::build_with_frontend() {
pushd "${CHALLENGE_PATH}"
2018-06-15 13:47:06 +00:00
args="--no-cache" build_challenge_internal
2018-06-15 13:18:46 +00:00
popd
}
build_challenge_internal() {
docker build -t "${IMAGE_NAME}" \
-f "${BUILD_CONTEXT}/Dockerfile" \
--build-arg BUILD_CONTEXT="${BUILD_CONTEXT}" \
2018-06-15 13:47:06 +00:00
${args} .
2018-06-15 13:18:46 +00:00
}
challenge::run() {
pushd "${TFW_PATH}"
2018-06-15 13:47:06 +00:00
local mount_baseimage
local mount_challenge
local mount_volumes
2018-06-18 12:53:10 +00:00
if [[ "${HOTRELOAD:-0}" == "1" ]]; then
if [[ -d "${BASEIMAGE_PATH}" ]]; then
mount_baseimage="-v ${BASEIMAGE_PATH}/lib/tfw:/usr/local/lib/tfw"
fi
2018-08-03 11:33:11 +00:00
mount_challenge="-v ${CHALLENGE_PATH}/solvable/src:/.tfw/builtin_event_handlers"
2018-06-15 13:18:46 +00:00
mount_volumes="${mount_baseimage:-} ${mount_challenge}"
fi
popd
docker run --rm \
-p ${CHALLENGE_PORT}:${CHALLENGE_PORT} \
${mount_volumes:-} \
${@:-} \
-e AVATAO_SECRET="${AVATAO_SECRET}" ${IMAGE_NAME}
}