Skip to content

Commit a71e964

Browse files
authored
ci: print the images built in PR for easier testing (#228)
1 parent edfffdc commit a71e964

File tree

3 files changed

+92
-58
lines changed

3 files changed

+92
-58
lines changed

.github/actions/build-and-push-image/action.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ inputs:
44
image-flavor:
55
description: A flavor used to tag the apollo-ci image.
66
required: true
7+
outputs:
8+
image-tag:
9+
description: The full image tag that was built and pushed
10+
value: ${{ steps.build-and-push.outputs.image-tag }}
711
runs:
812
using: composite
913
steps:
1014
- name: Build and push image
15+
id: build-and-push
1116
run: |
1217
.github/actions/build-and-push-image/build-and-push-image.sh \
1318
"${{ inputs.image-flavor }}"

.github/actions/build-and-push-image/build-and-push-image.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ set -euo pipefail
55
build_and_push_image() {
66
local image_flavor="$1"
77

8-
# Login may be required for pulling the base image for building (if used) and to avoid rate limits.
98
docker login -u "$QUAY_RHACS_ENG_RW_USERNAME" --password-stdin <<<"$QUAY_RHACS_ENG_RW_PASSWORD" quay.io
109

11-
TAG="$(scripts/get_tag.sh "$image_flavor")"
10+
TAG="$(scripts/get_tag.sh "${image_flavor}")"
1211
IMAGE="quay.io/rhacs-eng/apollo-ci:${TAG}"
1312

14-
make "$image_flavor"-image
13+
make "${image_flavor}-image"
1514

1615
retry 5 true docker push "${IMAGE}"
1716

17+
echo "image-tag=${IMAGE}" >> "${GITHUB_OUTPUT}"
18+
19+
# TODO: move all usages of apollo-ci images to quay.io/rhacs-eng/apollo-ci or quay.io/stackrox-io/apollo-ci.
1820
docker login -u "$QUAY_STACKROX_IO_RW_USERNAME" --password-stdin <<<"$QUAY_STACKROX_IO_RW_PASSWORD" quay.io
1921
docker tag "${IMAGE}" "quay.io/stackrox-io/apollo-ci:${TAG}"
2022

.github/workflows/build.yaml

Lines changed: 82 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -17,86 +17,72 @@ env:
1717

1818
jobs:
1919

20-
build-and-push-stackrox-build:
20+
build-and-push-builder-images:
2121
runs-on: ubuntu-latest
22+
strategy:
23+
matrix:
24+
image-flavor:
25+
- scanner-build
26+
- stackrox-build
27+
- stackrox-ui-test
28+
- jenkins-plugin
29+
fail-fast: false
2230
steps:
2331
- name: Checkout
2432
uses: actions/checkout@v3
2533
with:
2634
fetch-depth: 0
2735
ref: ${{ github.event.pull_request.head.sha }}
2836
- uses: ./.github/actions/build-and-push-image
37+
id: build-and-push-image
2938
with:
30-
image-flavor: "stackrox-build"
31-
32-
build-and-push-stackrox-test:
33-
runs-on: ubuntu-latest
34-
needs:
35-
- build-and-push-stackrox-build
36-
steps:
37-
- name: Checkout
38-
uses: actions/checkout@v3
39-
with:
40-
fetch-depth: 0
41-
ref: ${{ github.event.pull_request.head.sha }}
42-
- uses: ./.github/actions/build-and-push-image
43-
with:
44-
image-flavor: "stackrox-test"
45-
46-
build-and-push-stackrox-ui-test:
47-
runs-on: ubuntu-latest
48-
steps:
49-
- name: Checkout
50-
uses: actions/checkout@v3
51-
with:
52-
fetch-depth: 0
53-
ref: ${{ github.event.pull_request.head.sha }}
54-
- uses: ./.github/actions/build-and-push-image
55-
with:
56-
image-flavor: "stackrox-ui-test"
57-
58-
build-and-push-scanner-build:
59-
runs-on: ubuntu-latest
60-
steps:
61-
- name: Checkout
62-
uses: actions/checkout@v3
63-
with:
64-
fetch-depth: 0
65-
ref: ${{ github.event.pull_request.head.sha }}
66-
- uses: ./.github/actions/build-and-push-image
39+
image-flavor: "${{ matrix.image-flavor }}"
40+
- name: Save image info
41+
run: |
42+
mkdir -p image-info
43+
echo "${{ steps.build-and-push-image.outputs.image-tag }}" > "image-info/${{ matrix.image-flavor }}.txt"
44+
- name: Upload image info
45+
uses: actions/upload-artifact@v4
6746
with:
68-
image-flavor: "scanner-build"
47+
name: image-info-${{ matrix.image-flavor }}
48+
path: image-info/${{ matrix.image-flavor }}.txt
49+
retention-days: 1
6950

70-
build-and-push-scanner-test:
51+
build-and-push-test-images:
52+
needs: build-and-push-builder-images
7153
runs-on: ubuntu-latest
72-
needs:
73-
- build-and-push-scanner-build
54+
strategy:
55+
matrix:
56+
image-flavor:
57+
- stackrox-test
58+
- scanner-test
59+
fail-fast: false
7460
steps:
7561
- name: Checkout
7662
uses: actions/checkout@v3
7763
with:
7864
fetch-depth: 0
7965
ref: ${{ github.event.pull_request.head.sha }}
8066
- uses: ./.github/actions/build-and-push-image
67+
id: build-and-push-image
8168
with:
82-
image-flavor: "scanner-test"
83-
84-
build-and-push-jenkins-plugin:
85-
runs-on: ubuntu-latest
86-
steps:
87-
- name: Checkout
88-
uses: actions/checkout@v3
89-
with:
90-
fetch-depth: 0
91-
ref: ${{ github.event.pull_request.head.sha }}
92-
- uses: ./.github/actions/build-and-push-image
69+
image-flavor: "${{ matrix.image-flavor }}"
70+
- name: Save image info
71+
run: |
72+
mkdir -p image-info
73+
echo "${{ steps.build-and-push-image.outputs.image-tag }}" > "image-info/${{ matrix.image-flavor }}.txt"
74+
- name: Upload image info
75+
uses: actions/upload-artifact@v4
9376
with:
94-
image-flavor: "jenkins-plugin"
77+
name: image-info-${{ matrix.image-flavor }}
78+
path: image-info/${{ matrix.image-flavor }}.txt
79+
retention-days: 1
9580

9681
test-cci-export:
9782
runs-on: ubuntu-latest
9883
needs:
99-
- build-and-push-stackrox-test
84+
- build-and-push-builder-images
85+
- build-and-push-test-images
10086
steps:
10187
- name: Checkout
10288
uses: actions/checkout@v3
@@ -107,3 +93,44 @@ jobs:
10793
run: |
10894
docker login -u "$QUAY_RHACS_ENG_RW_USERNAME" --password-stdin <<<"$QUAY_RHACS_ENG_RW_PASSWORD" quay.io
10995
make test-cci-export
96+
97+
comment-build-images:
98+
runs-on: ubuntu-latest
99+
needs:
100+
- build-and-push-builder-images
101+
- build-and-push-test-images
102+
steps:
103+
- name: Download all image info artifacts
104+
uses: actions/download-artifact@v4
105+
with:
106+
pattern: image-info-*
107+
merge-multiple: true
108+
path: image-info
109+
- name: Build comment message
110+
id: build-message
111+
run: |
112+
echo "message<<EOF" >> $GITHUB_OUTPUT
113+
echo "## Build Images" >> $GITHUB_OUTPUT
114+
echo "" >> $GITHUB_OUTPUT
115+
echo "| Image Flavor | Image Tag |" >> $GITHUB_OUTPUT
116+
echo "|--------------|-----------|" >> $GITHUB_OUTPUT
117+
for file in image-info/*.txt; do
118+
if [ -f "$file" ]; then
119+
flavor=$(basename "$file" .txt)
120+
image=$(cat "$file")
121+
echo "| ${flavor} | \`${image}\` |" >> $GITHUB_OUTPUT
122+
fi
123+
done
124+
echo "EOF" >> $GITHUB_OUTPUT
125+
- name: Comment PR with build images
126+
if: ${{ github.event_name == 'pull_request' }}
127+
uses: thollander/actions-comment-pull-request@v3
128+
with:
129+
message: ${{ steps.build-message.outputs.message }}
130+
comment-tag: build-images
131+
- name: Print the comment message to step summary
132+
run: |
133+
# Need to cat here, because echo would interpret the backticks in the message as commands.
134+
cat >> $GITHUB_STEP_SUMMARY << 'EOF'
135+
${{ steps.build-message.outputs.message }}
136+
EOF

0 commit comments

Comments
 (0)