1
0
mirror of https://github.com/avatao-content/test-tutorial-framework synced 2024-11-14 15:47:17 +00:00
test-tutorial-framework/hack/tfw.sh
2018-03-31 19:43:02 +02:00

107 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -eo pipefail
[ "$(uname)" == "Darwin" ] && readlink_cmd="greadlink" || readlink_cmd="readlink"
SCRIPT_DIR="$(dirname $($readlink_cmd -f $0))"
TAO_PATH="${TAO_PATH:-$SCRIPT_DIR/../..}"
BASEIMAGE_REPO="${BASEIMAGE_REPO:-baseimage-tutorial-framework}"
TEST_REPO="${TEST_REPO:-test-tutorial-framework}"
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}"
BASEIMAGE_NAME="${BASEIMAGE_NAME:-avatao/tutorial-framework}"
IMAGE_NAME="${IMAGE_NAME:-test-tutorial-framework}"
TEST_PORT="${TEST_PORT:-8888}"
AVATAO_SECRET="${AVATAO_SECRET:-secret}"
BUILD_CONTEXT="${BUILD_CONTEXT:-solvable}"
build_baseimage()
{
[ ! -d "$BASEIMAGE_PATH" ] && return || :
cd $BASEIMAGE_PATH
docker build -t "${BASEIMAGE_NAME}:$(baseimage_releasename)" -t "${BASEIMAGE_NAME}:latest" .
}
release_baseimage()
{
[ ! -d "$BASEIMAGE_PATH" ] && return || :
cd $BASEIMAGE_PATH
TAG="$(baseimage_releasename)"
read -p "Tag and push new TFW version \"${TAG}\"? [y/N]" -r && echo
if [[ $REPLY =~ ^(y|Y|yes|Yes|YES)$ ]]
then
git tag -s -m "$1" "$TAG"
git push origin $TAG
fi
}
baseimage_releasename()
{
VERSION="$(cat VERSION | head -n 1)"
DATE="$(date +%Y%m%d)"
printf "${VERSION}-${DATE}"
}
build_test()
{
build_baseimage
cd $TEST_PATH
docker build -t $IMAGE_NAME -f ${BUILD_CONTEXT}/Dockerfile --build-arg BUILD_CONTEXT=$BUILD_CONTEXT --build-arg NOFRONTEND=1 .
}
run_test()
{
docker run --rm -p $TEST_PORT:$TEST_PORT -e AVATAO_SECRET=$AVATAO_SECRET $IMAGE_NAME
}
build_and_run_test()
{
build_test
run_test
}
run_frontend()
{
FRONTEND_IN_TEST="${TEST_PATH}/solvable/frontend"
if [ "$(find "$FRONTEND_IN_TEST" | wc -l)" -gt 2 ]
then
cd $FRONTEND_IN_TEST
else
cd $FRONTEND_PATH
fi
yarn start
}
start_test()
{
trap 'exit' INT TERM
trap 'kill 0' EXIT
run_frontend & build_and_run_test
wait
}
case $1 in
buildtfw)
build_baseimage
;;
releasetfw)
release_baseimage
;;
build)
build_test
;;
start)
start_test
;;
*)
echo "Usage: tfw.sh [buildtfw|build|start|buildstart]"
echo " |--- buildtfw: build TFW baseimage"
echo " |--- releasetfw: tag TFW baseimage and push to upstream"
echo " |--- build: build TFW test"
echo " |--- start: build & start TFW test"
;;
esac