mirror of
https://github.com/avatao-content/test-tutorial-framework
synced 2024-11-14 15:57:17 +00:00
Refactor challenge building to libhack
This commit is contained in:
parent
f563022aa8
commit
35776e7d7f
@ -2,6 +2,7 @@
|
|||||||
# - BASEIMAGE_PATH: absolute path of baseimage repo
|
# - BASEIMAGE_PATH: absolute path of baseimage repo
|
||||||
|
|
||||||
BASEIMAGE_NAME="${BASEIMAGE_NAME:-eu.gcr.io/avatao-challengestore/tutorial-framework}"
|
BASEIMAGE_NAME="${BASEIMAGE_NAME:-eu.gcr.io/avatao-challengestore/tutorial-framework}"
|
||||||
|
|
||||||
libhack_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
|
libhack_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
|
||||||
source "${libhack_dir}/common.sh"
|
source "${libhack_dir}/common.sh"
|
||||||
|
|
||||||
@ -20,6 +21,10 @@ baseimage::build() {
|
|||||||
popd
|
popd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
baseimage::build_if_exists() {
|
||||||
|
[[ -d "$BASEIMAGE_PATH" ]] && baseimage::build_as_latest
|
||||||
|
}
|
||||||
|
|
||||||
baseimage::tag_as_latest() {
|
baseimage::tag_as_latest() {
|
||||||
docker tag "${BASEIMAGE_NAME}:$(releasename)" "${BASEIMAGE_NAME}:latest"
|
docker tag "${BASEIMAGE_NAME}:$(releasename)" "${BASEIMAGE_NAME}:latest"
|
||||||
}
|
}
|
||||||
|
47
hack/libhack/challenge.sh
Normal file
47
hack/libhack/challenge.sh
Normal 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}
|
||||||
|
}
|
103
hack/tfw.sh
103
hack/tfw.sh
@ -5,117 +5,82 @@ set -o errtrace
|
|||||||
shopt -s expand_aliases
|
shopt -s expand_aliases
|
||||||
[ "$(uname)" == "Darwin" ] && alias readlink="greadlink" || :
|
[ "$(uname)" == "Darwin" ] && alias readlink="greadlink" || :
|
||||||
|
|
||||||
here="$(pwd)"
|
|
||||||
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
||||||
TAO_PATH="${TAO_PATH:-$SCRIPT_DIR/../..}"
|
TFW_PATH="${TFW_PATH:-$SCRIPT_DIR/../..}"
|
||||||
|
|
||||||
BASEIMAGE_REPO="${BASEIMAGE_REPO:-baseimage-tutorial-framework}"
|
BASEIMAGE_REPO="${BASEIMAGE_REPO:-baseimage-tutorial-framework}"
|
||||||
TEST_REPO="${TEST_REPO:-"$(basename "$(realpath "${SCRIPT_DIR}/..")")"}"
|
CHALLENGE_REPO="${CHALLENGE_REPO:-"$(basename "$(realpath "${SCRIPT_DIR}/..")")"}"
|
||||||
FRONTEND_REPO="${FRONTEND_REPO:-frontend-tutorial-framework}"
|
FRONTEND_REPO="${FRONTEND_REPO:-frontend-tutorial-framework}"
|
||||||
BASEIMAGE_PATH="${TAO_PATH}/${BASEIMAGE_REPO}"
|
|
||||||
TEST_PATH="${TAO_PATH}/${TEST_REPO}"
|
|
||||||
FRONTEND_PATH="${TAO_PATH}/${FRONTEND_REPO}"
|
|
||||||
|
|
||||||
IMAGE_NAME="${IMAGE_NAME:-test-tutorial-framework}"
|
BASEIMAGE_PATH="${TFW_PATH}/${BASEIMAGE_REPO}"
|
||||||
TEST_PORT="${TEST_PORT:-8888}"
|
CHALLENGE_PATH="${TFW_PATH}/${CHALLENGE_REPO}"
|
||||||
AVATAO_SECRET="${AVATAO_SECRET:-secret}"
|
FRONTEND_PATH="${TFW_PATH}/${FRONTEND_REPO}"
|
||||||
BUILD_CONTEXT="${BUILD_CONTEXT:-solvable}"
|
|
||||||
source "${SCRIPT_DIR}/libhack/baseimage.sh"
|
source "${SCRIPT_DIR}/libhack/baseimage.sh"
|
||||||
|
source "${SCRIPT_DIR}/libhack/challenge.sh"
|
||||||
|
|
||||||
|
|
||||||
build_test_internal()
|
run_frontend() {
|
||||||
{
|
FRONTEND_IN_CHALLENGE="${CHALLENGE_PATH}/solvable/frontend"
|
||||||
[[ -d "$BASEIMAGE_PATH" ]] && baseimage::build_as_latest
|
if [ "$(find "$FRONTEND_IN_CHALLENGE" | wc -l)" -gt 2 ]
|
||||||
cd $TEST_PATH
|
|
||||||
docker build -t $IMAGE_NAME \
|
|
||||||
-f ${BUILD_CONTEXT}/Dockerfile \
|
|
||||||
--build-arg BUILD_CONTEXT=$BUILD_CONTEXT \
|
|
||||||
${ARGS} .
|
|
||||||
}
|
|
||||||
|
|
||||||
build_test()
|
|
||||||
{
|
|
||||||
ARGS="--build-arg NOFRONTEND=1" build_test_internal
|
|
||||||
}
|
|
||||||
|
|
||||||
build_test_withfrontend()
|
|
||||||
{
|
|
||||||
ARGS="--no-cache" build_test_internal
|
|
||||||
}
|
|
||||||
|
|
||||||
run_test()
|
|
||||||
{
|
|
||||||
cd "$TAO_PATH"
|
|
||||||
if [ "${HOTRELOAD:-0}" == "1" ]; then
|
|
||||||
[ -d "$BASEIMAGE_PATH" ] && mount_baseimage="-v ${BASEIMAGE_PATH}/lib/tfw:/usr/local/lib/tfw"
|
|
||||||
mount_test="-v ${TEST_PATH}/solvable/src:/srv/.tfw"
|
|
||||||
mount_volumes="${mount_baseimage:-} ${mount_test}"
|
|
||||||
fi
|
|
||||||
docker run --rm \
|
|
||||||
-p $TEST_PORT:$TEST_PORT \
|
|
||||||
${mount_volumes:-} \
|
|
||||||
${@:-} \
|
|
||||||
-e AVATAO_SECRET=$AVATAO_SECRET $IMAGE_NAME
|
|
||||||
}
|
|
||||||
|
|
||||||
run_frontend()
|
|
||||||
{
|
|
||||||
FRONTEND_IN_TEST="${TEST_PATH}/solvable/frontend"
|
|
||||||
if [ "$(find "$FRONTEND_IN_TEST" | wc -l)" -gt 2 ]
|
|
||||||
then
|
then
|
||||||
cd $FRONTEND_IN_TEST
|
cd $FRONTEND_IN_CHALLENGE
|
||||||
else
|
else
|
||||||
cd $FRONTEND_PATH
|
cd $FRONTEND_PATH
|
||||||
fi
|
fi
|
||||||
yarn start
|
yarn start
|
||||||
}
|
}
|
||||||
|
|
||||||
start_test()
|
start_challenge_and_frontend() {
|
||||||
{
|
|
||||||
trap 'exit' INT TERM
|
trap 'exit' INT TERM
|
||||||
trap 'kill 0' EXIT
|
trap 'kill 0' EXIT
|
||||||
[[ "${RUN_FRONTEND:-1}" == "1" ]] && run_frontend &
|
[[ "${RUN_FRONTEND:-1}" == "1" ]] && run_frontend &
|
||||||
[[ "${BUILD:-1}" == "1" ]] && build_test
|
[[ "${BUILD:-1}" == "1" ]] && challenge::build
|
||||||
run_test $@
|
challenge::run $@
|
||||||
wait
|
wait
|
||||||
}
|
}
|
||||||
|
|
||||||
case ${1:-} in
|
case ${1:-} in
|
||||||
start)
|
start)
|
||||||
RUN_FRONTEND=1 start_test ${@:2}
|
baseimage::build_if_exists
|
||||||
|
BUILD=1 RUN_FRONTEND=1 start_challenge_and_frontend ${@:2}
|
||||||
;;
|
;;
|
||||||
run)
|
run)
|
||||||
BUILD=0 RUN_FRONTEND=1 start_test ${@:2}
|
BUILD=0 RUN_FRONTEND=1 start_challenge_and_frontend ${@:2}
|
||||||
;;
|
;;
|
||||||
startcontainer)
|
startcontainer)
|
||||||
RUN_FRONTEND=0 start_test ${@:2}
|
baseimage::build_if_exists
|
||||||
|
BUILD=1 RUN_FRONTEND=0 start_challenge_and_frontend ${@:2}
|
||||||
;;
|
;;
|
||||||
runcontainer)
|
runcontainer)
|
||||||
BUILD=0 RUN_FRONTEND=0 start_test ${@:2}
|
BUILD=0 RUN_FRONTEND=0 start_challenge_and_frontend ${@:2}
|
||||||
;;
|
;;
|
||||||
buildtfw)
|
buildtfw)
|
||||||
[[ -d "$BASEIMAGE_PATH" ]] && baseimage::build_as_latest
|
baseimage::build_if_exists
|
||||||
;;
|
;;
|
||||||
build)
|
build)
|
||||||
build_test
|
baseimage::build_if_exists
|
||||||
|
challenge::build
|
||||||
;;
|
;;
|
||||||
buildwithfrontend)
|
buildwithfrontend)
|
||||||
build_test_withfrontend
|
baseimage::build_if_exists
|
||||||
|
challenge::build_with_frontend
|
||||||
;;
|
;;
|
||||||
releasetfw)
|
releasetfw)
|
||||||
[[ -d "$BASEIMAGE_PATH" ]] && baseimage::release
|
[[ -d "$BASEIMAGE_PATH" ]] && baseimage::release
|
||||||
;;
|
;;
|
||||||
builddocs)
|
builddocs)
|
||||||
baseimage::builddocs
|
[[ -d "$BASEIMAGE_PATH" ]] && baseimage::builddocs
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Usage: tfw.sh [start|buildtfw|build|buildwithfrontend|releasetfw]"
|
echo "Usage: tfw.sh [COMMAND]"
|
||||||
echo " |--- start: build & run TFW test and Angular frontend"
|
echo " |--- start: build & run TFW challenge and Angular frontend"
|
||||||
echo " |--- run: run TFW test and Angular frontend"
|
echo " |--- run: run TFW challenge and Angular frontend"
|
||||||
echo " |--- startcontainer: build & run TFW test, container only"
|
echo " |--- startcontainer: build & run TFW challenge, container only"
|
||||||
echo " |--- runcontainer: run TFW test, container only"
|
echo " |--- runcontainer: run TFW challenge, container only"
|
||||||
echo " |--- buildtfw: build TFW baseimage"
|
echo " |--- buildtfw: build TFW baseimage"
|
||||||
echo " |--- build: build TFW baseimage and test"
|
echo " |--- build: build TFW baseimage and challenge"
|
||||||
echo " |--- buildwithfrontend: build TFW baseimage and test, include frontend in image"
|
echo " |--- buildwithfrontend: build TFW baseimage and challenge, include frontend in image"
|
||||||
echo " |--- releasetfw: tag TFW baseimage and push to upstream"
|
echo " |--- releasetfw: tag TFW baseimage and push to upstream"
|
||||||
echo " |--- builddocs: build baseimage documentation (in docs/build/html)"
|
echo " |--- builddocs: build baseimage documentation (in docs/build/html)"
|
||||||
;;
|
;;
|
||||||
|
Loading…
Reference in New Issue
Block a user