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


##########
.github/workflows/delete-rc-docker-image.yaml:
##########
@@ -0,0 +1,141 @@
+#
+# 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: Delete RC Docker Image
+
+# Deletes the Docker image of a release candidate from Docker Hub, once it is 
not needed anymore.
+#
+# The "Publish Docker Image" workflow publishes 
apache/solr-operator:<version>-rc<N> from the RC branch
+# rc/<version>-rc<N>. The release wizard deletes that RC branch once the RC is 
done with, either because its
+# vote failed and a new RC is started, or because the release is published. 
Deleting the RC branch triggers this
+# workflow, which deletes the matching RC image.
+#
+# It can also be run manually, for an RC image whose branch is already gone. 
Only RC image tags (vX.Y.Z-rcN)
+# are ever deleted, never release images, and never while the RC branch still 
exists.
+
+on:
+  # The delete event has no branch filters, so the job below only runs for RC 
branches.
+  delete:
+  workflow_dispatch:
+    inputs:
+      rc-image-tag:
+        description: 'RC image tag to delete from apache/solr-operator, e.g. 
v0.11.0-rc1'
+        required: true
+        type: string
+
+permissions:
+  contents: read
+
+concurrency:
+  group: delete-rc-docker-image-${{ github.event.ref || inputs.rc-image-tag }}

Review Comment:
   Fixed in 86c55b4. Both workflows now use one concurrency group per image, 
keyed by the RC branch name: `docker-image-${{ github.ref_name }}` in the 
publish workflow, and `docker-image-${{ github.event.ref || format('rc/{0}', 
inputs.rc-image-tag) }}` in the delete workflow, including manual runs. A 
delete waits for a running publish of the same image. A queued publish whose RC 
branch has been deleted no longer publishes: the new first job checks that the 
branch still exists and points at the run's commit (see the reply on the 
obsolete-run comment).



##########
.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
+            fi
+            PREVIOUS_DIGEST="$(tr -d '"' <<< "${OUTPUT}")"
+            echo "::warning::${IMAGE} already exists (${PREVIOUS_DIGEST}), and 
will be overwritten with an image built from this RC branch"
+            echo "previous-digest=${PREVIOUS_DIGEST}" >> "$GITHUB_OUTPUT"
+            exit 0

Review Comment:
   Fixed in 86c55b4. Before building, the workflow reads the existing image's 
`org.opencontainers.image.revision` label. If the image was already built from 
this commit, the run only verifies it, with no rebuild and no push. So a re-run 
can no longer replace an image that may be under vote, and the non-reproducible 
rebuild (`--pull`, the build time in the binary) can't happen. An RC image is 
only replaced when it was built from a different commit. Together with the 
current-ref check, that only happens when the RC branch was deliberately 
overwritten.



##########
.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
+            fi
+            PREVIOUS_DIGEST="$(tr -d '"' <<< "${OUTPUT}")"
+            echo "::warning::${IMAGE} already exists (${PREVIOUS_DIGEST}), and 
will be overwritten with an image built from this RC branch"
+            echo "previous-digest=${PREVIOUS_DIGEST}" >> "$GITHUB_OUTPUT"
+            exit 0
+          fi
+          # Any other failure (e.g. Docker Hub being unreachable) must not be 
mistaken for the tag not existing.
+          if ! grep -qi "not found" <<< "${OUTPUT}"; then
+            echo "Error: could not check whether ${IMAGE} exists:" >&2
+            echo "${OUTPUT}" >&2
+            exit 1
+          fi
+          echo "${IMAGE} does not exist yet"
+
+      # DOCKERHUB_USER and DOCKERHUB_TOKEN are provided to the repository by 
ASF Infra.
+      - name: Log in to Docker Hub
+        env:
+          DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
+          DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
+        run: |
+          set -euo pipefail
+          if [[ -z "${DOCKERHUB_USER}" || -z "${DOCKERHUB_TOKEN}" ]]; then
+            echo "Error: the DOCKERHUB_USER and DOCKERHUB_TOKEN secrets are 
not available to this workflow." >&2
+            exit 1
+          fi
+          echo "${DOCKERHUB_TOKEN}" | docker login docker.io -u 
"${DOCKERHUB_USER}" --password-stdin
+
+      # The Docker CLI on the runner already includes buildx. The Dockerfile 
cross-compiles the binary, so the
+      # images for every platform are built natively on this runner, without 
CPU emulation.
+      - name: Build and push the image
+        env:
+          IMAGE: ${{ steps.meta.outputs.image }}
+          IMAGE_TAG: ${{ steps.meta.outputs.image-tag }}
+          GIT_SHA: ${{ steps.meta.outputs.git-sha }}
+          DOCS_VERSION: ${{ steps.meta.outputs.docs-version }}
+        run: |
+          set -euo pipefail
+          docker buildx create --use --name solr-operator-release
+          docker buildx build --pull --push \

Review Comment:
   Fixed in 86c55b4. A new `current` job runs first and uses `git ls-remote` to 
check that the RC branch (or release tag) still exists and points at 
`github.sha`. For annotated tags it accepts either the tag object or the commit 
it points to. The publish job only runs if it does. Otherwise the run ends with 
a warning and publishes nothing. So re-running A after the branch moved to B no 
longer touches B's image. Since publishing is serialized per image, checking 
once at the start is enough: a newer push of the branch waits for this run, 
then publishes over it.



-- 
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