From 320cfe9952a38a349194abe47490e1ccae40a42f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Thu, 31 Oct 2019 15:17:27 +0100 Subject: [PATCH] Improve tfw.sh (refactor & new baseimage compliance) --- hack/libhack/baseimage.sh | 23 ++++++++++++++++------- hack/libhack/frontend.sh | 22 ++++++++++++++++------ hack/tfw.sh | 23 +++++++++++++++++------ 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/hack/libhack/baseimage.sh b/hack/libhack/baseimage.sh index b8a50d6..742d665 100644 --- a/hack/libhack/baseimage.sh +++ b/hack/libhack/baseimage.sh @@ -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)" diff --git a/hack/libhack/frontend.sh b/hack/libhack/frontend.sh index 43ab2b8..1e578e3 100644 --- a/hack/libhack/frontend.sh +++ b/hack/libhack/frontend.sh @@ -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 +} diff --git a/hack/tfw.sh b/hack/tfw.sh index 3ade1f1..1368847 100755 --- a/hack/tfw.sh +++ b/hack/tfw.sh @@ -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 ;; *)