mirror of
https://github.com/avatao-content/test-tutorial-framework
synced 2024-12-05 02:01:33 +00:00
Improve tfw.sh (refactor & new baseimage compliance)
This commit is contained in:
parent
6f7c197b12
commit
320cfe9952
@ -8,23 +8,32 @@ libhack_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
|
|||||||
source "${libhack_dir}/common.sh"
|
source "${libhack_dir}/common.sh"
|
||||||
|
|
||||||
|
|
||||||
baseimage::assert_exists() {
|
|
||||||
if [[ ! -d "${BASEIMAGE_PATH}" ]]; then
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
baseimage::build_if_exists() {
|
baseimage::build_if_exists() {
|
||||||
[[ ! -d "${BASEIMAGE_PATH}" ]] && return ||:
|
[[ ! -d "${BASEIMAGE_PATH}" ]] && return ||:
|
||||||
|
baseimage::build
|
||||||
|
}
|
||||||
|
|
||||||
|
baseimage::build() {
|
||||||
|
baseimage::assert_exists
|
||||||
pushd "${BASEIMAGE_PATH}"
|
pushd "${BASEIMAGE_PATH}"
|
||||||
local tag
|
local tag
|
||||||
tag="${BASEIMAGE_NAME}:$(releasename)"
|
tag="${BASEIMAGE_NAME}:$(releasename)"
|
||||||
docker build -t "${tag}" .
|
docker build --build-arg FRONTEND_VERSION="${frontend_version}" \
|
||||||
|
-t "${tag}" \
|
||||||
|
.
|
||||||
docker tag "${tag}" "${BASEIMAGE_NAME}:latest"
|
docker tag "${tag}" "${BASEIMAGE_NAME}:latest"
|
||||||
popd
|
popd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
baseimage::assert_exists() {
|
||||||
|
if [[ ! -d "${BASEIMAGE_PATH}" ]]; then
|
||||||
|
printf "Cannot find baseimage at ${BASEIMAGE_PATH}!\n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
baseimage::release() {
|
baseimage::release() {
|
||||||
|
baseimage::assert_exists
|
||||||
pushd "${BASEIMAGE_PATH}"
|
pushd "${BASEIMAGE_PATH}"
|
||||||
local tag
|
local tag
|
||||||
tag="$(releasename)"
|
tag="$(releasename)"
|
||||||
|
@ -7,19 +7,22 @@ libhack_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
|
|||||||
source "${libhack_dir}/common.sh"
|
source "${libhack_dir}/common.sh"
|
||||||
|
|
||||||
|
|
||||||
frontend::assert_exists() {
|
|
||||||
if [[ ! -d "${FRONTEND_PATH}" ]]; then
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
frontend::build() {
|
frontend::build() {
|
||||||
|
frontend::assert_exists
|
||||||
pushd "${FRONTEND_PATH}"
|
pushd "${FRONTEND_PATH}"
|
||||||
docker build -t "${FRONTEND_IMAGE_NAME}:$(releasename)" .
|
docker build -t "${FRONTEND_IMAGE_NAME}:$(releasename)" .
|
||||||
popd
|
popd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
frontend::assert_exists() {
|
||||||
|
if [[ ! -d "${FRONTEND_PATH}" ]]; then
|
||||||
|
printf "Cannot find frontend at ${FRONTEND_PATH}!\n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
frontend::release() {
|
frontend::release() {
|
||||||
|
frontend::assert_exists
|
||||||
pushd "${FRONTEND_PATH}"
|
pushd "${FRONTEND_PATH}"
|
||||||
local tag
|
local tag
|
||||||
tag="$(releasename)"
|
tag="$(releasename)"
|
||||||
@ -32,3 +35,10 @@ frontend::release() {
|
|||||||
fi
|
fi
|
||||||
popd
|
popd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
frontend::latest_tag() {
|
||||||
|
frontend::assert_exists
|
||||||
|
pushd "${FRONTEND_PATH}"
|
||||||
|
git describe --tags
|
||||||
|
popd
|
||||||
|
}
|
||||||
|
23
hack/tfw.sh
23
hack/tfw.sh
@ -21,9 +21,21 @@ source "${SCRIPT_DIR}/libhack/challenge.sh"
|
|||||||
source "${SCRIPT_DIR}/libhack/frontend.sh"
|
source "${SCRIPT_DIR}/libhack/frontend.sh"
|
||||||
|
|
||||||
|
|
||||||
|
build_baseimage() {
|
||||||
|
frontend_version="$(frontend::latest_tag)"
|
||||||
|
baseimage::build
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
try_build_baseimage() {
|
||||||
|
frontend_version="$(frontend::latest_tag)"
|
||||||
|
baseimage::build_if_exists
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
case ${1:-} in
|
case ${1:-} in
|
||||||
start)
|
start)
|
||||||
baseimage::build_if_exists
|
try_build_baseimage
|
||||||
challenge::build
|
challenge::build
|
||||||
challenge::run ${@:2}
|
challenge::run ${@:2}
|
||||||
;;
|
;;
|
||||||
@ -31,22 +43,21 @@ case ${1:-} in
|
|||||||
challenge:run ${@:2}
|
challenge:run ${@:2}
|
||||||
;;
|
;;
|
||||||
build-baseimage)
|
build-baseimage)
|
||||||
baseimage::build_if_exists
|
build_baseimage
|
||||||
;;
|
;;
|
||||||
build)
|
build)
|
||||||
baseimage::build_if_exists
|
try_build_baseimage
|
||||||
challenge::build_no_cache
|
challenge::build_no_cache
|
||||||
;;
|
;;
|
||||||
build-frontend)
|
build-frontend)
|
||||||
frontend::assert_exists
|
|
||||||
frontend::build
|
frontend::build
|
||||||
;;
|
;;
|
||||||
release-baseimage)
|
release-baseimage)
|
||||||
baseimage::assert_exists
|
build_baseimage
|
||||||
baseimage::release
|
baseimage::release
|
||||||
;;
|
;;
|
||||||
release-frontend)
|
release-frontend)
|
||||||
frontend::assert_exists
|
frontend::build
|
||||||
frontend::release
|
frontend::release
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
Loading…
Reference in New Issue
Block a user