1
0
mirror of https://github.com/avatao-content/test-tutorial-framework synced 2024-11-14 16:07:18 +00:00
test-tutorial-framework/hack/tfw.sh
2018-06-20 17:48:16 +02:00

81 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -eu
set -o pipefail
set -o errtrace
shopt -s expand_aliases
[ "$(uname)" == "Darwin" ] && alias readlink="greadlink" || :
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
TFW_PATH="${TFW_PATH:-$SCRIPT_DIR/../..}"
BASEIMAGE_REPO="${BASEIMAGE_REPO:-baseimage-tutorial-framework}"
CHALLENGE_REPO="${CHALLENGE_REPO:-"$(basename "$(realpath "${SCRIPT_DIR}/..")")"}"
FRONTEND_REPO="${FRONTEND_REPO:-frontend-tutorial-framework}"
BASEIMAGE_PATH="${TFW_PATH}/${BASEIMAGE_REPO}"
CHALLENGE_PATH="${TFW_PATH}/${CHALLENGE_REPO}"
FRONTEND_PATH="${TFW_PATH}/${FRONTEND_REPO}"
source "${SCRIPT_DIR}/libhack/baseimage.sh"
source "${SCRIPT_DIR}/libhack/challenge.sh"
source "${SCRIPT_DIR}/libhack/frontend.sh"
start_challenge_and_frontend() {
trap 'exit' INT TERM
trap 'kill 0' EXIT
[[ "${RUN_FRONTEND:-1}" == "1" ]] && frontend::run &
[[ "${BUILD:-1}" == "1" ]] && challenge::build
challenge::run $@
wait
}
case ${1:-} in
start)
baseimage::build_if_exists
BUILD=1 RUN_FRONTEND=1 start_challenge_and_frontend ${@:2}
;;
run)
BUILD=0 RUN_FRONTEND=1 start_challenge_and_frontend ${@:2}
;;
startcontainer)
baseimage::build_if_exists
BUILD=1 RUN_FRONTEND=0 start_challenge_and_frontend ${@:2}
;;
runcontainer)
BUILD=0 RUN_FRONTEND=0 start_challenge_and_frontend ${@:2}
;;
runfrontend)
frontend::run
;;
buildtfw)
baseimage::build_if_exists
;;
build)
baseimage::build_if_exists
challenge::build
;;
buildwithfrontend)
baseimage::build_if_exists
challenge::build_with_frontend
;;
releasetfw)
[[ -d "$BASEIMAGE_PATH" ]] && baseimage::release
;;
builddocs)
[[ -d "$BASEIMAGE_PATH" ]] && baseimage::builddocs
;;
*)
echo "Usage: tfw.sh [COMMAND]"
echo " |--- start: build & run TFW challenge and Angular frontend"
echo " |--- run: run TFW challenge and Angular frontend"
echo " |--- startcontainer: build & run TFW challenge, container only"
echo " |--- runcontainer: run TFW challenge, container only"
echo " |--- buildtfw: build TFW baseimage"
echo " |--- build: build TFW baseimage and challenge"
echo " |--- buildwithfrontend: build TFW baseimage and challenge, include frontend in image"
echo " |--- releasetfw: tag TFW baseimage and push to upstream"
echo " |--- builddocs: build baseimage documentation (in docs/build/html)"
;;
esac