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.
This commit is contained in:
Matt Keeler 2018-06-26 11:21:37 -04:00
parent d6bc5bc2db
commit f926786292
3 changed files with 33 additions and 5 deletions

View File

@ -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
}

View File

@ -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
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
}

View File

@ -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}"