Repository navigation
feat: build operator images hermetically in upstream repo [RHIDP-15044] #3359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Fortune-Ndlovu
merged 7 commits into
redhat-developer:main
from
Fortune-Ndlovu:RHIDP-15044-rhdh-operator-build-operator-images-hermetically-in-upstream-repo
Aug 20, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3b564f2
feat: build operator images hermetically in upstream repo [RHIDP-15044]
Fortune-Ndlovu 48f5c87
feat: cache hermeto dependencies in CI to speed up PR builds
Fortune-Ndlovu b0257d9
fix: address QODO review findings for hermetic build
Fortune-Ndlovu b373b78
fix: pin hermeto image to 0.60.1 with renovate tracking
Fortune-Ndlovu 6027aea
fix: add go.mod to hermeto cache key to avoid stale deps
Fortune-Ndlovu 2296fa4
chore: clarify Dockerfile supports both hermetic and non-hermetic builds
Fortune-Ndlovu 8bbc6a0
fix: restore original job name to match required status check
Fortune-Ndlovu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,7 @@ | |
| # Ignore build and test binaries. | ||
| bin/ | ||
| testbin/ | ||
|
|
||
| # Hermetic build artifacts | ||
| hermeto-cache/ | ||
| Dockerfile.hermeto | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| # Copyright Red Hat, Inc. | ||
| # | ||
| # Licensed 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: Docker Build (Hermetic) | ||
| description: Build operator image hermetically using Hermeto (offline/reproducible build) | ||
| inputs: | ||
| imageName: | ||
| description: The full image name including registry (e.g., quay.io/rhdh-community/operator) | ||
| required: true | ||
| imageTags: | ||
| description: The tags to apply to the image | ||
| required: true | ||
| imageLabels: | ||
| description: The labels for the Docker image | ||
| required: false | ||
| platform: | ||
| description: "Target given CPU platform architecture (default: linux/amd64)" | ||
| required: false | ||
| default: linux/amd64 | ||
| containerfilePath: | ||
| description: Path to the Dockerfile to use | ||
| required: false | ||
| default: 'Dockerfile' | ||
| skipArtifactUpload: | ||
| description: Skip uploading the built image as a GitHub artifact | ||
| required: false | ||
| default: 'false' | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Extract metadata (tags, labels) for Docker | ||
| id: meta | ||
| uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0 | ||
| with: | ||
| images: ${{ inputs.imageName }} | ||
| tags: | | ||
| ${{ inputs.imageTags }} | ||
| labels: | | ||
| ${{ inputs.imageLabels }} | ||
|
|
||
| - name: Ensure podman is available | ||
| shell: bash | ||
| run: | | ||
| if ! command -v podman &>/dev/null; then | ||
| echo "podman not found, installing..." | ||
| sudo apt-get -y update && sudo apt-get -y install podman | ||
| fi | ||
| podman --version | ||
|
|
||
| - name: Set up hermetic build variables | ||
| shell: bash | ||
| run: | | ||
| # renovate: datasource=docker depName=quay.io/konflux-ci/hermeto | ||
| echo "HERMETO_IMAGE=quay.io/konflux-ci/hermeto:0.60.1" >> "$GITHUB_ENV" | ||
| echo "LOCAL_CACHE_DIR=./hermeto-cache/operator" >> "$GITHUB_ENV" | ||
|
|
||
| - name: Restore hermeto dependency cache | ||
| id: cache-deps | ||
| uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 | ||
| with: | ||
| path: ./hermeto-cache/operator | ||
| key: hermeto-deps-${{ inputs.platform }}-${{ hashFiles('go.mod', 'go.sum', 'rpms.lock.yaml') }} | ||
|
|
||
| - name: Fetch dependencies with hermeto | ||
| if: steps.cache-deps.outputs.cache-hit != 'true' | ||
| shell: bash | ||
| run: | | ||
| set -ex | ||
|
|
||
| mkdir -p "$LOCAL_CACHE_DIR" | ||
|
|
||
| echo "::group::Fetching dependencies with hermeto" | ||
| podman run --rm -v "$PWD:/source:z" -v "$LOCAL_CACHE_DIR:/cachi2:z" -w /source "$HERMETO_IMAGE" \ | ||
| --log-level DEBUG \ | ||
| fetch-deps \ | ||
| --source . \ | ||
| --output /cachi2/output \ | ||
| '[{"type": "rpm", "path": "."}, {"type": "gomod", "path": "."}]' | ||
| echo "::endgroup::" | ||
|
|
||
| if [ ! -d "$LOCAL_CACHE_DIR/output" ]; then | ||
| echo "No output directory found after fetch-deps" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "::group::Generating environment file" | ||
| podman run --rm -v "$PWD:/source:z" -v "$LOCAL_CACHE_DIR:/cachi2:z" -w /source "$HERMETO_IMAGE" \ | ||
| --log-level DEBUG \ | ||
| generate-env --format env \ | ||
| --output /cachi2/cachi2.env /cachi2/output | ||
| echo "::endgroup::" | ||
|
|
||
| echo "::group::Injecting files" | ||
| podman run --rm -v "$PWD:/source:z" -v "$LOCAL_CACHE_DIR:/cachi2:z" -w /source "$HERMETO_IMAGE" \ | ||
| --log-level DEBUG \ | ||
| inject-files /cachi2/output | ||
| echo "::endgroup::" | ||
|
|
||
| - name: Generate env and inject files (cache hit) | ||
| if: steps.cache-deps.outputs.cache-hit == 'true' | ||
| shell: bash | ||
| run: | | ||
| set -ex | ||
| echo "::group::Generating environment file from cached deps" | ||
| podman run --rm -v "$PWD:/source:z" -v "$LOCAL_CACHE_DIR:/cachi2:z" -w /source "$HERMETO_IMAGE" \ | ||
| --log-level DEBUG \ | ||
| generate-env --format env \ | ||
| --output /cachi2/cachi2.env /cachi2/output | ||
| echo "::endgroup::" | ||
|
|
||
| echo "::group::Injecting files from cached deps" | ||
| podman run --rm -v "$PWD:/source:z" -v "$LOCAL_CACHE_DIR:/cachi2:z" -w /source "$HERMETO_IMAGE" \ | ||
| --log-level DEBUG \ | ||
| inject-files /cachi2/output | ||
| echo "::endgroup::" | ||
|
|
||
| - name: Fix cache ownership for non-root buildah | ||
| shell: bash | ||
| run: | | ||
| set -ex | ||
| echo LOCAL_CACHE_DIR_REALPATH=$(realpath "$LOCAL_CACHE_DIR") >> "$GITHUB_ENV" | ||
| sudo chown -R runner "$(realpath "$LOCAL_CACHE_DIR")" | ||
|
|
||
| - name: Transform Dockerfile for hermetic build | ||
| shell: bash | ||
| id: transform-containerfile | ||
| env: | ||
| CONTAINERFILE_PATH: ${{ inputs.containerfilePath }} | ||
| TRANSFORMED_CONTAINERFILE: ${{ inputs.containerfilePath }}.hermeto | ||
| run: | | ||
| set -x | ||
|
|
||
| cp "$CONTAINERFILE_PATH" "$TRANSFORMED_CONTAINERFILE" | ||
|
|
||
| # Insert RPM repo replacement before every dnf/microdnf install | ||
| sed -i '/RUN *\(dnf\|microdnf\) install/i RUN rm -r /etc/yum.repos.d/* && cp /cachi2/output/deps/rpm/$(uname -m)/repos.d/hermeto.repo /etc/yum.repos.d/' \ | ||
| "$TRANSFORMED_CONTAINERFILE" | ||
|
|
||
| # Prepend cachi2 env sourcing to every RUN command | ||
| sed -i 's/^\s*RUN /RUN . \/cachi2\/cachi2.env \&\& /' "$TRANSFORMED_CONTAINERFILE" | ||
|
|
||
| echo "transformed_containerfile=$TRANSFORMED_CONTAINERFILE" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Build Docker Image | ||
| id: build | ||
| uses: redhat-actions/buildah-build@7a95fa7ee0f02d552a32753e7414641a04307056 # v2.13 | ||
| with: | ||
| containerfiles: ${{ steps.transform-containerfile.outputs.transformed_containerfile }} | ||
| context: . | ||
| platform: ${{ inputs.platform }} | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| labels: ${{ steps.meta.outputs.labels }} | ||
| extra-args: | | ||
| --network=none | ||
| --volume ${{ env.LOCAL_CACHE_DIR_REALPATH }}:/cachi2:z | ||
|
|
||
| - name: Save image as artifact | ||
| if: ${{ inputs.skipArtifactUpload != 'true' }} | ||
| shell: bash | ||
| env: | ||
| TAGS_LIST: ${{ steps.meta.outputs.tags }} | ||
| run: | | ||
| mkdir -p ./operator-podman-artifacts | ||
| echo "Saving images with tags:" | ||
| echo "$TAGS_LIST" | ||
| readarray -t tags <<< "$TAGS_LIST" | ||
| podman save "${tags[@]}" -o ./operator-podman-artifacts/image.tar | ||
| echo "$TAGS_LIST" > ./operator-podman-artifacts/tags.txt | ||
|
|
||
| - name: Upload image artifact | ||
| if: ${{ inputs.skipArtifactUpload != 'true' }} | ||
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | ||
| with: | ||
| name: podman-image-${{ github.event.number || github.ref_name }}-${{ env.SHORT_SHA }} | ||
| path: ./operator-podman-artifacts/ | ||
| retention-days: 1 | ||
| if-no-files-found: error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ bin/* | |
| bundle_tmp* | ||
| testbin/* | ||
| Dockerfile.cross | ||
| Dockerfile.hermeto | ||
| hermeto-cache/ | ||
| __debug_bin* | ||
| tmp/* | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.