mirror of
https://github.com/avatao-content/test-tutorial-framework
synced 2025-07-03 01:26:23 +00:00
Rename magic starter to tfw.sh
This commit is contained in:
74
hack/tfw.sh
Executable file
74
hack/tfw.sh
Executable file
@ -0,0 +1,74 @@
|
||||
#!/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}"
|
||||
BACKEND_REPO="${BACKEND_REPO:-test-tutorial-framework}"
|
||||
FRONTEND_REPO="${FRONTEND_REPO:-frontend-tutorial-framework}"
|
||||
BASEIMAGE_PATH="${TAO_PATH}/${BASEIMAGE_REPO}"
|
||||
BACKEND_PATH="${TAO_PATH}/${BACKEND_REPO}"
|
||||
FRONTEND_PATH="${TAO_PATH}/${FRONTEND_REPO}"
|
||||
|
||||
BASEIMAGE_NAME="${BASEIMAGE_NAME:-baseimage-tutorial-framework}"
|
||||
IMAGE_NAME="${IMAGE_NAME:-test-tutorial-framework}"
|
||||
BACKEND_PORT="${BACKEND_PORT:-8888}"
|
||||
AVATAO_SECRET="${AVATAO_SECRET:-secret}"
|
||||
BUILD_CONTEXT="${BUILD_CONTEXT:-solvable}"
|
||||
|
||||
run_frontend()
|
||||
{
|
||||
cd $FRONTEND_PATH
|
||||
yarn start
|
||||
}
|
||||
|
||||
build_baseimage()
|
||||
{
|
||||
cd $BASEIMAGE_PATH
|
||||
VERSION="$(cat VERSION | head -n 1)"
|
||||
DATE="$(date +%Y%m%d)"
|
||||
docker build -t "${BASEIMAGE_NAME}:${VERSION}-${DATE}" .
|
||||
}
|
||||
|
||||
build_backend()
|
||||
{
|
||||
cd $BACKEND_PATH
|
||||
docker build -t $IMAGE_NAME -f ${BUILD_CONTEXT}/Dockerfile --build-arg BUILD_CONTEXT=$BUILD_CONTEXT --build-arg NOFRONTEND=1 .
|
||||
}
|
||||
|
||||
run_backend()
|
||||
{
|
||||
docker run --rm -p $BACKEND_PORT:$BACKEND_PORT -e AVATAO_SECRET=$AVATAO_SECRET $IMAGE_NAME
|
||||
}
|
||||
|
||||
build_and_run_backend()
|
||||
{
|
||||
build_backend
|
||||
run_backend
|
||||
}
|
||||
|
||||
start_tfw()
|
||||
{
|
||||
trap 'exit' INT TERM
|
||||
trap 'kill 0' EXIT
|
||||
build_baseimage
|
||||
run_frontend & build_and_run_backend
|
||||
wait
|
||||
}
|
||||
|
||||
case $1 in
|
||||
start)
|
||||
start_tfw
|
||||
;;
|
||||
build)
|
||||
build_backend
|
||||
;;
|
||||
buildtfw)
|
||||
build_baseimage
|
||||
;;
|
||||
*)
|
||||
echo "Usage: tfw.sh [start|build|buildtfw]"
|
||||
;;
|
||||
esac
|
Reference in New Issue
Block a user