# 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_challenge_internal popd } challenge::build_no_cache() { 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 127.0.0.1:${CHALLENGE_PORT}:${CHALLENGE_PORT} \ ${mount_volumes:-} \ ${@:-} \ -e AVATAO_SECRET="${AVATAO_SECRET}" ${IMAGE_NAME} }