Skip to content

Commit

Permalink
Edit ambassador.version when promoting an image
Browse files Browse the repository at this point in the history
Signed-off-by: Luke Shumaker <[email protected]>
  • Loading branch information
LukeShu committed Sep 17, 2021
1 parent 02c5ddd commit 3de1257
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions build-aux/tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions builder/builder.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) ;\
}

Expand Down
49 changes: 49 additions & 0 deletions tools/src/docker-promote.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"

0 comments on commit 3de1257

Please sign in to comment.