diff --git a/hack/libhack/bootstrap.sh b/hack/bootstrap.sh similarity index 76% rename from hack/libhack/bootstrap.sh rename to hack/bootstrap.sh index d1f86cf..fa63117 100755 --- a/hack/libhack/bootstrap.sh +++ b/hack/bootstrap.sh @@ -1,15 +1,20 @@ +#!/usr/bin/env bash +set -eu +set -o pipefail +set -o errtrace +shopt -s expand_aliases +[ "$(uname)" == "Darwin" ] && alias sed="gsed" || : + HERE="$(pwd)" CHALLENGE=${CHALLENGE:-test-tutorial-framework} +BASEIMAGE_NAME="${BASEIMAGE_NAME:-eu.gcr.io/avatao-challengestore/tutorial-framework}" +BASEIMAGE_REPO="${BASEIMAGE_REPO:-baseimage-tutorial-framework}" +FRONTEND_REPO="${FRONTEND_REPO:-frontend-tutorial-framework}" LOGFILE=/tmp/bootstrap_tfw.log REMOTEBASE="git@github.com:avatao-content" -libhack_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" -source "${libhack_dir}/common.sh" -source "${libhack_dir}/baseimage.sh" - - -bootstrap::run() { +run() { trap 'exit 1' INT trap handle_exit EXIT : > "${LOGFILE}" @@ -17,7 +22,7 @@ bootstrap::run() { check_dependencies clone_required_repos_ask_ssh_or_https local tag - tag="${BASEIMAGE_ONLY:-$(remotebase="${REMOTEBASE}" baseimage::latest_upstream_tag)}" + tag="${BASEIMAGE_ONLY:-$(remotebase="${REMOTEBASE}" baseimage_latest_upstream_tag)}" tag=${tag} build_baseimage if [ -z "${BASEIMAGE_ONLY:-}" ]; then @@ -108,6 +113,14 @@ install_frontend_deps() { echo "Done!" } +baseimage_latest_upstream_tag() { + echo -n "$(git ls-remote --tags ${remotebase}/${BASEIMAGE_REPO}.git | + cut -f2 | + grep -oP '(?<=refs/tags/)\w+-\d{8}$' | + sort -t '-' -k2 | + tail -n 1)" +} + pin_baseimage() { echo -n "Pinning TFW baseimage version... " echo -n "which is ${tag}... " @@ -137,3 +150,29 @@ merge_repos() { mv "${FRONTEND_REPO}" "${NESTED_FRONTEND}" echo "Done!" } + +spinned() { + "$@" & + pid=$! + spin=("-" "\\" "|" "/") + + echo -n "${spin[0]}" + while kill -0 $pid &> /dev/null; do + for i in "${spin[@]}"; do + echo -ne "\b$i" + sleep 0.1 + done + done + echo -ne "\b" + wait $pid +} + +pushd() { + command pushd "$@" > /dev/null +} + +popd() { + command popd "$@" > /dev/null +} + +run diff --git a/hack/libhack/baseimage.sh b/hack/libhack/baseimage.sh index df1ee15..22e2e79 100644 --- a/hack/libhack/baseimage.sh +++ b/hack/libhack/baseimage.sh @@ -67,14 +67,6 @@ baseimage::builddocs() { fi } -baseimage::latest_upstream_tag() { - echo -n "$(git ls-remote --tags ${remotebase}/${BASEIMAGE_REPO}.git | - cut -f2 | - grep -oP '(?<=refs/tags/)\w+-\d{8}$' | - sort -t '-' -k2 | - tail -n 1)" -} - releasename() { local version local date diff --git a/hack/libhack/common.sh b/hack/libhack/common.sh index 089e3aa..95a908b 100644 --- a/hack/libhack/common.sh +++ b/hack/libhack/common.sh @@ -5,19 +5,3 @@ pushd() { popd() { command popd "$@" > /dev/null } - -spinned() { - "$@" & - pid=$! - spin=("-" "\\" "|" "/") - - echo -n "${spin[0]}" - while kill -0 $pid &> /dev/null; do - for i in "${spin[@]}"; do - echo -ne "\b$i" - sleep 0.1 - done - done - echo -ne "\b" - wait $pid -} diff --git a/hack/tfw.sh b/hack/tfw.sh index 71106b6..46a843b 100755 --- a/hack/tfw.sh +++ b/hack/tfw.sh @@ -3,7 +3,7 @@ set -eu set -o pipefail set -o errtrace shopt -s expand_aliases -[ "$(uname)" == "Darwin" ] && alias readlink="greadlink" && alias sed="gsed" || : +[ "$(uname)" == "Darwin" ] && alias readlink="greadlink" || : SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" TFW_PATH="${TFW_PATH:-$SCRIPT_DIR/../..}" @@ -19,7 +19,6 @@ FRONTEND_PATH="${TFW_PATH}/${FRONTEND_REPO}" source "${SCRIPT_DIR}/libhack/baseimage.sh" source "${SCRIPT_DIR}/libhack/challenge.sh" source "${SCRIPT_DIR}/libhack/frontend.sh" -source "${SCRIPT_DIR}/libhack/bootstrap.sh" start_challenge_and_frontend() { @@ -32,9 +31,6 @@ start_challenge_and_frontend() { } case ${1:-} in - bootstrap) - bootstrap::run - ;; start) baseimage::build_if_exists BUILD=1 RUN_FRONTEND=1 start_challenge_and_frontend ${@:2} @@ -75,7 +71,6 @@ case ${1:-} in ;; *) echo "Usage: tfw.sh [COMMAND]" - echo " |--- bootstrap: setup TFW development environment" 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"