2018-03-23 20:40:24 +00:00
|
|
|
#!/usr/bin/env bash
|
2018-04-16 18:45:04 +00:00
|
|
|
set -eu
|
2018-04-15 19:22:56 +00:00
|
|
|
set -o pipefail
|
|
|
|
set -o errtrace
|
2018-04-03 16:03:12 +00:00
|
|
|
shopt -s expand_aliases
|
2018-04-14 22:31:47 +00:00
|
|
|
[ "$(uname)" == "Darwin" ] && alias sed="gsed" || :
|
2018-03-23 16:58:24 +00:00
|
|
|
|
2018-04-27 09:27:23 +00:00
|
|
|
pushd() { command pushd "$@" > /dev/null; }
|
|
|
|
popd() { command popd "$@" > /dev/null; }
|
|
|
|
|
2018-04-16 18:45:04 +00:00
|
|
|
TFWDEV="${TFWDEV:-0}"
|
2018-03-24 10:47:38 +00:00
|
|
|
TFW_POSTFIX=tutorial-framework
|
2018-04-27 09:28:00 +00:00
|
|
|
BASEDIR="$(pwd)"
|
2018-03-24 10:47:38 +00:00
|
|
|
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}
|
2018-04-27 09:27:23 +00:00
|
|
|
|
2018-03-24 10:47:38 +00:00
|
|
|
LOGFILE=/tmp/bootstrap_tfw.log
|
2018-04-27 09:27:23 +00:00
|
|
|
logged() { "$@" >> $LOGFILE 2>&1; }
|
2018-03-24 11:18:59 +00:00
|
|
|
|
2018-04-27 09:40:34 +00:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-14 22:31:47 +00:00
|
|
|
run()
|
|
|
|
{
|
|
|
|
trap 'err_cleanup; showlog' ERR
|
|
|
|
trap cleanlog EXIT
|
|
|
|
: > $LOGFILE
|
|
|
|
|
|
|
|
clone_repos
|
|
|
|
install_frontend_deps
|
2018-04-16 18:45:04 +00:00
|
|
|
if [ "$TFWDEV" == "0" ]; then
|
2018-04-14 22:31:47 +00:00
|
|
|
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"
|
|
|
|
}
|
2018-03-30 23:26:17 +00:00
|
|
|
|
2018-03-24 11:18:59 +00:00
|
|
|
showlog() { echo && echo "Error! Showing logs:" && cat $LOGFILE; }
|
|
|
|
cleanlog() { rm $LOGFILE; }
|
2018-04-27 09:28:00 +00:00
|
|
|
err_cleanup() { cd "$BASEDIR" && rm -rf "$BASEIMAGE" "$FRONTEND" "$TEST"; }
|
2018-04-14 22:31:47 +00:00
|
|
|
|
|
|
|
clone_repos()
|
|
|
|
{
|
|
|
|
echo -n "Cloning TFW repositories... "
|
2018-04-27 09:40:34 +00:00
|
|
|
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
|
2018-04-14 22:31:47 +00:00
|
|
|
echo "Done!"
|
|
|
|
}
|
|
|
|
|
|
|
|
install_frontend_deps()
|
|
|
|
{
|
|
|
|
echo -n "Installing frontend dependencies... "
|
2018-04-27 09:27:23 +00:00
|
|
|
pushd "$FRONTEND"
|
2018-04-27 09:40:34 +00:00
|
|
|
spinned logged yarn install
|
2018-04-27 09:27:23 +00:00
|
|
|
popd
|
2018-04-14 22:31:47 +00:00
|
|
|
echo "Done!"
|
|
|
|
}
|
|
|
|
|
|
|
|
pin_latest_baseimage()
|
|
|
|
{
|
2018-03-31 19:22:33 +00:00
|
|
|
echo -n "Pinning latest TFW baseimage version... "
|
2018-04-06 08:23:56 +00:00
|
|
|
echo -n "which is ${LATESTTAG}... "
|
2018-04-03 16:03:12 +00:00
|
|
|
sed -i "1 s/.*/&:${LATESTTAG}/" "${TEST}/solvable/Dockerfile"
|
2018-03-31 19:22:33 +00:00
|
|
|
echo "Done!"
|
2018-04-14 22:31:47 +00:00
|
|
|
}
|
2018-03-31 17:19:16 +00:00
|
|
|
|
2018-04-14 22:31:47 +00:00
|
|
|
build_latest_baseimage()
|
|
|
|
{
|
2018-04-14 08:10:02 +00:00
|
|
|
echo -n "Building baseimage at ${LATESTTAG}... "
|
2018-04-27 09:27:23 +00:00
|
|
|
pushd "$BASEIMAGE"
|
2018-04-27 09:40:34 +00:00
|
|
|
spinned logged git checkout "$LATESTTAG"
|
2018-04-27 09:27:23 +00:00
|
|
|
popd
|
2018-04-27 09:40:34 +00:00
|
|
|
TFWTAG=$LATESTTAG spinned logged ${TEST}/hack/tfw.sh buildtfw
|
2018-04-14 00:48:26 +00:00
|
|
|
echo "Done!"
|
2018-04-14 22:31:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)"
|
|
|
|
}
|
2018-04-14 00:48:26 +00:00
|
|
|
|
2018-04-14 22:31:47 +00:00
|
|
|
cleanup_repos()
|
|
|
|
{
|
2018-04-14 00:48:26 +00:00
|
|
|
rm -rf "${BASEIMAGE}"
|
2018-03-30 23:26:17 +00:00
|
|
|
rm -rf "${TEST}/.git"
|
|
|
|
rm -rf "${FRONTEND}/.git"
|
2018-04-14 22:31:47 +00:00
|
|
|
}
|
2018-03-30 23:26:17 +00:00
|
|
|
|
2018-04-14 22:31:47 +00:00
|
|
|
merge_repos()
|
|
|
|
{
|
2018-03-31 19:22:33 +00:00
|
|
|
echo -n "Merging repositories... "
|
2018-03-31 17:19:16 +00:00
|
|
|
NESTED_FRONTEND="${TEST}/solvable/frontend"
|
|
|
|
rm -rf $NESTED_FRONTEND
|
|
|
|
mv "$FRONTEND" "$NESTED_FRONTEND"
|
2018-03-31 19:22:33 +00:00
|
|
|
echo "Done!"
|
2018-04-14 22:31:47 +00:00
|
|
|
}
|
2018-03-23 16:58:24 +00:00
|
|
|
|
2018-04-14 22:31:47 +00:00
|
|
|
run
|