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

48 lines
1.6 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}"
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}"
if [ "${HOTRELOAD:-0}" == "1" ]; then
[ -d "${BASEIMAGE_PATH}" ] && mount_baseimage="-v ${BASEIMAGE_PATH}/lib/tfw:/usr/local/lib/tfw"
mount_challenge="-v ${CHALLENGE_PATH}/solvable/src:/srv/.tfw"
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}
}