Skip to content

Commit

Permalink
UI: Add conditional enterprise logo (hashicorp#4432)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
johncowen authored Jul 30, 2018
1 parent fde4146 commit 80a307c
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 19 deletions.
27 changes: 27 additions & 0 deletions build-support/functions/10-util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
33 changes: 27 additions & 6 deletions build-support/functions/20-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -82,20 +87,36 @@ 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")
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

# 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
Expand Down
17 changes: 12 additions & 5 deletions build-support/functions/40-publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -266,25 +266,32 @@ 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=""

while true
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
Expand Down Expand Up @@ -413,4 +420,4 @@ function publish_release {
fi

return 0
}
}
2 changes: 1 addition & 1 deletion build-support/scripts/build-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
5 changes: 2 additions & 3 deletions ui-v2/config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
10 changes: 6 additions & 4 deletions ui-v2/lib/startup/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 80a307c

Please sign in to comment.