2018-03-23 16:58:24 +00:00
|
|
|
#!/usr/bin/env bash
|
2018-04-16 18:45:46 +00:00
|
|
|
set -eu
|
2018-04-15 19:50:43 +00:00
|
|
|
set -o pipefail
|
|
|
|
set -o errtrace
|
2018-04-03 16:03:12 +00:00
|
|
|
shopt -s expand_aliases
|
2018-09-17 09:49:10 +00:00
|
|
|
[ "$(uname)" == "Darwin" ] && alias readlink="greadlink" && alias grep="ggrep" || :
|
2018-03-23 16:58:24 +00:00
|
|
|
|
2018-06-19 12:23:48 +00:00
|
|
|
SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
|
2018-06-15 13:18:46 +00:00
|
|
|
TFW_PATH="${TFW_PATH:-$SCRIPT_DIR/../..}"
|
|
|
|
|
2018-03-25 14:03:13 +00:00
|
|
|
BASEIMAGE_REPO="${BASEIMAGE_REPO:-baseimage-tutorial-framework}"
|
2018-06-15 13:18:46 +00:00
|
|
|
CHALLENGE_REPO="${CHALLENGE_REPO:-"$(basename "$(realpath "${SCRIPT_DIR}/..")")"}"
|
2018-03-23 16:58:24 +00:00
|
|
|
FRONTEND_REPO="${FRONTEND_REPO:-frontend-tutorial-framework}"
|
|
|
|
|
2018-06-15 13:18:46 +00:00
|
|
|
BASEIMAGE_PATH="${TFW_PATH}/${BASEIMAGE_REPO}"
|
|
|
|
CHALLENGE_PATH="${TFW_PATH}/${CHALLENGE_REPO}"
|
|
|
|
FRONTEND_PATH="${TFW_PATH}/${FRONTEND_REPO}"
|
2018-03-25 14:03:13 +00:00
|
|
|
|
2018-06-15 13:18:46 +00:00
|
|
|
source "${SCRIPT_DIR}/libhack/baseimage.sh"
|
|
|
|
source "${SCRIPT_DIR}/libhack/challenge.sh"
|
2019-09-30 13:08:04 +00:00
|
|
|
source "${SCRIPT_DIR}/libhack/frontend.sh"
|
2018-03-27 11:45:41 +00:00
|
|
|
|
2018-03-23 16:58:24 +00:00
|
|
|
|
2019-11-12 12:31:56 +00:00
|
|
|
try_build_baseimage() {
|
|
|
|
if baseimage::check_exists; then
|
|
|
|
build_baseimage
|
|
|
|
fi
|
2019-10-31 14:17:27 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 12:31:56 +00:00
|
|
|
build_baseimage() {
|
2019-10-31 14:17:27 +00:00
|
|
|
frontend_version="$(frontend::latest_tag)"
|
2019-11-12 12:31:56 +00:00
|
|
|
baseimage::build
|
2019-10-31 14:17:27 +00:00
|
|
|
}
|
|
|
|
|
2018-04-19 15:01:59 +00:00
|
|
|
case ${1:-} in
|
2018-05-04 09:00:22 +00:00
|
|
|
start)
|
2019-10-31 14:17:27 +00:00
|
|
|
try_build_baseimage
|
2019-09-05 16:23:57 +00:00
|
|
|
challenge::build
|
|
|
|
challenge::run ${@:2}
|
2018-05-04 09:00:22 +00:00
|
|
|
;;
|
2018-05-18 14:14:31 +00:00
|
|
|
run)
|
2019-09-05 16:23:57 +00:00
|
|
|
challenge:run ${@:2}
|
2018-06-15 14:03:26 +00:00
|
|
|
;;
|
2019-09-30 13:08:04 +00:00
|
|
|
build-baseimage)
|
2019-10-31 14:17:27 +00:00
|
|
|
build_baseimage
|
2018-03-27 14:07:59 +00:00
|
|
|
;;
|
|
|
|
build)
|
2019-10-31 14:17:27 +00:00
|
|
|
try_build_baseimage
|
2019-09-05 16:23:57 +00:00
|
|
|
challenge::build_no_cache
|
2018-03-31 19:07:11 +00:00
|
|
|
;;
|
2019-09-30 13:08:04 +00:00
|
|
|
build-frontend)
|
|
|
|
frontend::build
|
2018-05-04 09:00:22 +00:00
|
|
|
;;
|
2019-09-30 13:08:04 +00:00
|
|
|
release-baseimage)
|
2019-10-31 14:17:27 +00:00
|
|
|
build_baseimage
|
2019-09-30 13:08:04 +00:00
|
|
|
baseimage::release
|
|
|
|
;;
|
|
|
|
release-frontend)
|
2019-10-31 14:17:27 +00:00
|
|
|
frontend::build
|
2019-09-30 13:08:04 +00:00
|
|
|
frontend::release
|
2018-06-08 12:11:03 +00:00
|
|
|
;;
|
2018-03-27 14:07:59 +00:00
|
|
|
*)
|
2018-06-15 13:18:46 +00:00
|
|
|
echo "Usage: tfw.sh [COMMAND]"
|
2019-09-05 16:23:57 +00:00
|
|
|
echo " |--- start: build & run TFW challenge"
|
|
|
|
echo " |--- run: run TFW challenge"
|
2019-09-30 13:08:04 +00:00
|
|
|
echo " |--- build-baseimage: build TFW baseimage"
|
2018-06-15 13:18:46 +00:00
|
|
|
echo " |--- build: build TFW baseimage and challenge"
|
2019-09-30 13:08:04 +00:00
|
|
|
echo " |--- release-baseimage: tag TFW baseimage and push to DockerHub"
|
|
|
|
echo " |--- release-frontend: tag TFW frontend and push to DockerHub"
|
2018-03-27 14:07:59 +00:00
|
|
|
;;
|
|
|
|
esac
|