HoustonPutman commented on code in PR #923:
URL: https://github.com/apache/solr-operator/pull/923#discussion_r4762817907


##########
.github/workflows/publish-docker-image.yaml:
##########
@@ -0,0 +1,246 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+name: Publish Docker Image
+
+# Builds the multi-architecture Solr Operator Docker image for a release, and 
pushes it to Docker Hub.
+# This is done by CI so that the release manager does not need personal push 
access to apache/solr-operator.
+#
+#   - Pushing an RC branch, rc/<version>-rc<N> (e.g. rc/v0.11.0-rc1), 
publishes apache/solr-operator:<version>-rc<N>.
+#     The release wizard pushes this branch with the release commit that the 
RC artifacts were built from.
+#   - Pushing a release tag, <version> (e.g. v0.11.0), publishes 
apache/solr-operator:<version>.
+#     The release wizard pushes this tag once the vote has passed, on that 
same release commit.
+#
+# Both are built from the exact commit pushed, so the Git SHA in the image is 
the release commit's.
+# Release images are never overwritten: if the release image tag already 
exists the run fails.
+# RC images are overwritten when their RC branch is (force) pushed again, 
which the release wizard only allows before the
+# vote on that RC has started. Voters' smoke tests check the Git SHA in the 
image, so they would catch a mismatched image.
+
+on:
+  push:
+    branches:
+      - 'rc/v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+'
+    tags:
+      - 'v[0-9]+.[0-9]+.[0-9]+'
+
+permissions:
+  contents: read
+
+# Two runs for the same ref must never race to push the same image tag.
+concurrency:
+  group: publish-docker-image-${{ github.ref }}
+  cancel-in-progress: false
+
+env:
+  IMAGE_REPO: docker.io/apache/solr-operator
+  PLATFORMS: linux/amd64,linux/arm64
+
+jobs:
+  publish:
+    name: Build & Publish Docker Image

Review Comment:
   Fixed in 27b3991 (`if: ${{ !github.event.deleted }}`). That guard is now on 
the new first job, `current`, so a branch deletion starts no publish run at all.



