From 01657e80487ec25e8f9d51944ffb5ce82e4dfbf7 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 16 Sep 2021 23:51:09 -0600 Subject: [PATCH] Edit ambassador.version when promoting an image Signed-off-by: Luke Shumaker --- .editorconfig | 4 +++ build-aux/tools.mk | 1 + builder/builder.mk | 5 ++-- tools/src/docker-promote.sh | 49 +++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 tools/src/docker-promote.sh diff --git a/.editorconfig b/.editorconfig index 008325ad214..05622a1c9d7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -54,6 +54,10 @@ indent_style = tab [{*.sh,cluster-claim,cluster-unclaim}] indent_style = space indent_size = 4 +[docker-promote.sh] +indent_style = tab +indent_size = 8 +tab_width = 8 [*.el] indent_style = space diff --git a/build-aux/tools.mk b/build-aux/tools.mk index 42b3a94fa13..40e7328a2df 100644 --- a/build-aux/tools.mk +++ b/build-aux/tools.mk @@ -23,6 +23,7 @@ clobber-tools: # ============= # tools/copy-ifchanged = $(tools.bindir)/copy-ifchanged +tools/docker-promote = $(tools.bindir)/docker-promote tools/move-ifchanged = $(tools.bindir)/move-ifchanged tools/tap-driver = $(tools.bindir)/tap-driver tools/write-dockertagfile = $(tools.bindir)/write-dockertagfile diff --git a/builder/builder.mk b/builder/builder.mk index ed7010e392e..7fc5705a42d 100644 --- a/builder/builder.mk +++ b/builder/builder.mk @@ -717,7 +717,7 @@ RELEASE_VERSION=$$($(BUILDER) release-version) BUILD_VERSION=$$($(BUILDER) version) IS_DIRTY=$$($(BUILDER) is-dirty) -release/promote-oss/.main: +release/promote-oss/.main: $(tools/docker-promote) @[[ "$(RELEASE_VERSION)" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.*)?$$ ]] || (echo "MUST SET RELEASE_VERSION"; exit 1) @[[ -n "$(PROMOTE_FROM_VERSION)" ]] || (echo "MUST SET PROMOTE_FROM_VERSION"; exit 1) @[[ '$(PROMOTE_TO_VERSION)' =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.*)?$$ ]] || (echo "MUST SET PROMOTE_TO_VERSION" ; exit 1) @@ -736,8 +736,7 @@ release/promote-oss/.main: exit 1; \ fi ; \ printf ' $(CYN)$${pullregistry}/$(REPO):$(PROMOTE_FROM_VERSION)$(END)\n' ; \ - docker pull $${pullregistry}/$(REPO):$(PROMOTE_FROM_VERSION) && \ - docker tag $${pullregistry}/$(REPO):$(PROMOTE_FROM_VERSION) $(RELEASE_REGISTRY)/$(REPO):$(PROMOTE_TO_VERSION) && \ + $(tools/docker-promote) $${pullregistry}/$(REPO):$(PROMOTE_FROM_VERSION) $(RELEASE_REGISTRY)/$(REPO):$(PROMOTE_TO_VERSION) && \ docker push $(RELEASE_REGISTRY)/$(REPO):$(PROMOTE_TO_VERSION) ;\ } diff --git a/tools/src/docker-promote.sh b/tools/src/docker-promote.sh new file mode 100644 index 00000000000..74025119d23 --- /dev/null +++ b/tools/src/docker-promote.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +set -euE + +usage() { + echo "Usage: ${0##*/} FROM_IMAGE TO_REPO:TO_VERSION" +} + +errUsage() { + printf '%s: error: %s' "$*" + usage >&2 + exit 2 +} + +main() { + for arg in "$@"; do + if [[ $arg == '--help' ]]; then + usage + exit 0 + fi + done + if [[ $# != 2 ]]; then + errUsage "expected exactly 2 arguments, got $#" + fi + from=$1 + to=$2 + if [[ $to != *:* ]]; then + errUsage "does not look like a REPO:VERSION pair: ${to}" + fi + toVersion=${to##*:} + + toVersion_base=${toVersion%%-*} + toVersion_extra=${toVersion#"$toVersion_base"} + tmpdir=$(mktemp -d -t docker-promote.XXXXXXXXXX) + trap 'rm -rf "$tmpdir"' EXIT + cat >"$tmpdir/Dockerfile" <<-EOF + FROM ${from} + RUN find / -name ambassador.version -exec sed -i \\ + -e 's/^BASE_VERSION=.*/BASE_VERSION="${toVersion_base}"/' \\ + -e 's/^EXTRA_VERSION=.*/EXTRA_VERSION="${toVersion_extra}"/' \\ + -e 's/^RELEASE_VERSION=.*/RELEASE_VERSION="${toVersion}"/' \\ + -e 's/^BUILD_VERSION=.*/BUILD_VERSION="${toVersion}"/' \\ + -- {} + + EOF + grep -H ^ "$tmpdir/Dockerfile" + docker build -t "$to" "$tmpdir" +} + +main "$@"