mirror of
https://github.com/avatao-content/test-tutorial-framework
synced 2024-11-14 22:07:17 +00:00
130 lines
3.1 KiB
Bash
Executable File
130 lines
3.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -e
|
|
set -o pipefail
|
|
set -o errtrace
|
|
shopt -s expand_aliases
|
|
[ "$(uname)" == "Darwin" ] && alias readlink="greadlink" || :
|
|
|
|
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}"
|
|
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:-eu.gcr.io/avatao-challengestore/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}:${TFWTAG:-$(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_internal()
|
|
{
|
|
build_baseimage
|
|
cd $TEST_PATH
|
|
docker build -t $IMAGE_NAME \
|
|
-f ${BUILD_CONTEXT}/Dockerfile \
|
|
--build-arg BUILD_CONTEXT=$BUILD_CONTEXT \
|
|
${ARGS} .
|
|
}
|
|
|
|
build_test()
|
|
{
|
|
ARGS="--build-arg NOFRONTEND=1" build_test_internal
|
|
}
|
|
|
|
build_test_withfrontend()
|
|
{
|
|
ARGS="--no-cache" build_test_internal
|
|
}
|
|
|
|
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
|
|
;;
|
|
buildwithfrontend)
|
|
build_test_withfrontend
|
|
;;
|
|
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 " |--- buildwithfrontend: build TFW test, include frontend in image"
|
|
echo " |--- start: build & start TFW test"
|
|
;;
|
|
esac
|