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

53 lines
1.7 KiB
Bash

# 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}"
args="--build-arg NOFRONTEND=1" build_challenge_internal
popd
}
challenge::build_with_frontend() {
pushd "${CHALLENGE_PATH}"
args="--no-cache" build_challenge_internal
popd
}
build_challenge_internal() {
docker build -t "${IMAGE_NAME}" \
-f "${BUILD_CONTEXT}/Dockerfile" \
--build-arg BUILD_CONTEXT="${BUILD_CONTEXT}" \
${args} .
}
challenge::run() {
pushd "${TFW_PATH}"
local mount_baseimage
local mount_challenge
local mount_volumes
if [[ "${HOTRELOAD:-0}" == "1" ]]; then
if [[ -d "${BASEIMAGE_PATH}" ]]; then
mount_baseimage="-e HOTRELOAD=1 -v ${BASEIMAGE_PATH}/tfw:/usr/local/lib/tfw"
fi
mount_challenge="-v ${CHALLENGE_PATH}/solvable/src:/.tfw/builtin_event_handlers"
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}
}