##########
.github/workflows/publish-docker-image.yaml:
##########
@@ -0,0 +1,246 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+name: Publish Docker Image
+
+# Builds the multi-architecture Solr Operator Docker image for a release, and 
pushes it to Docker Hub.
+# This is done by CI so that the release manager does not need personal push 
access to apache/solr-operator.
+#
+#   - Pushing an RC branch, rc/<version>-rc<N> (e.g. rc/v0.11.0-rc1), 
publishes apache/solr-operator:<version>-rc<N>.
+#     The release wizard pushes this branch with the release commit that the 
RC artifacts were built from.
+#   - Pushing a release tag, <version> (e.g. v0.11.0), publishes 
apache/solr-operator:<version>.
+#     The release wizard pushes this tag once the vote has passed, on that 
same release commit.
+#
+# Both are built from the exact commit pushed, so the Git SHA in the image is 
the release commit's.
+# Release images are never overwritten: if the release image tag already 
exists the run fails.
+# RC images are overwritten when their RC branch is (force) pushed again, 
which the release wizard only allows before the
+# vote on that RC has started. Voters' smoke tests check the Git SHA in the 
image, so they would catch a mismatched image.
+
+on:
+  push:
+    branches:
+      - 'rc/v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+'
+    tags:
+      - 'v[0-9]+.[0-9]+.[0-9]+'
+
+permissions:
+  contents: read
+
+# Two runs for the same ref must never race to push the same image tag.
+concurrency:
+  group: publish-docker-image-${{ github.ref }}
+  cancel-in-progress: false
+
+env:
+  IMAGE_REPO: docker.io/apache/solr-operator
+  PLATFORMS: linux/amd64,linux/arm64
+
+jobs:
+  publish:
+    name: Build & Publish Docker Image
+    runs-on: ubuntu-latest
+    timeout-minutes: 60
+    steps:
+      # Full history, so the release tag's commit can be checked against the 
release branch below.
+      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # 
v7.0.1
+        with:
+          fetch-depth: 0
+          persist-credentials: false
+
+      # The ref name is passed through the environment rather than 
interpolated into the script body, so
+      # that a malicious ref name cannot inject shell commands.
+      - name: Determine the image tag
+        id: meta
+        env:
+          REF_TYPE: ${{ github.ref_type }}
+          REF_NAME: ${{ github.ref_name }}
+        run: |
+          set -euo pipefail
+
+          # The trigger filters are globs, so re-check the ref names strictly 
here.
+          if [[ "${REF_TYPE}" == "branch" && "${REF_NAME}" =~ 
^rc/(v([0-9]+)\.([0-9]+)\.[0-9]+)-rc[0-9]+$ ]]; then
+            VERSION="${BASH_REMATCH[1]}"
+            IMAGE_TAG="${REF_NAME#rc/}"
+          elif [[ "${REF_TYPE}" == "tag" && "${REF_NAME}" =~ 
^(v([0-9]+)\.([0-9]+)\.[0-9]+)$ ]]; then
+            VERSION="${BASH_REMATCH[1]}"
+            IMAGE_TAG="${VERSION}"
+          else
+            echo "Error: '${REF_NAME}' (${REF_TYPE}) is neither an RC branch 
(rc/vX.Y.Z-rcN) nor a release tag (vX.Y.Z)" >&2
+            exit 1
+          fi
+          MAJOR="${BASH_REMATCH[2]}"
+          MINOR="${BASH_REMATCH[3]}"
+
+          # For an annotated tag, HEAD is the tagged commit (not the tag 
object), which is what the binary reports.
+          # The release wizard and smoke tests identify the commit by its 
first 7 characters.
+          GIT_REV="$(git rev-parse HEAD)"
+
+          {
+            echo "version=${VERSION}"
+            echo "image-tag=${IMAGE_TAG}"
+            echo "image=${IMAGE_REPO}:${IMAGE_TAG}"
+            echo "docs-version=${MAJOR}_${MINOR}"
+            echo "release-branch=release-${MAJOR}.${MINOR}"
+            echo "git-rev=${GIT_REV}"
+            echo "git-sha=${GIT_REV:0:7}"
+          } >> "$GITHUB_OUTPUT"
+          echo "Publishing ${IMAGE_REPO}:${IMAGE_TAG} from commit ${GIT_REV}"
+
+      # Only a release commit, made by the release wizard, may be published as 
a release or RC image.
+      - name: Verify this is the release commit for the version
+        env:
+          VERSION: ${{ steps.meta.outputs.version }}
+        run: |
+          set -euo pipefail
+          COMMIT_VERSION="$(sed -nE 's/^[[:space:]]*Version[[:space:]]+= 
"(.*)"/\1/p' version/version.go)"
+          COMMIT_SUFFIX="$(sed -nE 's/^[[:space:]]*VersionSuffix[[:space:]]+= 
"(.*)"/\1/p' version/version.go)"
+          if [[ "${COMMIT_VERSION}" != "${VERSION}" || -n "${COMMIT_SUFFIX}" 
]]; then
+            echo "Error: version/version.go has version '${COMMIT_VERSION}' 
and suffix '${COMMIT_SUFFIX}'," >&2
+            echo "       but a release commit for ${VERSION} must have version 
'${VERSION}' and no suffix" >&2
+            exit 1
+          fi
+          echo "version/version.go is set to ${VERSION}, with no suffix"
+
+      # A release must be the RC commit that was voted on, fast-forwarded onto 
the release branch before tagging.
+      - name: Verify the release tag is on the release branch
+        if: ${{ github.ref_type == 'tag' }}
+        env:
+          RELEASE_BRANCH: ${{ steps.meta.outputs.release-branch }}
+          GIT_REV: ${{ steps.meta.outputs.git-rev }}
+        run: |
+          set -euo pipefail
+          if ! git merge-base --is-ancestor "${GIT_REV}" 
"origin/${RELEASE_BRANCH}"; then
+            echo "Error: commit ${GIT_REV} is not on ${RELEASE_BRANCH}." >&2
+            echo "       Fast-forward ${RELEASE_BRANCH} to the release commit 
before pushing the release tag." >&2
+            exit 1
+          fi
+          echo "Commit ${GIT_REV} is on ${RELEASE_BRANCH}"
+
+      # A release image must never replace one that people may already have 
pulled. An RC image may be replaced,
+      # since the RC branch is only overwritten before the vote on it starts, 
but its previous digest is recorded.
+      - name: Check whether the image tag already exists
+        id: existing
+        env:
+          IMAGE: ${{ steps.meta.outputs.image }}
+          REF_TYPE: ${{ github.ref_type }}
+        run: |
+          set -euo pipefail
+          if OUTPUT="$(docker buildx imagetools inspect "${IMAGE}" --format 
'{{json .Manifest.Digest}}' 2>&1)"; then
+            if [[ "${REF_TYPE}" == "tag" ]]; then
+              echo "Error: ${IMAGE} already exists, and release images are 
never overwritten." >&2
+              exit 1

Review Comment:
   Fixed in 86c55b4, without a separate job. If the image tag exists and was 
built from this same commit, the run skips the login, build and push, and goes 
straight to verification. Re-running a run whose verification failed after 
publishing therefore finishes the verification, for RC images and release 
images alike. A release image built from a different commit still fails the run.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to