-
Notifications
You must be signed in to change notification settings - Fork 56
224 lines (214 loc) · 8.04 KB
/
build.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
name: Build Images
on:
push:
branches:
- master
workflow_dispatch:
inputs:
push:
description: 'Push images to quay?'
default: 'false'
required: false
tag:
description: 'Tag to assign to built images'
default: 'manual'
required: false
diff_branch:
description: 'Upstream branch for determining changes'
default: 'master'
required: false
run_all:
description: 'Run all builds regardless of changes?'
default: 'false'
required: false
pull_request:
types: [synchronize, labeled]
jobs:
create_matrix:
runs-on: ubuntu-latest
name: Create Build Matrix
outputs:
build_matrix: ${{ steps.set-build-matrix.outputs.matrix }}
manifest_matrix: ${{ steps.set-manifest-matrix.outputs.matrix }}
env:
changed_only: ''
version_tag: '${{ github.sha }}'
if: >-
(
github.event_name != 'pull_request' || (
github.event_name == 'pull_request' && (
contains(github.event.pull_request.labels.*.name, 'ok to test') ||
github.event.label.name == 'ok to test'
)
)
)
steps:
- uses: actions/checkout@v2
- name: Setup Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Echo manual trigger params
if: github.event_name == 'workflow_dispatch'
run: echo "${{ toJSON(github.event.inputs) }}"
- name: Set upstream branch
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]
then
echo UPSTREAM_BRANCH=${{ github.event.inputs.diff_branch }} >> $GITHUB_ENV
else
echo UPSTREAM_BRANCH=master >> $GITHUB_ENV
fi
- name: Enable changed-only parameter for matrix build as appropriate
if: >-
(
(github.event_name == 'pull_request') ||
(github.event_name == 'push' && !(endsWith(github.ref, 'master'))) ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.run_all == 'false')
)
run: echo changed_only='--changed-only' >> $GITHUB_ENV
- name: Set version tag to latest if on master branch
if: github.event_name == 'push' && endsWith(github.ref, 'master')
run: >-
echo version_tag='latest' >> $GITHUB_ENV
- name: Set version tag to given input if manually triggered
if: github.event_name == 'workflow_dispatch'
run: >-
echo version_tag='${{ github.event.inputs.tag }}' >> $GITHUB_ENV
- name: Build job matrices
run: >-
echo matrix=`python ci/build_matrix.py --upstream ${{ env.UPSTREAM_BRANCH }}
--manifest ${{ env.changed_only }} ${{ env.version_tag }}` >> $GITHUB_ENV
- name: Set build matrix
id: set-build-matrix
run: |
export build_matrix=`echo '${{ env.matrix }}' | jq -c '.build'`
echo "::set-output name=matrix::$build_matrix"
- name: Echo build matrix variable
run: |
cat << EOF
${{ steps.set-build-matrix.outputs.matrix }}
EOF
- name: Sanity check by parsing build matrix using fromJSON
run: echo ${{ fromJSON(steps.set-build-matrix.outputs.matrix) }}
- name: Set manifest matrix
id: set-manifest-matrix
run: |
export manifest_matrix=`echo '${{ env.matrix }}' | jq -c '.manifest'`
echo "::set-output name=matrix::$manifest_matrix"
- name: Echo manifest matrix variable
run: |
cat << EOF
${{ steps.set-manifest-matrix.outputs.matrix }}
EOF
- name: Sanity check by parsing manifest matrix using fromJSON
run: echo ${{ fromJSON(steps.set-manifest-matrix.outputs.matrix) }}
build_push:
needs: create_matrix
runs-on: ubuntu-20.04
strategy:
matrix: ${{ fromJSON(needs.create_matrix.outputs.build_matrix) }}
fail-fast: false
name: Build ${{ matrix.benchmark }} on ${{ matrix.arch }}
steps:
- uses: actions/checkout@v2
- name: Echo Matrix Permutation
run: |
cat << EOF
${{ toJSON(matrix) }}
EOF
- name: Set quay organization
run: |
export org_secret="${{ secrets.QUAY_ORG }}"
export org=${org_secret:-cloud-bulldozer}
echo "Using organization: $org"
echo "quay_org=$org" >> $GITHUB_ENV
- name: Update apt cache
run: sudo apt update
- name: Install podman and qemu-user-static
run: sudo apt install -y podman qemu-user-static
- name: Build ${{ matrix.containerfile }}
id: build-image
uses: redhat-actions/buildah-build@v2
with:
arch: ${{ matrix.arch }}
image: ${{ matrix.image_name }}
tags: ${{ matrix.tags }}
dockerfiles: ${{ matrix.dockerfile }}
- name: Push ${{ matrix.dockerfile }}
id: push-image
if: >-
(github.event_name == 'push' && endsWith(github.ref, 'master')) ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.push == 'true')
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ steps.build-image.outputs.image }}
tags: ${{ steps.build-image.outputs.tags }}
registry: quay.io/${{ env.quay_org }}
username: ${{ secrets.QUAY_USER }}
password: ${{ secrets.QUAY_TOKEN }}
- name: Print image URL
if: steps.push-image.outcome != 'skipped'
run: echo "Image pushed to ${{ steps.push-image.outputs.registry-paths }}"
update_manifest:
needs:
- create_matrix
- build_push
if: >-
always() && !cancelled() && (
(github.event_name == 'push' && endsWith(github.ref, 'master')) ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.push == 'true')
)
runs-on: ubuntu-20.04
strategy:
matrix: ${{ fromJSON(needs.create_matrix.outputs.manifest_matrix) }}
fail-fast: false
name: Push Manifest ${{ matrix.image_name }}:${{ matrix.tag }}
steps:
- uses: actions/checkout@v2
- name: Echo Matrix Permutation
run: |
cat << EOF
${{ toJSON(matrix) }}
EOF
- name: Set quay organization
run: |
export org_secret="${{ secrets.QUAY_ORG }}"
export org=${org_secret:-cloud-bulldozer}
echo "Using organization: $org"
echo "quay_org=$org" >> $GITHUB_ENV
- name: Update apt cache
run: sudo apt update
- name: Install podman and qemu-user-static
run: sudo apt install -y podman qemu-user-static
- name: Login to quay
run: >-
podman login quay.io --username ${{ secrets.QUAY_USER }}
--password ${{ secrets.QUAY_TOKEN }}
- name: Create manifest
run: |
manifest="quay.io/${{ env.quay_org }}/${{ matrix.image_name }}:${{ matrix.tag }}"
echo "Updating manifest ${manifest} ..."
podman manifest create ${manifest}
for suffix in ${{ matrix.tag_suffixes }}
do
echo "Adding ${manifest}${suffix} to the manifest ..."
if podman manifest add ${manifest} ${manifest}${suffix}
then
echo "Image successfully added to the manifest"
else
echo "Image ${manifest}${suffix} couldn't be found, not adding to manifest"
echo "Did the build succeed?"
fi
done
manifest_json=`podman manifest inspect ${manifest}`
echo "Manifest details: "
echo $manifest_json
if echo $manifest_json | jq .manifests -e
then
echo "Pushing manifest to quay ..."
podman manifest push ${manifest} ${manifest}
else
echo "Got an empty manifest, not pushing to quay."
fi
echo "Done!"