From 08fe675865a41654a0a872ca355db3aad6cd8a8c Mon Sep 17 00:00:00 2001 From: John Cowen Date: Mon, 30 Jul 2018 17:59:43 +0100 Subject: [PATCH] UI: Add conditional enterprise logo (#4432) Adds additional 'enterprise' text underneath the 'startup' logo if the ui is built with a CONSUL_BINARY_TYPE environment variable that doesn't equal `oss`. --- build-support/functions/10-util.sh | 27 ++++++++++++++++++++++ build-support/functions/20-build.sh | 33 ++++++++++++++++++++++----- build-support/functions/40-publish.sh | 17 ++++++++++---- build-support/scripts/build-docker.sh | 2 +- ui-v2/config/environment.js | 5 ++-- ui-v2/lib/startup/index.js | 10 ++++---- 6 files changed, 75 insertions(+), 19 deletions(-) diff --git a/build-support/functions/10-util.sh b/build-support/functions/10-util.sh index 1d0dfd1ea..9dee97eb8 100644 --- a/build-support/functions/10-util.sh +++ b/build-support/functions/10-util.sh @@ -939,3 +939,30 @@ function shasum_directory { echo "$ui_version" return 0 } + function ui_logo_type { + # Arguments: + # $1 - path to index.html + # + # Returns: + # 0 - success + # * -failure + # + # Notes: echoes the 'logo type' to stdout upon success + # the 'logo' can be one of 'enterprise' or 'oss' + # and doesn't necessarily correspond to the binary type of consul + # the logo is 'enterprise' if the binary type is anything but 'oss' + if ! test -f "$1" + then + err "ERROR: No such file: '$1'" + return 1 + fi + grep -q "data-enterprise-logo" < "$1" + + if test $? -eq 0 + then + echo "enterprise" + else + echo "oss" + fi + return 0 + } diff --git a/build-support/functions/20-build.sh b/build-support/functions/20-build.sh index 54cef54d7..a68d2bda7 100644 --- a/build-support/functions/20-build.sh +++ b/build-support/functions/20-build.sh @@ -63,12 +63,17 @@ function build_ui { then commit_hash=$(git rev-parse --short HEAD) fi + local logo_type="${CONSUL_BINARY_TYPE}" + if test "$logo_type" != "oss" + then + logo_type="enterprise" + fi # make sure we run within the ui dir pushd ${ui_dir} > /dev/null 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 container_id=$(docker create -it -e "CONSUL_GIT_SHA=${commit_hash}" -e "CONSUL_VERSION=${version}" -e "CONSUL_BINARY_TYPE=${CONSUL_BINARY_TYPE}" ${image_name}) local ret=$? if test $ret -eq 0 then @@ -82,7 +87,8 @@ function build_ui { ret=$? docker rm ${container_id} > /dev/null fi - + + # Check the version is baked in correctly if test ${ret} -eq 0 then local ui_vers=$(ui_version "${1}/ui-v2/dist/index.html") @@ -90,12 +96,27 @@ function build_ui { 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 + + # Check the logo is baked in correctly + if test ${ret} -eq 0 + then + local ui_logo_type=$(ui_logo_type "${1}/ui-v2/dist/index.html") + if test "${logo_type}" != "${ui_logo_type}" + then + err "ERROR: UI logo type mismatch. Expecting: '${logo_type}' found '${ui_logo_type}'" + ret=1 + fi + fi + + # Copy UI over ready to be packaged into the binary + 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 + fi popd > /dev/null return $ret diff --git a/build-support/functions/40-publish.sh b/build-support/functions/40-publish.sh index c2fd062ad..e6d42c677 100644 --- a/build-support/functions/40-publish.sh +++ b/build-support/functions/40-publish.sh @@ -266,8 +266,15 @@ function confirm_consul_info { err "ERROR: Failed to determine the ui version from the index.html file" return 1 fi - status "UI Version: ${ui_vers}" + local ui_logo_type=$(ui_logo_type "${tfile}") + if test $? -ne 0 + then + err "ERROR: Failed to determine the ui logo/binary type from the index.html file" + return 1 + fi + status "UI Logo: ${ui_logo_type}" + echo "" local answer="" @@ -275,16 +282,16 @@ function confirm_consul_info { do case "${answer}" in [yY]* ) - status "Consul UI Version Accepted" + status "Consul UI/Logo Version Accepted" break ;; [nN]* ) - err "Consul UI Version Rejected" + err "Consul UI/Logo Version Rejected" return 1 break ;; * ) - read -p "Is this Consul UI Version correct? [y/n]: " answer + read -p "Is this Consul UI/Logo Version correct? [y/n]: " answer ;; esac done @@ -413,4 +420,4 @@ function publish_release { fi return 0 -} \ No newline at end of file +} diff --git a/build-support/scripts/build-docker.sh b/build-support/scripts/build-docker.sh index 9a8453f29..7fef57826 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 "==> UI Built with Version: $(ui_version ${sdir}/pkg/web_ui/v2/index.html)" + status "==> UI Built with Version: $(ui_version ${sdir}/pkg/web_ui/v2/index.html), Logo: $(ui_logo_type ${sdir}/pkg/web_ui/v2/index.html)" ;; ui-legacy ) if is_set "${refresh}" diff --git a/ui-v2/config/environment.js b/ui-v2/config/environment.js index 6ee649a70..5ed8a33f1 100644 --- a/ui-v2/config/environment.js +++ b/ui-v2/config/environment.js @@ -53,13 +53,12 @@ module.exports = function(environment) { .trim() .split('"')[1]; })(), - CONSUL_BINARY_TYPE: function() { + CONSUL_BINARY_TYPE: (function() { if (process.env.CONSUL_BINARY_TYPE) { return process.env.CONSUL_BINARY_TYPE; } - return 'oss'; - }, + })(), CONSUL_DOCUMENTATION_URL: 'https://www.consul.io/docs', CONSUL_COPYRIGHT_URL: 'https://www.hashicorp.com', CONSUL_COPYRIGHT_YEAR: '2018', diff --git a/ui-v2/lib/startup/index.js b/ui-v2/lib/startup/index.js index 64280e1a5..bb03b642d 100644 --- a/ui-v2/lib/startup/index.js +++ b/ui-v2/lib/startup/index.js @@ -3,13 +3,15 @@ module.exports = { name: 'startup', - isDevelopingAddon: function() { - return true; - }, contentFor: function(type, config) { switch (type) { case 'body': - return ``; + const enterprise = config.CONSUL_BINARY_TYPE !== 'oss' && config.CONSUL_BINARY_TYPE !== ''; + return `${ + enterprise + ? `` + : '' + }`; case 'root-class': return 'ember-loading'; }