1
0
mirror of https://github.com/avatao-content/test-tutorial-framework synced 2024-11-15 05:57:18 +00:00
test-tutorial-framework/hack/bootstrap_tfw_dev.sh

101 lines
2.5 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
set -eu
2018-04-15 19:22:56 +00:00
set -o pipefail
set -o errtrace
shopt -s expand_aliases
[ "$(uname)" == "Darwin" ] && alias sed="gsed" || :
TFWDEV="${TFWDEV:-0}"
2018-03-24 10:47:38 +00:00
TFW_POSTFIX=tutorial-framework
BASEIMAGE=baseimage-${TFW_POSTFIX}
2018-03-30 21:56:14 +00:00
TEST=test-${TFW_POSTFIX}
2018-03-24 10:47:38 +00:00
FRONTEND=frontend-${TFW_POSTFIX}
LOGFILE=/tmp/bootstrap_tfw.log
run()
{
trap 'err_cleanup; showlog' ERR
trap cleanlog EXIT
: > $LOGFILE
clone_repos
install_frontend_deps
if [ "$TFWDEV" == "0" ]; 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"; }
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!"
}
install_frontend_deps()
{
echo -n "Installing frontend dependencies... "
cd "$FRONTEND"
yarn install >> $LOGFILE 2>&1
cd ..
echo "Done!"
}
pin_latest_baseimage()
{
2018-03-31 19:22:33 +00:00
echo -n "Pinning latest TFW baseimage version... "
echo -n "which is ${LATESTTAG}... "
sed -i "1 s/.*/&:${LATESTTAG}/" "${TEST}/solvable/Dockerfile"
2018-03-31 19:22:33 +00:00
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()
{
2018-03-31 19:22:33 +00:00
echo -n "Merging repositories... "
NESTED_FRONTEND="${TEST}/solvable/frontend"
rm -rf $NESTED_FRONTEND
mv "$FRONTEND" "$NESTED_FRONTEND"
2018-03-31 19:22:33 +00:00
echo "Done!"
}
run