mirror of
https://github.com/avatao-content/test-tutorial-framework
synced 2024-11-15 02:17:16 +00:00
124 lines
2.9 KiB
Bash
Executable File
124 lines
2.9 KiB
Bash
Executable File
#!/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}"
|
|
TFW_POSTFIX=tutorial-framework
|
|
BASEDIR="$(pwd)"
|
|
BASEIMAGE=baseimage-${TFW_POSTFIX}
|
|
TEST=test-${TFW_POSTFIX}
|
|
FRONTEND=frontend-${TFW_POSTFIX}
|
|
|
|
LOGFILE=/tmp/bootstrap_tfw.log
|
|
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"
|
|
}
|
|
|
|
|
|
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() { cd "$BASEDIR" && rm -rf "$BASEIMAGE" "$FRONTEND" "$TEST"; }
|
|
|
|
clone_repos()
|
|
{
|
|
echo -n "Cloning TFW repositories... "
|
|
echo -n "baseimage... " && spinned logged git clone git@github.com:avatao-content/${BASEIMAGE}.git
|
|
echo -n "frontend... " && spinned logged git clone git@github.com:avatao-content/${FRONTEND}.git
|
|
echo -n "test... " && spinned logged git clone git@github.com:avatao-content/${TEST}.git
|
|
echo "Done!"
|
|
}
|
|
|
|
install_frontend_deps()
|
|
{
|
|
echo -n "Installing frontend dependencies... "
|
|
pushd "$FRONTEND"
|
|
spinned logged yarn install
|
|
popd
|
|
echo "Done!"
|
|
}
|
|
|
|
pin_latest_baseimage()
|
|
{
|
|
echo -n "Pinning latest TFW baseimage version... "
|
|
echo -n "which is ${LATESTTAG}... "
|
|
sed -i "1 s/.*/&:${LATESTTAG}/" "${TEST}/solvable/Dockerfile"
|
|
echo "Done!"
|
|
}
|
|
|
|
build_latest_baseimage()
|
|
{
|
|
echo -n "Building baseimage at ${LATESTTAG}... "
|
|
pushd "$BASEIMAGE"
|
|
spinned logged git checkout "$LATESTTAG"
|
|
popd
|
|
TFWTAG=$LATESTTAG spinned logged ${TEST}/hack/tfw.sh buildtfw
|
|
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!"
|
|
}
|
|
|
|
run
|