2018-03-23 16:58:24 +00:00
|
|
|
#!/usr/bin/env bash
|
2018-03-23 20:39:39 +00:00
|
|
|
set -eo pipefail
|
2018-03-23 16:58:24 +00:00
|
|
|
|
|
|
|
[ "$(uname)" == "Darwin" ] && readlink_cmd="greadlink" || readlink_cmd="readlink"
|
|
|
|
SCRIPT_DIR="$(dirname $($readlink_cmd -f $0))"
|
|
|
|
|
|
|
|
TAO_PATH="${TAO_PATH:-$SCRIPT_DIR/../..}"
|
2018-03-25 14:03:13 +00:00
|
|
|
BASEIMAGE_REPO="${BASEIMAGE_REPO:-baseimage-tutorial-framework}"
|
2018-03-30 17:38:36 +00:00
|
|
|
TEST_REPO="${TEST_REPO:-test-tutorial-framework}"
|
2018-03-23 16:58:24 +00:00
|
|
|
FRONTEND_REPO="${FRONTEND_REPO:-frontend-tutorial-framework}"
|
2018-03-25 14:03:13 +00:00
|
|
|
BASEIMAGE_PATH="${TAO_PATH}/${BASEIMAGE_REPO}"
|
2018-03-30 17:38:36 +00:00
|
|
|
TEST_PATH="${TAO_PATH}/${TEST_REPO}"
|
2018-03-23 16:58:24 +00:00
|
|
|
FRONTEND_PATH="${TAO_PATH}/${FRONTEND_REPO}"
|
|
|
|
|
2018-03-30 19:13:21 +00:00
|
|
|
BASEIMAGE_NAME="${BASEIMAGE_NAME:-avatao/tutorial-framework}"
|
2018-03-25 14:03:13 +00:00
|
|
|
IMAGE_NAME="${IMAGE_NAME:-test-tutorial-framework}"
|
2018-03-30 17:38:36 +00:00
|
|
|
TEST_PORT="${TEST_PORT:-8888}"
|
2018-03-23 16:58:24 +00:00
|
|
|
AVATAO_SECRET="${AVATAO_SECRET:-secret}"
|
|
|
|
BUILD_CONTEXT="${BUILD_CONTEXT:-solvable}"
|
|
|
|
|
2018-03-25 14:06:16 +00:00
|
|
|
run_frontend()
|
2018-03-23 16:58:24 +00:00
|
|
|
{
|
|
|
|
cd $FRONTEND_PATH
|
|
|
|
yarn start
|
|
|
|
}
|
|
|
|
|
2018-03-30 18:28:36 +00:00
|
|
|
release_baseimage()
|
|
|
|
{
|
2018-03-30 23:32:44 +00:00
|
|
|
[ ! -d "$BASEIMAGE_PATH" ] && return || :
|
2018-03-30 18:28:36 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-03-25 14:06:16 +00:00
|
|
|
build_baseimage()
|
2018-03-25 14:03:13 +00:00
|
|
|
{
|
2018-03-30 23:32:44 +00:00
|
|
|
[ ! -d "$BASEIMAGE_PATH" ] && return || :
|
2018-03-25 14:03:13 +00:00
|
|
|
cd $BASEIMAGE_PATH
|
2018-03-30 17:33:48 +00:00
|
|
|
docker build -t "${BASEIMAGE_NAME}:$(baseimage_releasename)" -t "${BASEIMAGE_NAME}:latest" .
|
|
|
|
}
|
|
|
|
|
|
|
|
baseimage_releasename()
|
|
|
|
{
|
2018-03-27 11:37:59 +00:00
|
|
|
VERSION="$(cat VERSION | head -n 1)"
|
|
|
|
DATE="$(date +%Y%m%d)"
|
2018-03-30 17:33:48 +00:00
|
|
|
printf "${VERSION}-${DATE}"
|
2018-03-25 14:03:13 +00:00
|
|
|
}
|
|
|
|
|
2018-03-30 17:38:36 +00:00
|
|
|
build_test()
|
2018-03-23 16:58:24 +00:00
|
|
|
{
|
2018-03-30 17:38:36 +00:00
|
|
|
cd $TEST_PATH
|
2018-03-23 16:58:24 +00:00
|
|
|
docker build -t $IMAGE_NAME -f ${BUILD_CONTEXT}/Dockerfile --build-arg BUILD_CONTEXT=$BUILD_CONTEXT --build-arg NOFRONTEND=1 .
|
2018-03-27 11:45:41 +00:00
|
|
|
}
|
|
|
|
|
2018-03-30 17:38:36 +00:00
|
|
|
run_test()
|
2018-03-27 11:45:41 +00:00
|
|
|
{
|
2018-03-30 17:38:36 +00:00
|
|
|
docker run --rm -p $TEST_PORT:$TEST_PORT -e AVATAO_SECRET=$AVATAO_SECRET $IMAGE_NAME
|
2018-03-23 16:58:24 +00:00
|
|
|
}
|
|
|
|
|
2018-03-30 17:38:36 +00:00
|
|
|
build_and_run_test()
|
2018-03-27 11:45:41 +00:00
|
|
|
{
|
2018-03-30 17:38:36 +00:00
|
|
|
build_test
|
|
|
|
run_test
|
2018-03-27 11:45:41 +00:00
|
|
|
}
|
|
|
|
|
2018-03-27 14:20:17 +00:00
|
|
|
build_and_start_tfw()
|
2018-03-27 14:07:59 +00:00
|
|
|
{
|
|
|
|
trap 'exit' INT TERM
|
|
|
|
trap 'kill 0' EXIT
|
|
|
|
build_baseimage
|
2018-03-30 17:38:36 +00:00
|
|
|
run_frontend & build_and_run_test
|
2018-03-27 14:07:59 +00:00
|
|
|
wait
|
|
|
|
}
|
|
|
|
|
2018-03-27 14:20:17 +00:00
|
|
|
start_tfw()
|
|
|
|
{
|
|
|
|
trap 'exit' INT TERM
|
|
|
|
trap 'kill 0' EXIT
|
2018-03-30 17:38:36 +00:00
|
|
|
run_frontend & run_test
|
2018-03-27 14:20:17 +00:00
|
|
|
wait
|
|
|
|
}
|
|
|
|
|
2018-03-27 14:07:59 +00:00
|
|
|
case $1 in
|
2018-03-27 14:20:17 +00:00
|
|
|
buildtfw)
|
|
|
|
build_baseimage
|
2018-03-27 14:07:59 +00:00
|
|
|
;;
|
|
|
|
build)
|
2018-03-30 17:38:36 +00:00
|
|
|
build_test
|
2018-03-27 14:07:59 +00:00
|
|
|
;;
|
2018-03-27 14:20:17 +00:00
|
|
|
start)
|
|
|
|
start_tfw
|
|
|
|
;;
|
|
|
|
buildstart)
|
|
|
|
build_and_start_tfw
|
2018-03-27 14:07:59 +00:00
|
|
|
;;
|
2018-03-30 18:28:36 +00:00
|
|
|
release)
|
|
|
|
release_baseimage
|
|
|
|
;;
|
2018-03-27 14:07:59 +00:00
|
|
|
*)
|
2018-03-27 14:20:17 +00:00
|
|
|
echo "Usage: tfw.sh [buildtfw|build|start|buildstart]"
|
2018-03-30 18:28:36 +00:00
|
|
|
echo " |--- buildtfw: build TFW baseimage"
|
|
|
|
echo " |--- build: build TFW test"
|
|
|
|
echo " |--- start: start TFW test"
|
2018-03-27 14:23:34 +00:00
|
|
|
echo " |--- buildstart: build all, then start TFW test"
|
2018-03-30 18:28:36 +00:00
|
|
|
echo " |--- release: tag TFW baseimage and push to upstream"
|
2018-03-27 14:07:59 +00:00
|
|
|
;;
|
|
|
|
esac
|