From d86f6affac7edc62db3c02aa5b17339364753d64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 12 Jun 2018 14:31:27 +0200 Subject: [PATCH 01/14] Refactor baseimage related stuff to libhack/baseimage.sh --- hack/libhack/baseimage.sh | 91 +++++++++++++++++++++++++++++++++++++++ hack/libhack/common.sh | 7 +++ hack/tfw.sh | 80 ++-------------------------------- 3 files changed, 102 insertions(+), 76 deletions(-) create mode 100644 hack/libhack/baseimage.sh create mode 100644 hack/libhack/common.sh diff --git a/hack/libhack/baseimage.sh b/hack/libhack/baseimage.sh new file mode 100644 index 0000000..486659d --- /dev/null +++ b/hack/libhack/baseimage.sh @@ -0,0 +1,91 @@ +# Requires context: +# - BASEIMAGE_PATH: absolute path of baseimage repo + +BASEIMAGE_NAME="${BASEIMAGE_NAME:-eu.gcr.io/avatao-challengestore/tutorial-framework}" +libhack_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" +source "${libhack_dir}/common.sh" + + +baseimage::build_as_latest() { + pushd "${BASEIMAGE_PATH}" + baseimage::build + baseimage::tag_as_latest + popd +} + +baseimage::build() { + pushd "${BASEIMAGE_PATH}" + docker build -t "${BASEIMAGE_NAME}:$(releasename)" \ + . + popd +} + +baseimage::tag_as_latest() { + docker tag "${BASEIMAGE_NAME}:$(releasename)" "${BASEIMAGE_NAME}:latest" +} + +baseimage::release() { + pushd "${BASEIMAGE_PATH}" + check_drone_releasename + + local tag + tag="$(releasename)" + read -p "Tag and push new TFW version \"${tag}\"? [y/N]" -r && echo + if [[ $REPLY =~ ^(y|Y|yes|Yes|YES)$ ]] + then + prompt_for_tag_description # This command sets $description + tag="${tag}" description="${description}" force_push_tag + fi + popd +} + +releasename() { + local version + local date + version="$(cat VERSION | head -n 1)" + date="$(date +%Y%m%d)" + printf "${version}-${date}" +} + +check_drone_releasename() { + local drone_releasename + local actual_releasename + drone_releasename="$(grep -oP '(?<=branch:\srefs/tags/).+(?=-.+)' .drone.yml)" + actual_releasename="$(baseimage_releasename | grep -oP ".+(?=-\d{8})")" + if [ "${drone_releasename}" != "${actual_releasename}" ]; then + echo "Release name '${drone_releasename}' in .drone.yml does not match \ + actual release name '${actual_releasename}' in VERSION." + echo "Please make them match before releasing!" + exit 1 + fi +} + +prompt_for_tag_description() { + local editor + local tempfile + editor="$(git config --global core.editor)" + tempfile="$(mktemp)" + + printf "\n\n" >> "${tempfile}" + echo "# Please enter the description for this release." >> "${tempfile}" + echo "# Lines starting with '#' will be ignored." >> "${tempfile}" + echo "# An empty description aborts the release." >> "${tempfile}" + + ${editor} "${tempfile}" + sed -i -e 's/#.*$//' -e '/^$/d' "${tempfile}" + sed -i 's/\n/ /g' "${tempfile}" + if [[ ! -s "${tempfile}" ]]; then + echo "Aborting release due to empty description." + exit 1 + fi + + description="$(tr '\n' ' ' < "${tempfile}")" + rm "${tempfile}" +} + +force_push_tag() { + git tag -d "${tag}" > /dev/null 2>&1 || : + git push --delete origin "${tag}" > /dev/null 2>&1 || : + git tag -s -m "${description}" "${tag}" + git push origin "${tag}" +} diff --git a/hack/libhack/common.sh b/hack/libhack/common.sh new file mode 100644 index 0000000..95a908b --- /dev/null +++ b/hack/libhack/common.sh @@ -0,0 +1,7 @@ +pushd() { + command pushd "$@" > /dev/null +} + +popd() { + command popd "$@" > /dev/null +} diff --git a/hack/tfw.sh b/hack/tfw.sh index dad09a4..c75d28d 100755 --- a/hack/tfw.sh +++ b/hack/tfw.sh @@ -15,88 +15,16 @@ BASEIMAGE_PATH="${TAO_PATH}/${BASEIMAGE_REPO}" TEST_PATH="${TAO_PATH}/${TEST_REPO}" FRONTEND_PATH="${TAO_PATH}/${FRONTEND_REPO}" -BASEIMAGE_NAME="${BASEIMAGE_NAME:-eu.gcr.io/avatao-challengestore/tutorial-framework}" IMAGE_NAME="${IMAGE_NAME:-test-tutorial-framework}" TEST_PORT="${TEST_PORT:-8888}" AVATAO_SECRET="${AVATAO_SECRET:-secret}" BUILD_CONTEXT="${BUILD_CONTEXT:-solvable}" +source "${SCRIPT_DIR}/libhack/baseimage.sh" -build_baseimage() -{ - [ ! -d "$BASEIMAGE_PATH" ] && return || : - cd $BASEIMAGE_PATH - docker build -t "${BASEIMAGE_NAME}:${TFWTAG:-$(baseimage_releasename)}" \ - -t "${BASEIMAGE_NAME}:latest" \ - . -} - -release_baseimage() -{ - [ ! -d "$BASEIMAGE_PATH" ] && return || : - cd $BASEIMAGE_PATH - check_drone_releasename - - TAG="$(baseimage_releasename)" - read -p "Tag and push new TFW version \"${TAG}\"? [y/N]" -r && echo - if [[ $REPLY =~ ^(y|Y|yes|Yes|YES)$ ]] - then - description="" - prompt_for_tag_description # This command overwrites $description - TAG="$TAG" DESCRIPTION="$description" force_push_tag - fi -} - -check_drone_releasename() -{ - DRONEYML_RELEASENAME="$(grep -oP '(?<=branch:\srefs/tags/).+(?=-.+)' .drone.yml)" - ACTUAL_RELEASENAME="$(baseimage_releasename | grep -oP ".+(?=-\d{8})")" - if [ "$DRONEYML_RELEASENAME" != "$ACTUAL_RELEASENAME" ]; then - echo "Release name '${DRONEYML_RELEASENAME}' in .drone.yml does not match actual release name '${ACTUAL_RELEASENAME}' in VERSION." - echo "Please make them match before releasing!" - exit 1 - fi -} - -prompt_for_tag_description() -{ - editor="$(git config --global core.editor)" - tempfile="$(mktemp)" - - printf "\n\n" >> "$tempfile" - echo "# Please enter the description for this release." >> "$tempfile" - echo "# Lines starting with '#' will be ignored." >> "$tempfile" - echo "# An empty description aborts the release." >> "$tempfile" - - $editor "$tempfile" - sed -i -e 's/#.*$//' -e '/^$/d' "$tempfile" - sed -i 's/\n/ /g' "$tempfile" - if [[ ! -s "$tempfile" ]]; then - echo "Aborting release due to empty description." - exit 1 - fi - - description="$(tr '\n' ' ' < "$tempfile")" - rm "$tempfile" -} - -force_push_tag() -{ - git tag -d "$TAG" > /dev/null 2>&1 || : - git push --delete origin "$TAG" > /dev/null 2>&1 || : - git tag -s -m "$DESCRIPTION" "$TAG" - git push origin "$TAG" -} - -baseimage_releasename() -{ - VERSION="$(cat VERSION | head -n 1)" - DATE="$(date +%Y%m%d)" - printf "${VERSION}-${DATE}" -} build_test_internal() { - build_baseimage + [[ -d "$BASEIMAGE_PATH" ]] && baseimage::build_as_latest cd $TEST_PATH docker build -t $IMAGE_NAME \ -f ${BUILD_CONTEXT}/Dockerfile \ @@ -187,7 +115,7 @@ case ${1:-} in BUILD=0 RUN_FRONTEND=0 start_test ${@:2} ;; buildtfw) - build_baseimage + [[ -d "$BASEIMAGE_PATH" ]] && baseimage::build_as_latest ;; build) build_test @@ -196,7 +124,7 @@ case ${1:-} in build_test_withfrontend ;; releasetfw) - release_baseimage + [[ -d "$BASEIMAGE_PATH" ]] && baseimage::release ;; builddocs) build_docs From f563022aa89949642da31ab7f87ecb6345429e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Fri, 15 Jun 2018 11:03:35 +0200 Subject: [PATCH 02/14] Refactor baseimage building to baseimage.sh --- hack/libhack/baseimage.sh | 21 +++++++++++++++++++++ hack/tfw.sh | 24 +----------------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/hack/libhack/baseimage.sh b/hack/libhack/baseimage.sh index 486659d..742a697 100644 --- a/hack/libhack/baseimage.sh +++ b/hack/libhack/baseimage.sh @@ -39,6 +39,27 @@ baseimage::release() { popd } +baseimage::builddocs() { + mount_point="/mnt/docs" + + docker run --rm \ + -ti \ + -v "${BASEIMAGE_PATH}"/docs:"${mount_point}" \ + "${BASEIMAGE_NAME}" \ + /bin/bash -c \ + "cd ${mount_point} + pip3 install sphinx + make html + exit" \ + &> /dev/null + + if [ "$?" == "0" ]; then + echo "Built baseimage docs at ${BASEIMAGE_PATH}/docs/build/html!" + else + echo "Building baseimage docs failed!" + fi +} + releasename() { local version local date diff --git a/hack/tfw.sh b/hack/tfw.sh index c75d28d..3f4c59a 100755 --- a/hack/tfw.sh +++ b/hack/tfw.sh @@ -79,28 +79,6 @@ start_test() wait } -build_docs() -{ - mount_point="/mnt/docs" - - docker run --rm \ - -ti \ - -v "$BASEIMAGE_PATH"/docs:"$mount_point" \ - "$BASEIMAGE_NAME" \ - /bin/bash -c \ - "cd $mount_point - pip3 install sphinx - make html - exit" \ - &> /dev/null - - if [ "$?" == "0" ]; then - echo "Built baseimage docs at ${BASEIMAGE_PATH}/docs/build/html!" - else - echo "Building baseimage docs failed!" - fi -} - case ${1:-} in start) RUN_FRONTEND=1 start_test ${@:2} @@ -127,7 +105,7 @@ case ${1:-} in [[ -d "$BASEIMAGE_PATH" ]] && baseimage::release ;; builddocs) - build_docs + baseimage::builddocs ;; *) echo "Usage: tfw.sh [start|buildtfw|build|buildwithfrontend|releasetfw]" From 35776e7d7f7a765d286f3268f8bfa5aacca9ea8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Fri, 15 Jun 2018 15:18:46 +0200 Subject: [PATCH 03/14] Refactor challenge building to libhack --- hack/libhack/baseimage.sh | 5 ++ hack/libhack/challenge.sh | 47 +++++++++++++++++ hack/tfw.sh | 103 +++++++++++++------------------------- 3 files changed, 86 insertions(+), 69 deletions(-) create mode 100644 hack/libhack/challenge.sh diff --git a/hack/libhack/baseimage.sh b/hack/libhack/baseimage.sh index 742a697..5dd5f8c 100644 --- a/hack/libhack/baseimage.sh +++ b/hack/libhack/baseimage.sh @@ -2,6 +2,7 @@ # - BASEIMAGE_PATH: absolute path of baseimage repo BASEIMAGE_NAME="${BASEIMAGE_NAME:-eu.gcr.io/avatao-challengestore/tutorial-framework}" + libhack_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" source "${libhack_dir}/common.sh" @@ -20,6 +21,10 @@ baseimage::build() { popd } +baseimage::build_if_exists() { + [[ -d "$BASEIMAGE_PATH" ]] && baseimage::build_as_latest +} + baseimage::tag_as_latest() { docker tag "${BASEIMAGE_NAME}:$(releasename)" "${BASEIMAGE_NAME}:latest" } diff --git a/hack/libhack/challenge.sh b/hack/libhack/challenge.sh new file mode 100644 index 0000000..0f5ddb7 --- /dev/null +++ b/hack/libhack/challenge.sh @@ -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} +} diff --git a/hack/tfw.sh b/hack/tfw.sh index 3f4c59a..9ebd188 100755 --- a/hack/tfw.sh +++ b/hack/tfw.sh @@ -5,117 +5,82 @@ set -o errtrace shopt -s expand_aliases [ "$(uname)" == "Darwin" ] && alias readlink="greadlink" || : -here="$(pwd)" 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}" -TEST_REPO="${TEST_REPO:-"$(basename "$(realpath "${SCRIPT_DIR}/..")")"}" +CHALLENGE_REPO="${CHALLENGE_REPO:-"$(basename "$(realpath "${SCRIPT_DIR}/..")")"}" 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}" -TEST_PORT="${TEST_PORT:-8888}" -AVATAO_SECRET="${AVATAO_SECRET:-secret}" -BUILD_CONTEXT="${BUILD_CONTEXT:-solvable}" +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" -build_test_internal() -{ - [[ -d "$BASEIMAGE_PATH" ]] && baseimage::build_as_latest - 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 ] +run_frontend() { + FRONTEND_IN_CHALLENGE="${CHALLENGE_PATH}/solvable/frontend" + if [ "$(find "$FRONTEND_IN_CHALLENGE" | wc -l)" -gt 2 ] then - cd $FRONTEND_IN_TEST + cd $FRONTEND_IN_CHALLENGE else cd $FRONTEND_PATH fi yarn start } -start_test() -{ +start_challenge_and_frontend() { trap 'exit' INT TERM trap 'kill 0' EXIT [[ "${RUN_FRONTEND:-1}" == "1" ]] && run_frontend & - [[ "${BUILD:-1}" == "1" ]] && build_test - run_test $@ + [[ "${BUILD:-1}" == "1" ]] && challenge::build + challenge::run $@ wait } case ${1:-} in start) - RUN_FRONTEND=1 start_test ${@:2} + baseimage::build_if_exists + BUILD=1 RUN_FRONTEND=1 start_challenge_and_frontend ${@:2} ;; run) - BUILD=0 RUN_FRONTEND=1 start_test ${@:2} + BUILD=0 RUN_FRONTEND=1 start_challenge_and_frontend ${@:2} ;; startcontainer) - RUN_FRONTEND=0 start_test ${@:2} + baseimage::build_if_exists + BUILD=1 RUN_FRONTEND=0 start_challenge_and_frontend ${@:2} ;; runcontainer) - BUILD=0 RUN_FRONTEND=0 start_test ${@:2} + BUILD=0 RUN_FRONTEND=0 start_challenge_and_frontend ${@:2} ;; buildtfw) - [[ -d "$BASEIMAGE_PATH" ]] && baseimage::build_as_latest + baseimage::build_if_exists ;; build) - build_test + baseimage::build_if_exists + challenge::build ;; buildwithfrontend) - build_test_withfrontend + baseimage::build_if_exists + challenge::build_with_frontend ;; releasetfw) [[ -d "$BASEIMAGE_PATH" ]] && baseimage::release ;; builddocs) - baseimage::builddocs + [[ -d "$BASEIMAGE_PATH" ]] && baseimage::builddocs ;; *) - echo "Usage: tfw.sh [start|buildtfw|build|buildwithfrontend|releasetfw]" - echo " |--- start: build & run TFW test and Angular frontend" - echo " |--- run: run TFW test and Angular frontend" - echo " |--- startcontainer: build & run TFW test, container only" - echo " |--- runcontainer: run TFW test, container only" + 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 test" - echo " |--- buildwithfrontend: build TFW baseimage and test, include frontend in image" + 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)" ;; From 6248da24e76f3e4f03706830760cbb44bfd0d317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Fri, 15 Jun 2018 15:47:06 +0200 Subject: [PATCH 04/14] Use locals where possible --- hack/libhack/challenge.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hack/libhack/challenge.sh b/hack/libhack/challenge.sh index 0f5ddb7..799532c 100644 --- a/hack/libhack/challenge.sh +++ b/hack/libhack/challenge.sh @@ -14,13 +14,13 @@ source "${libhack_dir}/common.sh" challenge::build() { pushd "${CHALLENGE_PATH}" - ARGS="--build-arg NOFRONTEND=1" build_challenge_internal + args="--build-arg NOFRONTEND=1" build_challenge_internal popd } challenge::build_with_frontend() { pushd "${CHALLENGE_PATH}" - ARGS="--no-cache" build_challenge_internal + args="--no-cache" build_challenge_internal popd } @@ -28,11 +28,14 @@ build_challenge_internal() { docker build -t "${IMAGE_NAME}" \ -f "${BUILD_CONTEXT}/Dockerfile" \ --build-arg BUILD_CONTEXT="${BUILD_CONTEXT}" \ - ${ARGS} . + ${args} . } challenge::run() { pushd "${TFW_PATH}" + local mount_baseimage + local mount_challenge + local mount_volumes 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" From cdbae9f39ef4519ab1b2f044298c0b54b6c64833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Fri, 15 Jun 2018 16:03:26 +0200 Subject: [PATCH 05/14] Refactor frontend stuff to libhack/frontend.sh --- hack/libhack/frontend.sh | 14 ++++++++++++++ hack/tfw.sh | 17 +++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 hack/libhack/frontend.sh diff --git a/hack/libhack/frontend.sh b/hack/libhack/frontend.sh new file mode 100644 index 0000000..64bfee5 --- /dev/null +++ b/hack/libhack/frontend.sh @@ -0,0 +1,14 @@ +# Requires context: +# - FRONTEND_PATH: absolute path of frontend repo +# - CHALLENGE_PATH: absolute path of challenge repo + + +frontend::run() { + local frontend_in_challenge="${CHALLENGE_PATH}/solvable/frontend" + if [[ "$(find "${frontend_in_challenge}" | wc -l)" -gt 2 ]];then + cd "${frontend_in_challenge}" + else + cd "${FRONTEND_PATH}" + fi + yarn start +} diff --git a/hack/tfw.sh b/hack/tfw.sh index 9ebd188..db2fd26 100755 --- a/hack/tfw.sh +++ b/hack/tfw.sh @@ -18,23 +18,13 @@ FRONTEND_PATH="${TFW_PATH}/${FRONTEND_REPO}" source "${SCRIPT_DIR}/libhack/baseimage.sh" source "${SCRIPT_DIR}/libhack/challenge.sh" +source "${SCRIPT_DIR}/libhack/frontend.sh" -run_frontend() { - FRONTEND_IN_CHALLENGE="${CHALLENGE_PATH}/solvable/frontend" - if [ "$(find "$FRONTEND_IN_CHALLENGE" | wc -l)" -gt 2 ] - then - cd $FRONTEND_IN_CHALLENGE - else - cd $FRONTEND_PATH - fi - yarn start -} - start_challenge_and_frontend() { trap 'exit' INT TERM trap 'kill 0' EXIT - [[ "${RUN_FRONTEND:-1}" == "1" ]] && run_frontend & + [[ "${RUN_FRONTEND:-1}" == "1" ]] && frontend::run & [[ "${BUILD:-1}" == "1" ]] && challenge::build challenge::run $@ wait @@ -55,6 +45,9 @@ case ${1:-} in runcontainer) BUILD=0 RUN_FRONTEND=0 start_challenge_and_frontend ${@:2} ;; + runfrontend) + frontend::run + ;; buildtfw) baseimage::build_if_exists ;; From f37e07d95551a56a43a6550a40ee12f4b24b0137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Fri, 15 Jun 2018 16:12:14 +0200 Subject: [PATCH 06/14] Fix TFWDEV=0 workflow --- hack/libhack/baseimage.sh | 2 +- hack/tfw.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hack/libhack/baseimage.sh b/hack/libhack/baseimage.sh index 5dd5f8c..7ee4d9b 100644 --- a/hack/libhack/baseimage.sh +++ b/hack/libhack/baseimage.sh @@ -22,7 +22,7 @@ baseimage::build() { } baseimage::build_if_exists() { - [[ -d "$BASEIMAGE_PATH" ]] && baseimage::build_as_latest + [[ -d "$BASEIMAGE_PATH" ]] && baseimage::build_as_latest || : } baseimage::tag_as_latest() { diff --git a/hack/tfw.sh b/hack/tfw.sh index db2fd26..825c8b9 100755 --- a/hack/tfw.sh +++ b/hack/tfw.sh @@ -60,10 +60,10 @@ case ${1:-} in challenge::build_with_frontend ;; releasetfw) - [[ -d "$BASEIMAGE_PATH" ]] && baseimage::release + [[ -d "$BASEIMAGE_PATH" ]] && baseimage::release || : ;; builddocs) - [[ -d "$BASEIMAGE_PATH" ]] && baseimage::builddocs + [[ -d "$BASEIMAGE_PATH" ]] && baseimage::builddocs || : ;; *) echo "Usage: tfw.sh [COMMAND]" From 8128866c863deb81ddc22dd6a4789efdf51b7373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Mon, 18 Jun 2018 14:53:10 +0200 Subject: [PATCH 07/14] Fix certain ifs in hack stuff --- hack/libhack/baseimage.sh | 7 ++++--- hack/libhack/challenge.sh | 6 ++++-- hack/tfw.sh | 8 ++++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/hack/libhack/baseimage.sh b/hack/libhack/baseimage.sh index 7ee4d9b..9f9b2e2 100644 --- a/hack/libhack/baseimage.sh +++ b/hack/libhack/baseimage.sh @@ -22,7 +22,9 @@ baseimage::build() { } baseimage::build_if_exists() { - [[ -d "$BASEIMAGE_PATH" ]] && baseimage::build_as_latest || : + if [[ -d "$BASEIMAGE_PATH" ]]; then + baseimage::build_as_latest + fi } baseimage::tag_as_latest() { @@ -36,8 +38,7 @@ baseimage::release() { local tag tag="$(releasename)" read -p "Tag and push new TFW version \"${tag}\"? [y/N]" -r && echo - if [[ $REPLY =~ ^(y|Y|yes|Yes|YES)$ ]] - then + if [[ $REPLY =~ ^(y|Y|yes|Yes|YES)$ ]]; then prompt_for_tag_description # This command sets $description tag="${tag}" description="${description}" force_push_tag fi diff --git a/hack/libhack/challenge.sh b/hack/libhack/challenge.sh index 799532c..d756e3c 100644 --- a/hack/libhack/challenge.sh +++ b/hack/libhack/challenge.sh @@ -36,8 +36,10 @@ challenge::run() { local mount_baseimage local mount_challenge local mount_volumes - if [ "${HOTRELOAD:-0}" == "1" ]; then - [ -d "${BASEIMAGE_PATH}" ] && mount_baseimage="-v ${BASEIMAGE_PATH}/lib/tfw:/usr/local/lib/tfw" + if [[ "${HOTRELOAD:-0}" == "1" ]]; then + if [[ -d "${BASEIMAGE_PATH}" ]]; then + mount_baseimage="-v ${BASEIMAGE_PATH}/lib/tfw:/usr/local/lib/tfw" + fi mount_challenge="-v ${CHALLENGE_PATH}/solvable/src:/srv/.tfw" mount_volumes="${mount_baseimage:-} ${mount_challenge}" fi diff --git a/hack/tfw.sh b/hack/tfw.sh index 825c8b9..9198b8a 100755 --- a/hack/tfw.sh +++ b/hack/tfw.sh @@ -60,10 +60,14 @@ case ${1:-} in challenge::build_with_frontend ;; releasetfw) - [[ -d "$BASEIMAGE_PATH" ]] && baseimage::release || : + if [[ -d "$BASEIMAGE_PATH" ]]; then + baseimage::release + fi ;; builddocs) - [[ -d "$BASEIMAGE_PATH" ]] && baseimage::builddocs || : + if [[ -d "$BASEIMAGE_PATH" ]]; then + baseimage::builddocs + fi ;; *) echo "Usage: tfw.sh [COMMAND]" From 0f9b5920c1bed77f403f470a005ca9c4659274d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Mon, 18 Jun 2018 15:17:43 +0200 Subject: [PATCH 08/14] Fix leftover legacy function names from libhack refactor --- hack/libhack/baseimage.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/libhack/baseimage.sh b/hack/libhack/baseimage.sh index 9f9b2e2..fcbab64 100644 --- a/hack/libhack/baseimage.sh +++ b/hack/libhack/baseimage.sh @@ -78,7 +78,7 @@ check_drone_releasename() { local drone_releasename local actual_releasename drone_releasename="$(grep -oP '(?<=branch:\srefs/tags/).+(?=-.+)' .drone.yml)" - actual_releasename="$(baseimage_releasename | grep -oP ".+(?=-\d{8})")" + actual_releasename="$(releasename | grep -oP ".+(?=-\d{8})")" if [ "${drone_releasename}" != "${actual_releasename}" ]; then echo "Release name '${drone_releasename}' in .drone.yml does not match \ actual release name '${actual_releasename}' in VERSION." From df285fea5812dfbd162c6830f049ea34546c2061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 19 Jun 2018 14:23:48 +0200 Subject: [PATCH 09/14] Integrate old bootstrap_tfw_dev.sh into tfw.sh --- hack/bootstrap_tfw_dev.sh | 193 --------------------------------- hack/libhack/baseimage.sh | 9 ++ hack/libhack/bootstrap.sh | 139 ++++++++++++++++++++++++ hack/libhack/common.sh | 16 +++ hack/oneline_install.sh | 1 - hack/tfw.sh | 9 +- hack/update_oneline_install.sh | 13 --- 7 files changed, 171 insertions(+), 209 deletions(-) delete mode 100755 hack/bootstrap_tfw_dev.sh create mode 100755 hack/libhack/bootstrap.sh delete mode 100644 hack/oneline_install.sh delete mode 100755 hack/update_oneline_install.sh diff --git a/hack/bootstrap_tfw_dev.sh b/hack/bootstrap_tfw_dev.sh deleted file mode 100755 index 826820c..0000000 --- a/hack/bootstrap_tfw_dev.sh +++ /dev/null @@ -1,193 +0,0 @@ -#!/usr/bin/env bash -set -eu -set -o pipefail -set -o errtrace -shopt -s expand_aliases -[ "$(uname)" == "Darwin" ] && alias sed="gsed" || : - -pushd() { command pushd "$@" > /dev/null; } -popd() { command popd "$@" > /dev/null; } - -TFWDEV="${TFWDEV:-0}" -HTTPS_REMOTES="${HTTPS_REMOTES:-}" - -TFW_POSTFIX=tutorial-framework -BASEDIR="$(pwd)" -BASEIMAGE=baseimage-${TFW_POSTFIX} -TEST=test-${TFW_POSTFIX} -FRONTEND=frontend-${TFW_POSTFIX} -BASEIMAGE_NAME="${BASEIMAGE_NAME:-eu.gcr.io/avatao-challengestore/tutorial-framework}" - -LOGFILE=/tmp/bootstrap_tfw.log - -remotebase="git@github.com:" - -run() -{ - trap 'exit 1' INT - trap handle_exit EXIT - : > $LOGFILE - - check_dependencies - clone_required_repos_ask_ssh_or_https - TAG="${BASEIMAGE_ONLY:-$(fetch_latest_tag)}" - TAG=$TAG build_baseimage - - if [ -z "${BASEIMAGE_ONLY:-}" ]; then - TAG=$TAG pin_baseimage - install_frontend_deps - if [ "$TFWDEV" == "0" ]; then - cleanup_repos - merge_repos - fi - else - delete_repos - fi - - echo - if [ -z "${BASEIMAGE_ONLY:-}" ]; then - echo "You can build & start TFW by executing the command: ${TEST}/hack/tfw.sh start" - else - echo "Baseimage version ${BASEIMAGE_ONLY} built successfully!" - fi -} - -handle_exit() -{ - if [[ $? -ne 0 ]]; then - delete_repos - showlog - fi - cleanlog -} - -showlog() { echo && echo "Error! Showing logs:" && cat $LOGFILE; } -cleanlog() { rm $LOGFILE; } -delete_repos() { pushd "$BASEDIR" && rm -rf "$BASEIMAGE" "$FRONTEND" "$TEST" && popd; } - -check_dependencies() -{ - dependencies=("git" "docker" "yarn" "ng") - missing="0" - for dep in ${dependencies[@]}; do - if ! type "$dep" > /dev/null 2>&1; then - logged echo "Dependency '${dep}' not found!" - missing="1" - fi - done - if [ "$missing" == "1" ]; then - logged echo "Please install the missing packages and retry!" - exit 1 - fi - - if [ "$TFWDEV" == "0" ]; then - if ! docker info > /dev/null 2>&1; then - logged echo "The Docker daemon appears to be stopped. Please start it and try again!" - exit 1 - fi - fi -} - -clone_required_repos_ask_ssh_or_https() -{ - if [[ -z "$HTTPS_REMOTES" ]]; then - read -p "Repos are pulled over SSH by default. Should I use HTTPS instead? [y/N]" -r -t 5 || : - echo - if [[ $REPLY =~ ^(y|Y|yes|Yes|YES)$ ]]; then - HTTPS_REMOTES=1 clone_required_repos - else - HTTPS_REMOTES=0 clone_required_repos - fi - else - clone_required_repos - fi -} - -clone_required_repos() -{ - [[ "$HTTPS_REMOTES" == "1" ]] && remotebase="https://github.com/" - - echo -n "Cloning TFW repositories... " - echo -n "baseimage... " && logged git clone ${remotebase}avatao-content/${BASEIMAGE}.git - if [ -z "${BASEIMAGE_ONLY:-}" ]; then - echo -n "frontend... " && logged git clone ${remotebase}avatao-content/${FRONTEND}.git - echo -n "test... " && logged git clone ${remotebase}avatao-content/${TEST}.git - fi - echo "Done!" -} - -install_frontend_deps() -{ - echo -n "Installing frontend dependencies... " - pushd "$FRONTEND" - spinned logged yarn install - popd - echo "Done!" -} - -fetch_latest_tag() -{ - echo -n "$(git ls-remote --tags ${remotebase}avatao-content/${BASEIMAGE}.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}... " - sed -i "1 s/.*/&:${TAG}/" "${TEST}/solvable/Dockerfile" - echo "Done!" -} - -build_baseimage() -{ - echo -n "Building baseimage at ${TAG}... " - pushd "$BASEIMAGE" - logged git checkout "$TAG" - spinned logged docker build -t "${BASEIMAGE_NAME}:${TAG}" . - popd - echo "Done!" -} - -cleanup_repos() -{ - rm -rf "${BASEIMAGE}" - rm -rf "${TEST}/.git" - rm -rf "${FRONTEND}/.git" -} - -merge_repos() -{ - echo -n "Merging repositories... " - NESTED_FRONTEND="${TEST}/solvable/frontend" - rm -rf $NESTED_FRONTEND - mv "$FRONTEND" "$NESTED_FRONTEND" - echo "Done!" -} - -logged() -{ - "$@" >> $LOGFILE 2>&1 -} - -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 -} - -run diff --git a/hack/libhack/baseimage.sh b/hack/libhack/baseimage.sh index fcbab64..df1ee15 100644 --- a/hack/libhack/baseimage.sh +++ b/hack/libhack/baseimage.sh @@ -1,5 +1,6 @@ # Requires context: # - BASEIMAGE_PATH: absolute path of baseimage repo +# - BASEIMAGE_REPO: basename of baseimage repo BASEIMAGE_NAME="${BASEIMAGE_NAME:-eu.gcr.io/avatao-challengestore/tutorial-framework}" @@ -66,6 +67,14 @@ 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/bootstrap.sh b/hack/libhack/bootstrap.sh new file mode 100755 index 0000000..d25eff6 --- /dev/null +++ b/hack/libhack/bootstrap.sh @@ -0,0 +1,139 @@ +HERE="$(pwd)" +CHALLENGE=${CHALLENGE:-test-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() { + trap 'exit 1' INT + trap handle_exit EXIT + : > "${LOGFILE}" + + check_dependencies + clone_required_repos_ask_ssh_or_https + local tag + tag="${BASEIMAGE_ONLY:-$(remotebase="${REMOTEBASE}" baseimage::latest_upstream_tag)}" + tag=${tag} build_baseimage + + if [ -z "${BASEIMAGE_ONLY:-}" ]; then + tag=${tag} pin_baseimage + install_frontend_deps + if [ "${TFWDEV:-0}" == "0" ]; then + cleanup_repos + merge_repos + fi + else + delete_repos + fi + + echo + if [ -z "${BASEIMAGE_ONLY:-}" ]; then + echo "You can build & start TFW by executing the command: ${CHALLENGE}/hack/tfw.sh start" + else + echo "Baseimage version ${BASEIMAGE_ONLY} built successfully!" + fi +} + +handle_exit() { + if [[ $? -ne 0 ]]; then + delete_repos + showlog + fi + cleanlog +} + +logged() { "$@" >> "${LOGFILE}" 2>&1; } +showlog() { echo && echo "Error! Showing logs:" && cat "${LOGFILE}"; } +cleanlog() { rm "${LOGFILE}"; } +delete_repos() { pushd "${HERE}" && rm -rf "${BASEIMAGE_REPO}" "${FRONTEND_REPO}" "${CHALLENGE}" && popd; } + +check_dependencies() { + local dependencies=("git" "docker" "yarn" "ng") + local missing="0" + for dep in ${dependencies[@]}; do + if ! type "${dep}" > /dev/null 2>&1; then + logged echo "Dependency '${dep}' not found!" + missing="1" + fi + done + if [ "${missing}" == "1" ]; then + logged echo "Please install the missing packages and retry!" + exit 1 + fi + + if [ "${TFWDEV:-0}" == "0" ]; then + if ! docker info > /dev/null 2>&1; then + logged echo "The Docker daemon appears to be stopped. Please start it and try again!" + exit 1 + fi + fi +} + +clone_required_repos_ask_ssh_or_https() { + if [[ "${HTTPS_REMOTES:-0}" == "1" ]]; then + read -p "Repos are pulled over SSH by default. Should I use HTTPS instead? [y/N]" -r -t 5 || : + echo + if [[ ${REPLY} =~ ^(y|Y|yes|Yes|YES)$ ]]; then + HTTPS_REMOTES=1 clone_required_repos + else + HTTPS_REMOTES=0 clone_required_repos + fi + else + clone_required_repos + fi +} + +clone_required_repos() { + [[ "${HTTPS_REMOTES:-0}" == "1" ]] && REMOTEBASE="https://github.com/avatao-content" + + echo -n "Cloning TFW repositories... " + echo -n "baseimage... " && logged git clone ${REMOTEBASE}/${BASEIMAGE_REPO}.git + if [ -z "${BASEIMAGE_ONLY:-}" ]; then + echo -n "frontend... " && logged git clone ${REMOTEBASE}/${FRONTEND_REPO}.git + echo -n "test... " && logged git clone ${REMOTEBASE}/${CHALLENGE}.git + fi + echo "Done!" +} + +install_frontend_deps() { + echo -n "Installing frontend dependencies... " + pushd "${FRONTEND_REPO}" + spinned logged yarn install + popd + echo "Done!" +} + +pin_baseimage() { + echo -n "Pinning TFW baseimage version... " + echo -n "which is ${tag}... " + sed -i "1 s/.*/&:${tag}/" "${CHALLENGE}/solvable/Dockerfile" + echo "Done!" +} + +build_baseimage() { + echo -n "Building baseimage at ${tag}... " + pushd "${BASEIMAGE_REPO}" + logged git checkout "${tag}" + spinned logged docker build -t "${BASEIMAGE_NAME}:${tag}" . + popd + echo "Done!" +} + +cleanup_repos() { + rm -rf "${BASEIMAGE_REPO}" + rm -rf "${CHALLENGE}/.git" + rm -rf "${FRONTEND_REPO}/.git" +} + +merge_repos() { + echo -n "Merging repositories... " + NESTED_FRONTEND="${CHALLENGE}/solvable/frontend" + rm -rf "${NESTED_FRONTEND}" + mv "${FRONTEND_REPO}" "${NESTED_FRONTEND}" + echo "Done!" +} diff --git a/hack/libhack/common.sh b/hack/libhack/common.sh index 95a908b..089e3aa 100644 --- a/hack/libhack/common.sh +++ b/hack/libhack/common.sh @@ -5,3 +5,19 @@ 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/oneline_install.sh b/hack/oneline_install.sh deleted file mode 100644 index dc1b5e3..0000000 --- a/hack/oneline_install.sh +++ /dev/null @@ -1 +0,0 @@ -URL=https://git.io/vxBfj SHA=d81057610588e16666251a4167f05841fc8b66ccd6988490c1a2d2deb6de8ffa bash -c 'cmd="$(curl -fsSL $URL)" && [ $(echo "$cmd" | sha256sum | cut -d " " -f1) == $SHA ] && echo "$cmd" | bash || echo Checksum mismatch!' diff --git a/hack/tfw.sh b/hack/tfw.sh index 9198b8a..71106b6 100755 --- a/hack/tfw.sh +++ b/hack/tfw.sh @@ -3,9 +3,9 @@ set -eu set -o pipefail set -o errtrace shopt -s expand_aliases -[ "$(uname)" == "Darwin" ] && alias readlink="greadlink" || : +[ "$(uname)" == "Darwin" ] && alias readlink="greadlink" && alias sed="gsed" || : -SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" +SCRIPT_DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" TFW_PATH="${TFW_PATH:-$SCRIPT_DIR/../..}" BASEIMAGE_REPO="${BASEIMAGE_REPO:-baseimage-tutorial-framework}" @@ -19,6 +19,7 @@ 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() { @@ -31,6 +32,9 @@ 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} @@ -71,6 +75,7 @@ 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" diff --git a/hack/update_oneline_install.sh b/hack/update_oneline_install.sh deleted file mode 100755 index f7c3be0..0000000 --- a/hack/update_oneline_install.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash -set -eu -set -o pipefail -set -o errtrace -shopt -s expand_aliases - -if [ "$(uname)" == "Darwin" ]; then - alias readlink="greadlink" - alias sed="gsed" -fi -SCRIPT_DIR="$(dirname $(readlink -f $0))" - -sed -i "s/SHA=\w\+/SHA=$(sha256sum hack/bootstrap_tfw_dev.sh | cut -d ' ' -f1)/g" "${SCRIPT_DIR}/oneline_install.sh" From 51cd837e3a546a90f5bdd6d3335170daac44d3bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 20 Jun 2018 17:10:30 +0200 Subject: [PATCH 10/14] Fix remote ask logic broken by refactor streak --- hack/libhack/bootstrap.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/libhack/bootstrap.sh b/hack/libhack/bootstrap.sh index d25eff6..d1f86cf 100755 --- a/hack/libhack/bootstrap.sh +++ b/hack/libhack/bootstrap.sh @@ -75,7 +75,7 @@ check_dependencies() { } clone_required_repos_ask_ssh_or_https() { - if [[ "${HTTPS_REMOTES:-0}" == "1" ]]; then + if [[ -z "${HTTPS_REMOTES:-}" ]]; then read -p "Repos are pulled over SSH by default. Should I use HTTPS instead? [y/N]" -r -t 5 || : echo if [[ ${REPLY} =~ ^(y|Y|yes|Yes|YES)$ ]]; then From 7567bcb891f49489090eff24301758a656a2334f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 27 Jun 2018 10:36:44 +0200 Subject: [PATCH 11/14] Elaborate creating proxy-aware web applications in readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index ad8acad..b550c7e 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,9 @@ location /yoururl { ``` After this you can access the service running on port `3333` at `http://localhost:8888/yoururl` +It is very important to understand that from now on your application must behave well behind a reverse proxy. +What this means is all `href`s must point the proxied paths (e.g. links should refer to `/yoururl/register` instead of `/register`) on your HTML pages. + You can learn about configuring nginx in [this](https://www.digitalocean.com/community/tutorials/understanding-the-nginx-configuration-file-structure-and-configuration-contexts) handy little tutorial. ### supervisor From 043ae9580134956a2e7d08eae10fdc069fdd9e93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 27 Jun 2018 13:57:00 +0200 Subject: [PATCH 12/14] Strip bootstrap.sh from tfw.sh as Dockerization efforts are abandoned --- hack/{libhack => }/bootstrap.sh | 53 ++++++++++++++++++++++++++++----- hack/libhack/baseimage.sh | 8 ----- hack/libhack/common.sh | 16 ---------- hack/tfw.sh | 7 +---- 4 files changed, 47 insertions(+), 37 deletions(-) rename hack/{libhack => }/bootstrap.sh (76%) 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" From 1507a9338b453bf9be7d0a576b61a1539ffcb630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 27 Jun 2018 14:35:06 +0200 Subject: [PATCH 13/14] Implement invalid tag detection --- hack/bootstrap.sh | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/hack/bootstrap.sh b/hack/bootstrap.sh index fa63117..c63781d 100755 --- a/hack/bootstrap.sh +++ b/hack/bootstrap.sh @@ -23,6 +23,7 @@ run() { clone_required_repos_ask_ssh_or_https local tag tag="${BASEIMAGE_ONLY:-$(remotebase="${REMOTEBASE}" baseimage_latest_upstream_tag)}" + tag=${tag} verify_baseimage_tag tag=${tag} build_baseimage if [ -z "${BASEIMAGE_ONLY:-}" ]; then @@ -105,14 +106,6 @@ clone_required_repos() { echo "Done!" } -install_frontend_deps() { - echo -n "Installing frontend dependencies... " - pushd "${FRONTEND_REPO}" - spinned logged yarn install - popd - echo "Done!" -} - baseimage_latest_upstream_tag() { echo -n "$(git ls-remote --tags ${remotebase}/${BASEIMAGE_REPO}.git | cut -f2 | @@ -121,6 +114,18 @@ baseimage_latest_upstream_tag() { tail -n 1)" } +verify_baseimage_tag() { + pushd "${BASEIMAGE_REPO}" + local statuscode + if ! git rev-parse --quiet \ + --verify \ + "refs/tags/${tag}" &> /dev/null; then + logged echo "${tag} is not a valid tag!" + exit 1 + fi + popd +} + pin_baseimage() { echo -n "Pinning TFW baseimage version... " echo -n "which is ${tag}... " @@ -137,6 +142,14 @@ build_baseimage() { echo "Done!" } +install_frontend_deps() { + echo -n "Installing frontend dependencies... " + pushd "${FRONTEND_REPO}" + spinned logged yarn install + popd + echo "Done!" +} + cleanup_repos() { rm -rf "${BASEIMAGE_REPO}" rm -rf "${CHALLENGE}/.git" From f71d94e8dcd20da54f3710ec1325e9c8f2846c30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 27 Jun 2018 14:38:11 +0200 Subject: [PATCH 14/14] Fix delete_repos broken directory changing logic --- hack/bootstrap.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/bootstrap.sh b/hack/bootstrap.sh index c63781d..643a9cc 100755 --- a/hack/bootstrap.sh +++ b/hack/bootstrap.sh @@ -56,7 +56,7 @@ handle_exit() { logged() { "$@" >> "${LOGFILE}" 2>&1; } showlog() { echo && echo "Error! Showing logs:" && cat "${LOGFILE}"; } cleanlog() { rm "${LOGFILE}"; } -delete_repos() { pushd "${HERE}" && rm -rf "${BASEIMAGE_REPO}" "${FRONTEND_REPO}" "${CHALLENGE}" && popd; } +delete_repos() { cd "${HERE}" && rm -rf "${BASEIMAGE_REPO}" "${FRONTEND_REPO}" "${CHALLENGE}"; } check_dependencies() { local dependencies=("git" "docker" "yarn" "ng")