Repository navigation
feat(ci): build must-gather image hermetically in upstream repo [RHIDP-14412] #218
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
rm3l
merged 7 commits into
redhat-developer:main
from
Fortune-Ndlovu:RHIDP-14412-build-must-gather-image-hermetically-in-upstream-repo
Sep 30, 2026
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
54764d3
feat(ci): build must-gather image hermetically [RHIDP-14412]
Fortune-Ndlovu f5fb79f
fix(ci): allow go build to write cache during hermetic image build
Fortune-Ndlovu cc72c03
fix: pass RHDH_MUST_GATHER_VERSION into local hermetic builds [RHIDP-…
Fortune-Ndlovu f91bb00
fix: share one Hermeto image pin and document root go-builder [RHIDP-…
Fortune-Ndlovu bf7119c
fix(ci): include Hermeto version in deps cache key [RHIDP-14412]
Fortune-Ndlovu 95c8b5b
fix: build go-builder stage as non-root in Konflux Containerfile [RHI…
Fortune-Ndlovu a9f8bce
Apply suggestion from @rm3l
rm3l 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 |
|---|---|---|
| @@ -0,0 +1,184 @@ | ||
| # 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 must-gather image hermetically using Hermeto (offline/reproducible build) | ||
| inputs: | ||
| imageName: | ||
| description: The full image name including registry (e.g., quay.io/rhdh-community/rhdh-must-gather) | ||
| 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 Konflux/hermetic Containerfile | ||
| required: false | ||
| default: '.rhdh/docker/Containerfile' | ||
| buildArgs: | ||
| description: Build arguments to pass to buildah (newline-separated KEY=VALUE pairs) | ||
| required: false | ||
| default: '' | ||
| 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@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.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 | ||
| id: hermeto-vars | ||
| shell: bash | ||
| run: | | ||
| # Same pin as local hermetic builds: HERMETO_IMAGE in the Makefile. | ||
| HERMETO_IMAGE=$(sed -n 's/^HERMETO_IMAGE ?= //p' Makefile | head -1) | ||
| if [[ -z "${HERMETO_IMAGE}" ]]; then | ||
| echo "HERMETO_IMAGE is not set in the Makefile" | ||
| exit 1 | ||
| fi | ||
| echo "Using ${HERMETO_IMAGE}" | ||
| echo "HERMETO_IMAGE=${HERMETO_IMAGE}" >> "$GITHUB_ENV" | ||
| echo "LOCAL_CACHE_DIR=/tmp/hermeto-cache/rhdh-must-gather" >> "$GITHUB_ENV" | ||
| # Invalidate the dependency cache when the Hermeto image tag changes. | ||
| echo "hermeto_key=${HERMETO_IMAGE##*:}" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Restore hermeto dependency cache | ||
| id: cache-deps | ||
| uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 | ||
| with: | ||
| path: /tmp/hermeto-cache/rhdh-must-gather | ||
| key: hermeto-deps-${{ inputs.platform }}-${{ steps.hermeto-vars.outputs.hermeto_key }}-${{ hashFiles('go.mod', 'go.sum', 'rpms.lock.yaml') }} | ||
|
|
||
|
Fortune-Ndlovu marked this conversation as resolved.
Resolved
|
||
| - 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" \ | ||
|
Fortune-Ndlovu marked this conversation as resolved.
Resolved
|
||
| --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")" | ||
| sudo chmod -R a+rwX "$(realpath "$LOCAL_CACHE_DIR")" | ||
|
|
||
| - name: Build Docker Image | ||
| id: build | ||
| uses: redhat-actions/buildah-build@719e3c40d8af9790c23eca13f7daa339f2867034 # v3.1.0 | ||
| with: | ||
| containerfiles: ${{ inputs.containerfilePath }} | ||
| context: . | ||
| platform: ${{ inputs.platform }} | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| labels: ${{ steps.meta.outputs.labels }} | ||
| build-args: ${{ inputs.buildArgs }} | ||
| 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 ./podman-artifacts | ||
| echo "Saving images with tags:" | ||
| echo "$TAGS_LIST" | ||
| readarray -t tags <<< "$TAGS_LIST" | ||
| podman save "${tags[@]}" -o ./podman-artifacts/image.tar | ||
| echo "$TAGS_LIST" > ./podman-artifacts/tags.txt | ||
|
|
||
| - name: Upload image artifact | ||
| if: ${{ inputs.skipArtifactUpload != 'true' }} | ||
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | ||
| with: | ||
| name: podman-image-${{ github.event.number || github.ref_name }} | ||
| path: ./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
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.