@@ -20,10 +20,10 @@ inputs:
20
20
required : true
21
21
password :
22
22
description : The password to use for the registry
23
- required : true
23
+ required : false
24
24
username :
25
25
description : The username to use for the registry
26
- required : true
26
+ required : false
27
27
imageName :
28
28
description : The name of the image to build
29
29
required : true
@@ -34,18 +34,30 @@ inputs:
34
34
description : The labels for the Docker image
35
35
required : false
36
36
push :
37
- description : Whether to push the image
37
+ description : Whether to push the image (automatically ignored and assumed to be false if enableHermeticBuild is true)
38
38
required : true
39
39
platform :
40
40
description : " Target given CPU platform architecture (default: linux/amd64)"
41
41
required : false
42
42
default : linux/amd64
43
+ enableHermeticBuild :
44
+ description : Whether to enable hermetic builds using hermeto (currently only supported for linux/amd64)
45
+ required : false
46
+ default : ' false'
47
+ componentDirectory :
48
+ description : Path to the component directory for hermetic builds
49
+ required : false
50
+ default : ' .'
51
+ dockerfilePath :
52
+ description : Path to the Dockerfile to use
53
+ required : false
54
+ default : ' docker/Dockerfile'
43
55
44
56
outputs :
45
57
digest :
58
+ description : The digest of the built Docker image
46
59
value : ${{ steps.build.outputs.digest }}
47
60
48
-
49
61
runs :
50
62
using : composite
51
63
steps :
@@ -63,11 +75,15 @@ runs:
63
75
- name : Set up QEMU
64
76
uses : docker/setup-qemu-action@v3
65
77
66
- - name : Set up Docker Buildx
67
- uses : docker/setup-buildx-action@v3
78
+ # - name: Install qemu dependency
79
+ # shell: bash
80
+ # run: |
81
+ # set -ex
82
+ # sudo apt-get update
83
+ # sudo apt-get install -y qemu-user-static
68
84
69
- - name : Log in to the Container registry
70
- if : ${{ inputs.push }}
85
+ - name : Login to Registry
86
+ if : ${{ inputs.push == 'true' && inputs.enableHermeticBuild != 'true' }}
71
87
uses : docker/login-action@v3
72
88
with :
73
89
registry : ${{ inputs.registry }}
@@ -84,14 +100,151 @@ runs:
84
100
labels : |
85
101
${{ inputs.imageLabels }}
86
102
87
- - name : Build and push Docker image
103
+ # Hermetic Build Steps
104
+ - name : Set up hermetic build variables
105
+ if : ${{ inputs.enableHermeticBuild == 'true' }}
106
+ shell : bash
107
+ run : |
108
+ echo "HERMETO_IMAGE=quay.io/konflux-ci/hermeto:latest" >> $GITHUB_ENV
109
+ echo "LOCAL_CACHE_DIR=./hermeto-cache/$(basename ${{ inputs.componentDirectory }})" >> $GITHUB_ENV
110
+ echo "COMPONENT_ABS_DIR=${{ github.workspace }}/${{ inputs.componentDirectory }}" >> $GITHUB_ENV
111
+
112
+ - name : Cache dependencies with hermeto
113
+ if : ${{ inputs.enableHermeticBuild == 'true' }}
114
+ shell : bash
115
+ run : |
116
+ set -ex
117
+
118
+ echo "=== Creating local cache directory ==="
119
+ mkdir -p ${{ env.LOCAL_CACHE_DIR }} || echo "Failed to create local cache directory"
120
+
121
+ echo "=== Fetching dependencies with hermeto ==="
122
+ # Build hermeto cache for rpm, yarn, and pip (currently does not support ARM64 due to quay.io/konflux-ci/hermeto:latest not having an arm64 image)
123
+ podman run --rm -v "$PWD:/source:z" -v "$LOCAL_CACHE_DIR:/cachi2:z" -w /source "$HERMETO_IMAGE" \
124
+ --log-level DEBUG \
125
+ fetch-deps --dev-package-managers \
126
+ --source . \
127
+ --output /cachi2/output \
128
+ '[{"type": "rpm", "path": "."}, {"type": "yarn","path": "."}, {"type": "yarn","path": "./dynamic-plugins"}, {"type": "pip","path": "./python", "allow_binary": "false"}]' || echo "Fetch-deps failed"
129
+
130
+ if [ -d ${{ env.LOCAL_CACHE_DIR }}/output ]; then
131
+ echo "=== Output directory exists, running generate-env ==="
132
+
133
+ # Generate environment file
134
+ podman run --rm -v "$PWD:/source:z" -v "$LOCAL_CACHE_DIR:/cachi2:z" -w /source "$HERMETO_IMAGE" \
135
+ --log-level DEBUG \
136
+ generate-env --format env \
137
+ --output /cachi2/cachi2.env /cachi2/output
138
+
139
+ else
140
+ echo "No output directory found, skipping generate-env"
141
+ exit 1
142
+ fi
143
+
144
+ if [ -d ${{ env.LOCAL_CACHE_DIR }}/output ]; then
145
+ echo "=== Running inject-files ==="
146
+
147
+ podman run --rm -v "$PWD:/source:z" -v "$LOCAL_CACHE_DIR:/cachi2:z" -w /source "$HERMETO_IMAGE" \
148
+ --log-level DEBUG \
149
+ inject-files /cachi2/output || echo "Inject-files failed"
150
+
151
+ else
152
+ echo "No output directory found, skipping inject-files"
153
+ exit 1
154
+ fi
155
+
156
+ echo LOCAL_CACHE_DIR_REALPATH=$(realpath "${{ env.LOCAL_CACHE_DIR }}") >> $GITHUB_ENV
157
+
158
+ - name : " Fix Cache Ownership for Non-Root Buildah"
159
+ if : ${{ inputs.enableHermeticBuild == 'true' }}
160
+ shell : bash
161
+ run : |
162
+ set -ex
163
+ echo "=== Before ownership fix ==="
164
+ ls -l ${{ env.LOCAL_CACHE_DIR_REALPATH }}
165
+ echo "=== Attempting to fix ownership to runner user ==="
166
+ sudo chown -R runner ${{ env.LOCAL_CACHE_DIR_REALPATH }}
167
+ echo "=== After ownership fix ==="
168
+ ls -l ${{ env.LOCAL_CACHE_DIR_REALPATH }}
169
+
170
+ - name : Transform Containerfile for hermetic build
171
+ if : ${{ inputs.enableHermeticBuild == 'true' }}
172
+ shell : bash
173
+ run : |
174
+ set -x
175
+
176
+ CONTAINERFILE_PATH="${{ inputs.dockerfilePath }}"
177
+
178
+ TRANSFORMED_CONTAINERFILE="${CONTAINERFILE_PATH}.hermeto"
179
+
180
+ # Copy original dockerfile for hermetic build modifications
181
+ cp "$CONTAINERFILE_PATH" "$TRANSFORMED_CONTAINERFILE"
182
+
183
+ # Transform the dockerfile to simulate Konflux build
184
+ # Configure dnf to use the cachi2 repo
185
+ sed -i '/RUN *\(dnf\|microdnf\) install/i RUN rm -r /etc/yum.repos.d/* && cp /cachi2/output/deps/rpm/x86_64/repos.d/hermeto.repo /etc/yum.repos.d/' "$TRANSFORMED_CONTAINERFILE"
186
+
187
+ # Inject the cachi2 env variables to every RUN command
188
+ sed -i 's/^\s*RUN /RUN . \/cachi2\/cachi2.env \&\& /' "$TRANSFORMED_CONTAINERFILE"
189
+
190
+ echo "TRANSFORMED_CONTAINERFILE=$TRANSFORMED_CONTAINERFILE" >> $GITHUB_ENV
191
+
192
+ - name : Build and push Docker image (Standard)
193
+ if : ${{ inputs.enableHermeticBuild != 'true' }}
88
194
uses : docker/build-push-action@v6
89
195
id : build
90
196
with :
91
197
context : .
92
- file : docker/Dockerfile
198
+ file : ${{ inputs.dockerfilePath }}
93
199
push : ${{ inputs.push }}
94
200
provenance : false
95
201
tags : ${{ steps.meta.outputs.tags }}
96
202
labels : ${{ steps.meta.outputs.labels }}
97
203
platforms : ${{ inputs.platform }}
204
+
205
+ - name : " Build Docker Image (Hermetic)"
206
+ id : hermetic-build
207
+ if : ${{ inputs.enableHermeticBuild == 'true' }}
208
+ uses : redhat-actions/buildah-build@7a95fa7ee0f02d552a32753e7414641a04307056 # v2.13
209
+ with :
210
+ containerfiles : ${{ inputs.dockerfilePath }}.hermeto
211
+ context : .
212
+ platform : ${{ inputs.platform }}
213
+ tags : ${{ steps.meta.outputs.tags }}
214
+ labels : ${{ steps.meta.outputs.labels }}
215
+ extra-args : |
216
+ --network=none
217
+ --volume ${{ env.LOCAL_CACHE_DIR_REALPATH }}:/cachi2:z
218
+
219
+ - name : Set build output for hermetic builds
220
+ if : ${{ inputs.enableHermeticBuild == 'true' }}
221
+ shell : bash
222
+ run : |
223
+ echo "digest=${{ steps.hermetic-build.outputs.digest || 'no-digest-available' }}" >> $GITHUB_OUTPUT
224
+
225
+ - name : Save image as artifact (Hermetic)
226
+ if : ${{ inputs.enableHermeticBuild == 'true' }}
227
+ shell : bash
228
+ run : |
229
+ mkdir -p ./rhdh-podman-artifacts
230
+
231
+ # Extract the built image tags from the metadata
232
+ TAGS_LIST="${{ steps.meta.outputs.tags }}"
233
+
234
+ # Save all the built images to tar (podman save can handle multiple tags)
235
+ echo "Saving images with tags:"
236
+ echo "$TAGS_LIST"
237
+
238
+ podman save $TAGS_LIST -o ./rhdh-podman-artifacts/image.tar
239
+
240
+ # Save metadata for the push workflow
241
+ echo "$TAGS_LIST" > ./rhdh-podman-artifacts/tags.txt
242
+
243
+ - name : Upload image artifact
244
+ if : ${{ inputs.enableHermeticBuild == 'true' }}
245
+ uses : actions/upload-artifact@v4
246
+ with :
247
+ name : podman-image-${{ github.event.number || 'main' }}-${{ env.SHORT_SHA }}
248
+ path : ./rhdh-podman-artifacts/
249
+ retention-days : 1
250
+ if-no-files-found : error
0 commit comments