mirror of
https://github.com/avatao-content/test-tutorial-framework
synced 2024-11-14 16:17:17 +00:00
113 lines
2.6 KiB
Bash
Executable File
113 lines
2.6 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}"
|
|
|
|
run_frontend()
|
|
{
|
|
cd $FRONTEND_PATH
|
|
yarn start
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
build_baseimage()
|
|
{
|
|
[ ! -d "$BASEIMAGE_PATH" ] && return || :
|
|
cd $BASEIMAGE_PATH
|
|
docker build -t "${BASEIMAGE_NAME}:$(baseimage_releasename)" -t "${BASEIMAGE_NAME}:latest" .
|
|
}
|
|
|
|
baseimage_releasename()
|
|
{
|
|
VERSION="$(cat VERSION | head -n 1)"
|
|
DATE="$(date +%Y%m%d)"
|
|
printf "${VERSION}-${DATE}"
|
|
}
|
|
|
|
build_test()
|
|
{
|
|
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
|
|
}
|
|
|
|
build_and_start_tfw()
|
|
{
|
|
trap 'exit' INT TERM
|
|
trap 'kill 0' EXIT
|
|
build_baseimage
|
|
run_frontend & build_and_run_test
|
|
wait
|
|
}
|
|
|
|
start_tfw()
|
|
{
|
|
trap 'exit' INT TERM
|
|
trap 'kill 0' EXIT
|
|
run_frontend & run_test
|
|
wait
|
|
}
|
|
|
|
case $1 in
|
|
buildtfw)
|
|
build_baseimage
|
|
;;
|
|
build)
|
|
build_test
|
|
;;
|
|
start)
|
|
start_tfw
|
|
;;
|
|
buildstart)
|
|
build_and_start_tfw
|
|
;;
|
|
release)
|
|
release_baseimage
|
|
;;
|
|
*)
|
|
echo "Usage: tfw.sh [buildtfw|build|start|buildstart]"
|
|
echo " |--- buildtfw: build TFW baseimage"
|
|
echo " |--- build: build TFW test"
|
|
echo " |--- start: start TFW test"
|
|
echo " |--- buildstart: build all, then start TFW test"
|
|
echo " |--- release: tag TFW baseimage and push to upstream"
|
|
;;
|
|
esac
|