From f92678629240d3fe58dd193a0d0a87570287beba Mon Sep 17 00:00:00 2001 From: Matt Keeler Date: Tue, 26 Jun 2018 11:21:37 -0400 Subject: [PATCH] Create a new ui_version function to pull it out of an index.html file Also verify the ui version after it was built that it matches the env var we set in the build container. --- build-support/functions/10-util.sh | 20 ++++++++++++++++++++ build-support/functions/20-build.sh | 16 ++++++++++++---- build-support/scripts/build-docker.sh | 2 +- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/build-support/functions/10-util.sh b/build-support/functions/10-util.sh index 1de0b949fb..1d0dfd1eae 100644 --- a/build-support/functions/10-util.sh +++ b/build-support/functions/10-util.sh @@ -919,3 +919,23 @@ function shasum_directory { return $ret } + + function ui_version { + # Arguments: + # $1 - path to index.html + # + # Returns: + # 0 - success + # * -failure + # + # Notes: echoes the version to stdout upon success + if ! test -f "$1" + then + err "ERROR: No such file: '$1'" + return 1 + fi + + local ui_version=$(sed -n ${SED_EXT} -e 's/.*CONSUL_VERSION%22%3A%22([^%]*)%22%2C%22.*/\1/p' < "$1") || return 1 + echo "$ui_version" + return 0 + } diff --git a/build-support/functions/20-build.sh b/build-support/functions/20-build.sh index 5c34cd7c96..a2134c410f 100644 --- a/build-support/functions/20-build.sh +++ b/build-support/functions/20-build.sh @@ -67,7 +67,7 @@ function build_ui { # make sure we run within the ui dir pushd ${ui_dir} > /dev/null - status "Creating the UI Build Container with image: ${image_name} and embedding as version ${version}" + status "Creating the UI Build Container with image: ${image_name} and version '${version}'" local container_id=$(docker create -it -e "CONSUL_GIT_SHA=${commit_hash}" -e "CONSUL_VERSION=${version}" ${image_name}) local ret=$? if test $ret -eq 0 @@ -85,10 +85,18 @@ function build_ui { if test ${ret} -eq 0 then - rm -rf ${1}/pkg/web_ui/v2 - mkdir -p ${1}/pkg/web_ui - cp -r ${1}/ui-v2/dist ${1}/pkg/web_ui/v2 + local ui_vers=$(ui_version "${1}/ui-v2/dist/index.html") + if test "${version}" != "${ui_vers}" + then + err "ERROR: UI version mismatch. Expecting: '${version}' found '${ui_vers}'" + ret=1 + else + rm -rf ${1}/pkg/web_ui/v2 + mkdir -p ${1}/pkg/web_ui + cp -r ${1}/ui-v2/dist ${1}/pkg/web_ui/v2 + fi fi + popd > /dev/null return $ret } diff --git a/build-support/scripts/build-docker.sh b/build-support/scripts/build-docker.sh index e80c72bbb4..9a8453f29c 100755 --- a/build-support/scripts/build-docker.sh +++ b/build-support/scripts/build-docker.sh @@ -128,7 +128,7 @@ function main { fi status_stage "==> Building UI" build_ui "${sdir}" "${image}" || return 1 - status_stage "==> UI V2 Built with embedded version: $(cat ${sdir}/pkg/web_ui/v2/index.html | sed -n -e 's/.*CONSUL_VERSION%22%3A%22//p' | sed -n -e 's/%22%2C%22.*//p')" + status "==> UI Built with Version: $(ui_version ${sdir}/pkg/web_ui/v2/index.html)" ;; ui-legacy ) if is_set "${refresh}"