1
0
mirror of https://github.com/avatao-content/test-tutorial-framework synced 2025-06-28 10:45:13 +00:00

Refactor challenge building to libhack

This commit is contained in:
Kristóf Tóth
2018-06-15 15:18:46 +02:00
parent f563022aa8
commit 35776e7d7f
3 changed files with 86 additions and 69 deletions

View File

@ -2,6 +2,7 @@
# - BASEIMAGE_PATH: absolute path of baseimage repo
BASEIMAGE_NAME="${BASEIMAGE_NAME:-eu.gcr.io/avatao-challengestore/tutorial-framework}"
libhack_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
source "${libhack_dir}/common.sh"
@ -20,6 +21,10 @@ baseimage::build() {
popd
}
baseimage::build_if_exists() {
[[ -d "$BASEIMAGE_PATH" ]] && baseimage::build_as_latest
}
baseimage::tag_as_latest() {
docker tag "${BASEIMAGE_NAME}:$(releasename)" "${BASEIMAGE_NAME}:latest"
}

47
hack/libhack/challenge.sh Normal file
View File

@ -0,0 +1,47 @@
# 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}
}