|
| 1 | +# Points :latest at an already-published version tag. |
| 2 | +# |
| 3 | +# This is a registry-side manifest copy rather than a rebuild, so :latest resolves to the exact |
| 4 | +# digest that was verified. |
| 5 | +# |
| 6 | +# Run manually after the target tag has passed the checks in RELEASING.md. |
| 7 | + |
| 8 | +name: Promote Docker Image to :latest |
| 9 | + |
| 10 | +on: |
| 11 | + workflow_dispatch: |
| 12 | + inputs: |
| 13 | + version: |
| 14 | + description: 'Published version tag to promote (e.g. v1.0.0). Prereleases are rejected.' |
| 15 | + required: true |
| 16 | + type: string |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: read |
| 20 | + |
| 21 | +# Shared with docker-release.yml so a promotion cannot interleave with a build. |
| 22 | +concurrency: |
| 23 | + group: docker-release |
| 24 | + cancel-in-progress: false |
| 25 | + |
| 26 | +env: |
| 27 | + IMAGE_NAME: keeper/gchat-app |
| 28 | + |
| 29 | +jobs: |
| 30 | + promote: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + timeout-minutes: 15 |
| 33 | + environment: release |
| 34 | + permissions: |
| 35 | + contents: read |
| 36 | + steps: |
| 37 | + - name: Checkout repository |
| 38 | + uses: actions/checkout@v6 |
| 39 | + with: |
| 40 | + fetch-depth: 0 |
| 41 | + |
| 42 | + - name: Validate promotion target |
| 43 | + env: |
| 44 | + VERSION: ${{ inputs.version }} |
| 45 | + run: | |
| 46 | + set -euo pipefail |
| 47 | +
|
| 48 | + if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then |
| 49 | + echo "::error::'$VERSION' is not a GA tag. :latest must not point at a prerelease." |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | +
|
| 53 | + if ! git rev-parse -q --verify "refs/tags/$VERSION" >/dev/null; then |
| 54 | + echo "::error::git tag $VERSION does not exist in this repository" |
| 55 | + exit 1 |
| 56 | + fi |
| 57 | +
|
| 58 | + HIGHEST="$(git tag -l 'v[0-9]*.[0-9]*.[0-9]*' | grep -v -- '-' | sort -V | tail -1)" |
| 59 | + if [ "$VERSION" != "$HIGHEST" ]; then |
| 60 | + echo "::error::$VERSION is not the highest GA tag ($HIGHEST); refusing to move :latest backwards" |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | + echo "OK: $VERSION is the highest GA tag" |
| 64 | +
|
| 65 | + - name: Set up Docker Buildx |
| 66 | + uses: docker/setup-buildx-action@v3 |
| 67 | + |
| 68 | + - name: Log in to DockerHub |
| 69 | + uses: docker/login-action@v4 |
| 70 | + with: |
| 71 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 72 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 73 | + |
| 74 | + - name: Verify the source tag is a complete multi-arch image |
| 75 | + env: |
| 76 | + VERSION: ${{ inputs.version }} |
| 77 | + run: | |
| 78 | + set -euo pipefail |
| 79 | + SRC="${IMAGE_NAME}:${VERSION}" |
| 80 | + PLATFORMS="$(docker buildx imagetools inspect "$SRC" --raw \ |
| 81 | + | jq -r '.manifests[] | select(.platform.architecture != "unknown") |
| 82 | + | "\(.platform.os)/\(.platform.architecture)"' | sort -u)" |
| 83 | + echo "Source platforms:" |
| 84 | + printf '%s\n' "$PLATFORMS" |
| 85 | + for required in linux/amd64 linux/arm64; do |
| 86 | + if ! grep -qx "$required" <<<"$PLATFORMS"; then |
| 87 | + echo "::error::$SRC is missing $required; refusing to promote a partial image" |
| 88 | + exit 1 |
| 89 | + fi |
| 90 | + done |
| 91 | +
|
| 92 | + - name: Point :latest at ${{ inputs.version }} |
| 93 | + env: |
| 94 | + VERSION: ${{ inputs.version }} |
| 95 | + run: | |
| 96 | + set -euo pipefail |
| 97 | + docker buildx imagetools create \ |
| 98 | + --tag "${IMAGE_NAME}:latest" \ |
| 99 | + "${IMAGE_NAME}:${VERSION}" |
| 100 | + docker buildx imagetools inspect "${IMAGE_NAME}:latest" |
| 101 | +
|
| 102 | + - name: Summary |
| 103 | + env: |
| 104 | + VERSION: ${{ inputs.version }} |
| 105 | + run: | |
| 106 | + { |
| 107 | + echo "### \`${IMAGE_NAME}:latest\` now points at \`${VERSION}\`" |
| 108 | + echo |
| 109 | + echo 'Copied by digest, so :latest is identical to the verified image.' |
| 110 | + } >> "$GITHUB_STEP_SUMMARY" |
0 commit comments