@@ -118,55 +118,12 @@ jobs:
118118 matrix : ${{ steps.set-matrix.outputs.matrix }}
119119 tag : ${{ steps.set-matrix.outputs.WORKING_TAG }}
120120 steps :
121- - name : Set matrix
121+ - uses : ./.github/actions/prepare-build
122122 id : set-matrix
123- run : |
124- # turn the comma separated string into a list
125- platforms=()
126- IFS=',' read -r -a platforms <<< "${{ inputs.platforms }}"
127-
128- MATRIX="{\"include\":[]}"
129- for platform in "${platforms[@]}"; do
130- MATRIX=$(echo $MATRIX | jq ".include += [{\"platform\": \"$platform\"}]")
131- done
132- echo "matrix=$(echo $MATRIX | jq -c '.')" >> $GITHUB_OUTPUT
133-
134- WORKING_TAG="${{ github.ref_name }}"
135- echo "WORKING_TAG=${WORKING_TAG//\//_}" >> "$GITHUB_OUTPUT"
136-
137- - name : Install Cosign
138- if : ${{ inputs.upstream-public-key != '' }}
139- uses : sigstore/cosign-installer@3454372f43399081ed03b604cb2d021dabca52bb # v3.8.2
140-
141- - name : Checkout
142- if : ${{ inputs.upstream-public-key != '' }}
143- uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
144123 with :
145- submodules : true
146-
147- - name : Extract upstream
148- if : ${{ inputs.upstream-public-key != '' }}
149- id : extract
150- run : |
151- # Install Dockerfile parser
152- pip3 install dockerfile-parse
153- # Extract the last FROM image using Python
154- upstream=$(python3 - << 'EOF'
155- from dockerfile_parse import DockerfileParser
156- with open("${{ inputs.containerfile }}", "r") as f:
157- dfp = DockerfileParser(fileobj=f)
158- froms = [s['value'].split()[0] for s in dfp.structure if s['instruction'] == 'FROM']
159- print(froms[-1])
160- EOF
161- )
162- echo "upstream-image=$upstream" >> $GITHUB_OUTPUT
163-
164- - name : Verify signature
165- if : ${{ inputs.upstream-public-key != '' }}
166- id : verify
167- run : |
168- echo "Verifying signature for ${{ steps.extract.outputs.upstream-image }}"
169- cosign verify --key ${{ inputs.upstream-public-key }} ${{ steps.extract.outputs.upstream-image }} | jq .
124+ platforms : ${{ inputs.platforms }}
125+ containerfile : ${{ inputs.containerfile }}
126+ upstream-public-key : ${{ inputs.upstream-public-key }}
170127
171128 build_push :
172129 name : Build and push image
@@ -189,68 +146,22 @@ jobs:
189146 version : ${{ steps.load.outputs.version }}
190147
191148 steps :
192- - name : Set up environment
193- id : set-env
194- run : |
195- ARCH=${{ matrix.platform }}
196- echo "CLEAN_ARCH=${ARCH//\//_}" >> "$GITHUB_ENV"
197-
198- - name : Login to Container Registry
199- run : |
200- echo ${{ secrets.REGISTRY_TOKEN }} | podman login -u ${{ inputs.REGISTRY_USER }} --password-stdin ${{ env.IMAGE_REGISTRY }}
201-
202- # This is needed by cosign
203- echo ${{ secrets.REGISTRY_TOKEN }} | docker login -u ${{ inputs.REGISTRY_USER }} --password-stdin ${{ env.IMAGE_REGISTRY }}
204-
205- - name : Maximize build space
206- if : ${{ matrix.platform != 'arm64' && inputs.skip-maximize-build-space != true }}
207- uses : ublue-os/remove-unwanted-software@cc0becac701cf642c8f0a6613bbdaf5dc36b259e # v9
208- with :
209- remove-codeql : true
210-
211149 - name : Checkout
212150 uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
213- with :
214- submodules : true
215- fetch-depth : 500
216-
217- - name : Build image
218- id : build
219- shell : bash
220- env :
221- IMAGE_TAG : ${{ needs.generate_matrix.outputs.tag }}-${{ env.CLEAN_ARCH }}
222- VARIANT : ${{ inputs.variant }}
223- run : |
224- sudo podman build \
225- --platform=linux/${{ matrix.platform }} \
226- --security-opt=label=disable \
227- --cap-add=all \
228- --device /dev/fuse \
229- --timestamp=0 \
230- --iidfile /tmp/image-id \
231- --build-arg IMAGE_NAME=${{ env.IMAGE_NAME }} \
232- --build-arg IMAGE_REGISTRY=${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_PATH }} \
233- --build-arg VARIANT=${{ env.VARIANT }} \
234- -t ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} \
235- -f ${{ env.CONTAINERFILE }} \
236- .
237-
238- echo "image-id=$(cat /tmp/image-id)" >> $GITHUB_OUTPUT
239- echo "date=$(date -u +%Y\-%m\-%d\T%H\:%M\:%S\Z)" >> $GITHUB_OUTPUT
240151
241- - name : Check image
242- id : check
243- shell : bash
244- env :
245- IMAGE_ID : ${{ steps.build.outputs.image-id }}
246- run : |
247- INSPECT=$(sudo podman image inspect ${{ env.IMAGE_ID }} )
248- echo $INSPECT | jq .
249- echo "redhat-id=$(echo "$INSPECT" | jq -r '.[0].Labels["redhat.id"]')" >> $GITHUB_OUTPUT
250- echo "redhat-version-id=$(echo "$INSPECT" | jq -r '.[0].Labels["redhat.version-id"]')" >> $GITHUB_OUTPUT
251- echo "version=$(echo "$INSPECT" | jq -r '.[0].Labels["org.opencontainers.image.version"]')" >> $GITHUB_OUTPUT
252-
253- sudo podman run --platform=linux/ ${{ matrix.platform }} --rm ${{ env.IMAGE_ID }} bash -c "rpm -q almalinux-gpg-keys && cat /etc/os-release"
152+ - uses : ./.github/actions/build
153+ id : initial-build
154+ with :
155+ platforms : ${{ matrix.platform }}
156+ variant : ${{ inputs.variant }}
157+ containerfile : ${{ inputs.containerfile }}
158+ image_name : ${{ inputs.image-name }}
159+ image_path : ${{ inputs.image-path }}
160+ image_tag : ${{ needs.generate_matrix.outputs.tag }}
161+ skip_maximize_build_space : ${{ inputs.skip-maximize-build-space }}
162+ REGISTRY : ${{ inputs.REGISTRY }}
163+ REGISTRY_USER : ${{ inputs.REGISTRY_USER }}
164+ REGISTRY_TOKEN : ${{ secrets.REGISTRY_TOKEN }}
254165
255166 - name : Setup Syft
256167 id : setup-syft
0 commit comments