From a33a04f4ad0422028f84d7c484ae965653049cf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Sun, 15 Apr 2018 00:31:47 +0200 Subject: [PATCH 1/3] Refactor bootstrap script to better handle increased complexity --- hack/bootstrap_tfw_dev.sh | 81 ++++++++++++++++++++++++++++----------- hack/oneline_install.sh | 2 +- 2 files changed, 59 insertions(+), 24 deletions(-) diff --git a/hack/bootstrap_tfw_dev.sh b/hack/bootstrap_tfw_dev.sh index 2fddbb3..5d1e9ca 100755 --- a/hack/bootstrap_tfw_dev.sh +++ b/hack/bootstrap_tfw_dev.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash set -eo pipefail shopt -s expand_aliases +[ "$(uname)" == "Darwin" ] && alias sed="gsed" || : TFW_POSTFIX=tutorial-framework BASEIMAGE=baseimage-${TFW_POSTFIX} @@ -8,55 +9,89 @@ TEST=test-${TFW_POSTFIX} FRONTEND=frontend-${TFW_POSTFIX} LOGFILE=/tmp/bootstrap_tfw.log -[ "$(uname)" == "Darwin" ] && alias sed="gsed" || : +run() +{ + trap 'err_cleanup; showlog' ERR + trap cleanlog EXIT + : > $LOGFILE + + clone_repos + install_frontend_deps + if [ -z "$TFWDEV" ]; then + LATESTTAG="$(fetch_latest_tag)" + LATESTTAG=$LATESTTAG pin_latest_baseimage + LATESTTAG=$LATESTTAG build_latest_baseimage + cleanup_repos + merge_repos + fi + + echo + echo "You can build & start TFW by executing the command: ${TEST}/hack/tfw.sh start" +} showlog() { echo && echo "Error! Showing logs:" && cat $LOGFILE; } cleanlog() { rm $LOGFILE; } err_cleanup() { rm -rf "$BASEIMAGE" "$FRONTEND" "$TEST"; } -trap 'err_cleanup; showlog' ERR -trap cleanlog EXIT -: > $LOGFILE -echo -n "Cloning TFW repositories... " -echo -n "baseimage... " && git clone git@github.com:avatao-content/${BASEIMAGE}.git >> $LOGFILE 2>&1 -echo -n "frontend... " && git clone git@github.com:avatao-content/${FRONTEND}.git >> $LOGFILE 2>&1 -echo -n "test... " && git clone git@github.com:avatao-content/${TEST}.git >> $LOGFILE 2>&1 -echo "Done!" +clone_repos() +{ + echo -n "Cloning TFW repositories... " + echo -n "baseimage... " && git clone git@github.com:avatao-content/${BASEIMAGE}.git >> $LOGFILE 2>&1 + echo -n "frontend... " && git clone git@github.com:avatao-content/${FRONTEND}.git >> $LOGFILE 2>&1 + echo -n "test... " && git clone git@github.com:avatao-content/${TEST}.git >> $LOGFILE 2>&1 + echo "Done!" +} -echo -n "Installing frontend dependencies... " -cd "$FRONTEND" -yarn install >> $LOGFILE 2>&1 -cd .. -echo "Done!" +install_frontend_deps() +{ + echo -n "Installing frontend dependencies... " + cd "$FRONTEND" + yarn install >> $LOGFILE 2>&1 + cd .. + echo "Done!" +} -if [ -z "$TFWDEV" ]; then +pin_latest_baseimage() +{ echo -n "Pinning latest TFW baseimage version... " - LATESTTAG="$(git ls-remote --tags git@github.com:avatao-content/${BASEIMAGE}.git | - cut -f2 | - grep -oP '(?<=refs/tags/)\w+-\d{8}$' | - sort -t '-' -k2 | - tail -n 1)" echo -n "which is ${LATESTTAG}... " sed -i "1 s/.*/&:${LATESTTAG}/" "${TEST}/solvable/Dockerfile" echo "Done!" +} +build_latest_baseimage() +{ echo -n "Building baseimage at ${LATESTTAG}... " cd "$BASEIMAGE" git checkout "$LATESTTAG" >> $LOGFILE 2>&1 cd .. TFWTAG=$LATESTTAG ${TEST}/hack/tfw.sh buildtfw >> $LOGFILE 2>&1 echo "Done!" +} +fetch_latest_tag() +{ + echo -n "$(git ls-remote --tags git@github.com:avatao-content/${BASEIMAGE}.git | + cut -f2 | + grep -oP '(?<=refs/tags/)\w+-\d{8}$' | + sort -t '-' -k2 | + tail -n 1)" +} + +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!" -fi +} -echo -echo "You can build & start TFW by executing the command: ${TEST}/hack/tfw.sh start" +run diff --git a/hack/oneline_install.sh b/hack/oneline_install.sh index a40047d..ec37b59 100644 --- a/hack/oneline_install.sh +++ b/hack/oneline_install.sh @@ -1 +1 @@ -URL=https://git.io/vxBfj SHA=dcc634915977f14e32a65d0601ebbfe4cc1cd46b77a1b1de7dd157744e616851 bash -c 'cmd="$(curl -fsSL $URL)" && [ $(echo "$cmd" | sha256sum | cut -d " " -f1) == $SHA ] && echo "$cmd" | bash || echo Checksum mismatch!' +URL=https://git.io/vxBfj SHA=d8d41c268c36bbc972ac0ebf01fddc39bb8f53dab59c30d6ed3e46b98cbccfa2 bash -c 'cmd="$(curl -fsSL $URL)" && [ $(echo "$cmd" | sha256sum | cut -d " " -f1) == $SHA ] && echo "$cmd" | bash || echo Checksum mismatch!' From 8812c59b6023764e8138ecf4bc073a825a59e621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Sun, 15 Apr 2018 21:22:56 +0200 Subject: [PATCH 2/3] Fix broken traps --- hack/bootstrap_tfw_dev.sh | 4 +++- hack/oneline_install.sh | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/hack/bootstrap_tfw_dev.sh b/hack/bootstrap_tfw_dev.sh index 5d1e9ca..fd39447 100755 --- a/hack/bootstrap_tfw_dev.sh +++ b/hack/bootstrap_tfw_dev.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash -set -eo pipefail +set -e +set -o pipefail +set -o errtrace shopt -s expand_aliases [ "$(uname)" == "Darwin" ] && alias sed="gsed" || : diff --git a/hack/oneline_install.sh b/hack/oneline_install.sh index ec37b59..c9690d3 100644 --- a/hack/oneline_install.sh +++ b/hack/oneline_install.sh @@ -1 +1 @@ -URL=https://git.io/vxBfj SHA=d8d41c268c36bbc972ac0ebf01fddc39bb8f53dab59c30d6ed3e46b98cbccfa2 bash -c 'cmd="$(curl -fsSL $URL)" && [ $(echo "$cmd" | sha256sum | cut -d " " -f1) == $SHA ] && echo "$cmd" | bash || echo Checksum mismatch!' +URL=https://git.io/vxBfj SHA=e72bc2836448c4ab0171d637b459546f927ae7ec63cafa2bf4596f50eaaa0aec bash -c 'cmd="$(curl -fsSL $URL)" && [ $(echo "$cmd" | sha256sum | cut -d " " -f1) == $SHA ] && echo "$cmd" | bash || echo Checksum mismatch!' From f9a97eb25306253be6216b19b6f349875c2e18d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Sun, 15 Apr 2018 21:50:43 +0200 Subject: [PATCH 3/3] Make script headers consistent --- hack/tfw.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hack/tfw.sh b/hack/tfw.sh index a6ca836..67fba1e 100755 --- a/hack/tfw.sh +++ b/hack/tfw.sh @@ -1,10 +1,11 @@ #!/usr/bin/env bash -set -eo pipefail +set -e +set -o pipefail +set -o errtrace shopt -s expand_aliases - [ "$(uname)" == "Darwin" ] && alias readlink="greadlink" || : -SCRIPT_DIR="$(dirname $(readlink -f $0))" +SCRIPT_DIR="$(dirname $(readlink -f $0))" TAO_PATH="${TAO_PATH:-$SCRIPT_DIR/../..}" BASEIMAGE_REPO="${BASEIMAGE_REPO:-baseimage-tutorial-framework}" TEST_REPO="${TEST_REPO:-test-tutorial-framework}"