Skip to content

Commit f3f0251

Browse files
committed
✨ Test image build on Dockerfile change
If the workflow is run from a PR, and the PR includes a change to the `Dockerfile`, then run image builds for all of our target platforms. The images are built but not pushed to any repository. We want to be reasonably sure that any `Dockerfile` change will not cause the image-build-and-push on PR merge workflow to break. Doing the image build here should show up most problems much earlier. For example, a npm version update in the build container could break github action `nofiles` or network access capabilities for the npm install. In future, it may be reasonable to extend this check to happen when other core build related changes are made (package-lock.json, package.json). See konveyor#1742, konveyor#1746, and konveyor#1781 for some other examples of when this check could have caught issues before a PR merge. Supports: konveyor#1883 Signed-off-by: Scott J Dickerson <[email protected]>
1 parent 4884439 commit f3f0251

File tree

2 files changed

+95
-3
lines changed

2 files changed

+95
-3
lines changed

.github/workflows/ci-Dockerfile.yml

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: CI (test image build for a PR with a Dockerfile change)
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "main"
7+
- "release-*"
8+
9+
jobs:
10+
checks:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
should-test: ${{ steps.check-dockerfile.outputs.should-test }}
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: What files changed?
19+
id: changed
20+
uses: tj-actions/changed-files@v44
21+
with:
22+
files: |
23+
Dockerfile
24+
25+
- name: Check if the `Dockerfile` has been changed in a PR
26+
id: check-dockerfile
27+
env:
28+
IS_PR: ${{ !!github.event.pull_request }}
29+
ANY_MODIFIED: ${{ steps.changed.outputs.any_modified }}
30+
run: |
31+
TEST_IMAGE_BUILD=$(
32+
if [[ $IS_PR == true ]] && [[ $ANY_MODIFIED == true ]]; then
33+
echo "true"
34+
else
35+
echo "false"
36+
fi
37+
)
38+
39+
echo "is-pr=$IS_PR" >> "$GITHUB_OUTPUT"
40+
echo "changed=${ANY_MODIFIED:-false}" >> "$GITHUB_OUTPUT"
41+
echo "should-test=$TEST_IMAGE_BUILD" >> "$GITHUB_OUTPUT"
42+
43+
- name: Summarize findings
44+
run: |
45+
cat >> "$GITHUB_STEP_SUMMARY" <<EOF
46+
## Findings
47+
PR triggered? \`${{ steps.check-dockerfile.outputs.is-pr }}\`
48+
PR includes a Dockerfile change? \`${{ steps.check-dockerfile.outputs.changed }}\`
49+
Should the image build be tested? \`${{ steps.check-dockerfile.outputs.should-test }}\`
50+
EOF
51+
52+
#
53+
# Based on:
54+
# - image-build.yaml
55+
# - konveyor/release-tools/.github/workflows/build-push-images.yaml@main
56+
#
57+
# Only test the image build, no push to quay is required.
58+
#
59+
test-image-build:
60+
runs-on: ubuntu-latest
61+
needs: checks
62+
if: ${{ needs.checks.outputs.should-test == 'true' }}
63+
64+
strategy:
65+
fail-fast: true
66+
matrix:
67+
architecture:
68+
- amd64
69+
- arm64
70+
71+
steps:
72+
- name: Checkout merge commit for PR${{ github.event.pull_request.number }}
73+
uses: actions/checkout@v4
74+
75+
- name: Setup QEMU to be able to build on platform ${{ matrix.architecture }}
76+
if: ${{ matrix.architecture != 'amd64' }}
77+
uses: docker/setup-qemu-action@master
78+
with:
79+
platforms: ${{ matrix.architecture }}
80+
81+
- name: Test build image on ${{ matrix.architecture }}
82+
id: test-build
83+
uses: redhat-actions/buildah-build@main
84+
with:
85+
image: "tackle2-ui"
86+
tags: pr${{ github.event.pull_request.number }}-${{ matrix.architecture }}
87+
extra-args: "--no-cache --rm --ulimit nofile=4096:4096"
88+
archs: ${{ matrix.architecture }}
89+
labels: ""
90+
containerfiles: "./Dockerfile"
91+
context: "."

.github/workflows/ci-repo.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ on:
1717
workflow_dispatch:
1818

1919
jobs:
20-
unit-test-lookup-image:
20+
unit-test-lookups:
2121
runs-on: ubuntu-latest
2222
outputs:
2323
builder-image: ${{ steps.grepBuilder.outputs.builder }}
24+
2425
steps:
2526
- uses: actions/checkout@v4
2627

@@ -33,10 +34,10 @@ jobs:
3334
3435
unit-test:
3536
runs-on: ubuntu-latest
36-
needs: unit-test-lookup-image
37+
needs: unit-test-lookups
3738

3839
# Use the same container as the Dockerfile's "FROM * as builder"
39-
container: ${{ needs.unit-test-lookup-image.outputs.builder-image }}
40+
container: ${{ needs.unit-test-lookups.outputs.builder-image }}
4041

4142
steps:
4243
- uses: actions/checkout@v4

0 commit comments

Comments
 (0)