Improve tfw.sh (refactor & new baseimage compliance)

This commit is contained in:
Kristóf Tóth 2019-10-31 15:17:27 +01:00
parent 6f7c197b12
commit 320cfe9952
3 changed files with 49 additions and 19 deletions

View File

@ -8,23 +8,32 @@ libhack_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
source "${libhack_dir}/common.sh"
baseimage::assert_exists() {
if [[ ! -d "${BASEIMAGE_PATH}" ]]; then
exit 0
fi
}
baseimage::build_if_exists() {
[[ ! -d "${BASEIMAGE_PATH}" ]] && return ||:
baseimage::build
}
baseimage::build() {
baseimage::assert_exists
pushd "${BASEIMAGE_PATH}"
local tag
tag="${BASEIMAGE_NAME}:$(releasename)"
docker build -t "${tag}" .
docker build --build-arg FRONTEND_VERSION="${frontend_version}" \
-t "${tag}" \
.
docker tag "${tag}" "${BASEIMAGE_NAME}:latest"
popd
}
baseimage::assert_exists() {
if [[ ! -d "${BASEIMAGE_PATH}" ]]; then
printf "Cannot find baseimage at ${BASEIMAGE_PATH}!\n"
exit 1
fi
}
baseimage::release() {
baseimage::assert_exists
pushd "${BASEIMAGE_PATH}"
local tag
tag="$(releasename)"

View File

@ -7,19 +7,22 @@ libhack_dir="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")"
source "${libhack_dir}/common.sh"
frontend::assert_exists() {
if [[ ! -d "${FRONTEND_PATH}" ]]; then
exit 0
fi
}
frontend::build() {
frontend::assert_exists
pushd "${FRONTEND_PATH}"
docker build -t "${FRONTEND_IMAGE_NAME}:$(releasename)" .
popd
}
frontend::assert_exists() {
if [[ ! -d "${FRONTEND_PATH}" ]]; then
printf "Cannot find frontend at ${FRONTEND_PATH}!\n"
exit 1
fi
}
frontend::release() {
frontend::assert_exists
pushd "${FRONTEND_PATH}"
local tag
tag="$(releasename)"
@ -32,3 +35,10 @@ frontend::release() {
fi
popd
}
frontend::latest_tag() {
frontend::assert_exists
pushd "${FRONTEND_PATH}"
git describe --tags
popd
}

View File

@ -21,9 +21,21 @@ source "${SCRIPT_DIR}/libhack/challenge.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
start)
baseimage::build_if_exists
try_build_baseimage
challenge::build
challenge::run ${@:2}
;;
@ -31,22 +43,21 @@ case ${1:-} in
challenge:run ${@:2}
;;
build-baseimage)
baseimage::build_if_exists
build_baseimage
;;
build)
baseimage::build_if_exists
try_build_baseimage
challenge::build_no_cache
;;
build-frontend)
frontend::assert_exists
frontend::build
;;
release-baseimage)
baseimage::assert_exists
build_baseimage
baseimage::release
;;
release-frontend)
frontend::assert_exists
frontend::build
frontend::release
;;
*)