From 560c727bcfa8d2576db062be2c8a5e340e53c22a Mon Sep 17 00:00:00 2001 From: Sam Salisbury Date: Thu, 8 Oct 2020 18:51:53 +0100 Subject: [PATCH] make update-ui-version (#578) * make update-ui-version * make update-ui-version: default branch main * make update-ui-version: actually checkout commit --- Makefile | 31 ++++++++++++++++++++++++++++--- internal/ui/VERSION | 4 +++- scripts/uiclone.sh | 29 +++++++++++++++++++++++++++++ scripts/uigen.sh | 37 +++++++++++-------------------------- scripts/uiupdate.sh | 23 +++++++++++++++++++++++ 5 files changed, 94 insertions(+), 30 deletions(-) create mode 100755 scripts/uiclone.sh create mode 100755 scripts/uiupdate.sh diff --git a/Makefile b/Makefile index 44b8328415..1f84385b68 100644 --- a/Makefile +++ b/Makefile @@ -35,13 +35,38 @@ bin: build-ui fmt: goimports -w $$(find . -name '*.go' | grep -v pb.go | grep -v pb.gw.go) +# Set env for all UI targets. +UI_TARGETS := update-ui-version build-ui build-ui-ifne +# Note the extra .tmp path segment in UI_CLONE_DIR is significant and required. +$(UI_TARGETS): export UI_CLONE_DIR := internal/ui/.tmp/boundary-ui +$(UI_TARGETS): export UI_VERSION_FILE := internal/ui/VERSION +$(UI_TARGETS): export UI_ASSETS_FILE := internal/ui/assets.go +$(UI_TARGETS): export UI_DEFAULT_BRANCH := main +$(UI_TARGETS): export UI_CURRENT_COMMIT := $(shell head -n1 < "$(UI_VERSION_FILE)" | cut -d' ' -f1) +$(UI_TARGETS): export UI_COMMITISH ?= + +update-ui-version: + @if [ -z "$(UI_COMMITISH)" ]; then \ + echo "==> Setting UI version to latest commit on branch '$(UI_DEFAULT_BRANCH)'"; \ + export UI_COMMITISH="$(UI_DEFAULT_BRANCH)"; \ + else \ + echo "==> Setting to latest commit matching '$(UI_COMMITISH)'"; \ + fi; \ + ./scripts/uiclone.sh && ./scripts/uiupdate.sh + build-ui: - @scripts/uigen.sh + @if [ -z "$(UI_COMMITISH)" ]; then \ + echo "==> Building default UI version from $(UI_VERSION_FILE): $(UI_CURRENT_COMMIT)"; \ + export UI_COMMITISH="$(UI_CURRENT_COMMIT)"; \ + else \ + echo "==> Building custom UI version $(UI_COMMITISH)"; \ + fi; \ + ./scripts/uiclone.sh && ./scripts/uigen.sh build-ui-ifne: ifeq (,$(wildcard internal/ui/assets.go)) @echo "==> No UI assets found, building..." - @scripts/uigen.sh + @$(MAKE) build-ui else @echo "==> UI assets found, use build-ui target to update" endif @@ -119,7 +144,7 @@ test-ci: install-go install-go: ./ci/goinstall.sh -.PHONY: api tools gen migrations proto website ci-config ci-verify +.PHONY: api tools gen migrations proto website ci-config ci-verify set-ui-version .NOTPARALLEL: diff --git a/internal/ui/VERSION b/internal/ui/VERSION index 1a83fa171a..fd05a491d5 100644 --- a/internal/ui/VERSION +++ b/internal/ui/VERSION @@ -1,2 +1,4 @@ 31f7b575a981f92629dfe1ba8006054ae8b22eff Merge pull request #311 from hashicorp/release -# Above commit is used for production builds. +# This file determines the version of the UI to embed in the boundary binary. +# Update this file by running 'make update-ui-version' from the root of this repo. +# Set UI_COMMITISH when running the above target to update to a specific version. diff --git a/scripts/uiclone.sh b/scripts/uiclone.sh new file mode 100755 index 0000000000..63b878c3a3 --- /dev/null +++ b/scripts/uiclone.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +set -e + +if [ -z "$UI_COMMITISH" ]; then + echo "Must set UI_COMMITISH"; exit 1 +fi + +if [ -z "$UI_CLONE_DIR" ]; then + echo "Must set UI_CLONE_DIR"; exit 1 +fi + +if [ -z "$UI_VERSION_FILE" ]; then + echo "Must set UI_CLONE_DIR"; exit 1 +fi + +tempdir="$(dirname "${UI_CLONE_DIR}")" + +mkdir -p "${tempdir}" +echo "*" > "${tempdir}/.gitignore" + +if ! [ -d "${UI_CLONE_DIR}/.git" ]; then + git clone https://github.com/hashicorp/boundary-ui "${UI_CLONE_DIR}" +fi + +cd "${UI_CLONE_DIR}" +git reset --hard +git fetch origin "${UI_COMMITISH}" +git checkout "${UI_COMMITISH}" diff --git a/scripts/uigen.sh b/scripts/uigen.sh index cef6046b57..1c98471669 100755 --- a/scripts/uigen.sh +++ b/scripts/uigen.sh @@ -2,41 +2,26 @@ set -e -ui_commitish="${UI_COMMITISH:-develop}" - -targetdir="internal/ui" -shafile="${targetdir}/VERSION" -shafileabs="$(pwd)/${shafile}" -tempdir="${targetdir}/source" -uirepodir="${tempdir}/boundary-ui" -mkdir -p "${tempdir}" -echo "*" > "${tempdir}/.gitignore" +if [ -z "$UI_CLONE_DIR" ]; then + echo "Must set UI_CLONE_DIR"; exit 1 +fi -if ! [ -d "${uirepodir}/.git" ]; then - git clone https://github.com/hashicorp/boundary-ui "${uirepodir}" +if [ -z "$UI_ASSETS_FILE" ]; then + echo "Must set UI_ASSETS_FILE"; exit 1 fi ( - cd "${uirepodir}" - git reset --hard - git fetch origin "${ui_commitish}" - git checkout "${ui_commitish}" + cd "$UI_CLONE_DIR" if ! docker-compose -f docker-compose-embedding.yml run build; then echo "==> UI build failed." exit 1 fi - git log -n1 --pretty=oneline > "${shafileabs}" - echo "# Above commit is used for production builds." >> "${shafileabs}" ) -uidir="${uirepodir}/ui/core/dist" - -target="${targetdir}/assets.go" - -go-bindata -fs -o "${target}.tmp" -pkg ui -prefix "${uidir}" "${uidir}" "${uidir}/assets" +uidir="${UI_CLONE_DIR}/ui/core/dist" -printf "// +build ui\n" > "${target}" -cat "${target}.tmp" >> "${target}" -rm "${target}.tmp" +go-bindata -fs -o "$UI_ASSETS_FILE.tmp" -pkg ui -prefix "${uidir}" "${uidir}" "${uidir}/assets" -rm -rf "$tempdir" +printf "// +build ui\n" > "$UI_ASSETS_FILE" +cat "$UI_ASSETS_FILE.tmp" >> "$UI_ASSETS_FILE" +rm "$UI_ASSETS_FILE.tmp" diff --git a/scripts/uiupdate.sh b/scripts/uiupdate.sh new file mode 100755 index 0000000000..3e9bd9ae7d --- /dev/null +++ b/scripts/uiupdate.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +set -e + +if [ -z "$UI_VERSION_FILE" ]; then + echo "Must set UI_VERSION_FILE"; exit 1 +fi +if [ -z "$UI_CLONE_DIR" ]; then + echo "Must set UI_CLONE_DIR"; exit 1 +fi + +shafileabs="$(pwd)/${UI_VERSION_FILE}" +cd "${UI_CLONE_DIR}" +V="$(git log -n1 --pretty=oneline)" +echo "==> Setting UI version to: $V" + +# Write the version file. +{ + echo "$V" + echo "# This file determines the version of the UI to embed in the boundary binary." + echo "# Update this file by running 'make update-ui-version' from the root of this repo." + echo "# Set UI_COMMITISH when running the above target to update to a specific version." +} > "${shafileabs}"