forked from quarkusio/quarkus-super-heroes
-
Notifications
You must be signed in to change notification settings - Fork 0
407 lines (359 loc) · 18.3 KB
/
build-push-container-images.yml
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
name: Build and Push Container images
env:
IMAGE_BASE_NAME: "quay.io/quarkus-super-heroes"
MANDREL_IMAGE: "quay.io/quarkus/ubi-quarkus-mandrel-builder-image"
LATEST_IMAGE_TAG: "latest"
on:
workflow_run:
workflows:
- "Basic build and test"
branches:
- main
types:
- completed
workflow_dispatch:
concurrency:
group: "workflow = ${{ github.workflow }}, ref = ${{ github.event.workflow_run.head_branch || github.event.ref || github.ref }}"
cancel-in-progress: false
jobs:
build-jvm-images:
if: ((github.event_name == 'workflow_dispatch') || ((github.event_name == 'workflow_run') && ((github.event.workflow_run.event == 'push') || (github.event.workflow_run.event == 'workflow_dispatch')) && (github.event.workflow_run.conclusion == 'success'))) && ((github.repository == 'quarkusio/quarkus-super-heroes') && ((github.event.workflow_run.head_branch == 'main')))
runs-on: ubuntu-latest
strategy:
matrix:
java:
- '17'
project:
- { name: event-statistics }
- { name: rest-fights }
- { name: rest-heroes }
- { name: rest-villains }
- { name: rest-narration }
- { name: rest-narration, openai-type: azure-openai }
- { name: grpc-locations }
- { name: ui-super-heroes }
arch:
- amd64
- arm64
name: "Build JVM images (${{ matrix.arch }}-${{ matrix.project.name }}-java${{ matrix.java }}-${{ matrix.project.openai-type }})"
steps:
- name: Calculate Branch (workflow_run event)
if: github.event_name == 'workflow_run'
run: |
echo "REF=${{ github.event.workflow_run.head_commit.id }}" >> $GITHUB_ENV
echo "BRANCH=${{ github.event.workflow_run.head_branch }}" >> $GITHUB_ENV
- name: Calculate Branch (workflow_dispatch event)
if: github.event_name == 'workflow_dispatch'
run: |
echo "REF=${{ github.sha }}" >> $GITHUB_ENV
echo "BRANCH=${{ github.ref_name }}" >> $GITHUB_ENV
- name: Checkout from ${{ env.REF }}
uses: actions/checkout@v4
with:
ref: ${{ env.REF }}
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: temurin
cache: maven
- name: Create env vars
working-directory: ${{ matrix.project.name }}
run: |
echo "QUARKUS_VERSION=$(./mvnw help:evaluate -Dexpression=quarkus.platform.version -q -DforceStdout)" >> $GITHUB_ENV &&
echo "APP_VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV &&
if [[ ${{ matrix.java }} == '17' ]]; then
echo "JVM_DOCKERFILE=Dockerfile.jvm" >> "$GITHUB_ENV"
else
echo "JVM_DOCKERFILE=Dockerfile.jvm${{ matrix.java }}" >> "$GITHUB_ENV"
fi
- name: Create OpenAI env vars
if: matrix.project.openai-type
working-directory: ${{ matrix.project.name }}
run: echo "QUARKUS_PROFILE=${{ matrix.project.openai-type }}" >> $GITHUB_ENV
- name: Create CONTAINER_TAG
working-directory: .github/workflows/scripts
shell: bash
run: echo "CONTAINER_TAG=$(./compute-container-tag.sh ${{ env.APP_VERSION }} ${{ env.QUARKUS_VERSION }} "" ${{ matrix.java }} "${{ matrix.project.openai-type }}")" >> $GITHUB_ENV
- name: Set up QEMU
if: matrix.arch == 'arm64'
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ matrix.arch }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
install: true
- name: Build JVM image (${{ matrix.project.name }}-java${{ matrix.java }}-${{ matrix.arch }}-${{ matrix.project.openai-type }})
working-directory: ${{ matrix.project.name }}
run: |
./mvnw -B clean package -DskipTests \
-Dmaven.compiler.release=${{ matrix.java }} \
-Dquarkus.http.host=0.0.0.0 \
-Dquarkus.container-image.build=true \
-Dquarkus.container-image.push=false \
-Dquarkus.container-image.tag=${{ env.CONTAINER_TAG }}-${{ matrix.arch }} \
-Dquarkus.docker.dockerfile-jvm-path=src/main/docker/${{ env.JVM_DOCKERFILE }} \
-Dquarkus.docker.buildx.platform=linux/${{ matrix.arch }}
- name: Save JVM Image (${{ matrix.project.name }}-java${{ matrix.java }}-${{ matrix.arch }}-${{ matrix.project.openai-type }})
uses: ishworkh/docker-image-artifact-upload@v1
with:
image: "${{ env.IMAGE_BASE_NAME }}/${{ matrix.project.name }}:${{ env.CONTAINER_TAG }}-${{ matrix.arch }}"
build-native-images:
if: ((github.event_name == 'workflow_dispatch') || ((github.event_name == 'workflow_run') && ((github.event.workflow_run.event == 'push') || (github.event.workflow_run.event == 'workflow_dispatch')) && (github.event.workflow_run.conclusion == 'success'))) && ((github.repository == 'quarkusio/quarkus-super-heroes') && ((github.event.workflow_run.head_branch == 'main')))
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
java:
- '17'
project:
- { name: event-statistics }
- { name: rest-fights }
- { name: rest-heroes }
- { name: rest-villains }
- { name: rest-narration }
- { name: rest-narration, openai-type: azure-openai }
- { name: grpc-locations }
- { name: ui-super-heroes }
arch:
- amd64
- arm64
name: "Build Native images (${{ matrix.arch }}-${{ matrix.project.name }}-java${{ matrix.java }}-${{ matrix.project.openai-type }})"
steps:
- name: Calculate Branch (workflow_run event)
if: github.event_name == 'workflow_run'
run: |
echo "REF=${{ github.event.workflow_run.head_commit.id }}" >> $GITHUB_ENV
echo "BRANCH=${{ github.event.workflow_run.head_branch }}" >> $GITHUB_ENV
- name: Calculate Branch (workflow_dispatch event)
if: github.event_name == 'workflow_dispatch'
run: |
echo "REF=${{ github.sha }}" >> $GITHUB_ENV
echo "BRANCH=${{ github.ref_name }}" >> $GITHUB_ENV
- name: Checkout from ${{ env.REF }}
uses: actions/checkout@v4
with:
ref: ${{ env.REF }}
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: temurin
cache: maven
- name: Create env vars
working-directory: ${{ matrix.project.name }}
run: |
echo "QUARKUS_VERSION=$(./mvnw help:evaluate -Dexpression=quarkus.platform.version -q -DforceStdout)" >> $GITHUB_ENV && \
echo "APP_VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
- name: Create OpenAI env vars
if: matrix.project.openai-type
working-directory: ${{ matrix.project.name }}
run: echo "QUARKUS_PROFILE=${{ matrix.project.openai-type }}" >> $GITHUB_ENV
- name: Create CONTAINER_TAG
working-directory: .github/workflows/scripts
shell: bash
run: echo "CONTAINER_TAG=$(./compute-container-tag.sh ${{ env.APP_VERSION }} ${{ env.QUARKUS_VERSION }} "native-" ${{ matrix.java }} "${{ matrix.project.openai-type }}")" >> $GITHUB_ENV
- name: Set up QEMU
if: matrix.arch == 'arm64'
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ matrix.arch }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
install: true
- name: Build native image (${{ matrix.project.name }}-java${{ matrix.java }}-${{ matrix.arch }}-${{ matrix.project.openai-type }})
working-directory: ${{ matrix.project.name }}
run: |
./mvnw -B clean package -DskipTests -Pnative \
-Dmaven.compiler.release=${{ matrix.java }} \
-Dquarkus.http.host=0.0.0.0 \
-Dquarkus.native.container-build=true \
-Dquarkus.native.builder-image=${{ env.MANDREL_IMAGE }}:jdk-${{ matrix.java }} \
-Dquarkus.native.container-runtime-options=--platform=linux/${{ matrix.arch }} \
-Dquarkus.container-image.build=true \
-Dquarkus.container-image.push=false \
-Dquarkus.container-image.tag=${{ env.CONTAINER_TAG }}-${{ matrix.arch }} \
-Dquarkus.docker.buildx.platform=linux/${{ matrix.arch }}
- name: Save native Image (${{ matrix.project.name }}-java${{ matrix.java }}-${{ matrix.arch }}-${{ matrix.project.openai-type }})
uses: ishworkh/docker-image-artifact-upload@v1
with:
image: "${{ env.IMAGE_BASE_NAME }}/${{ matrix.project.name }}:${{ env.CONTAINER_TAG }}-${{ matrix.arch }}"
push-app-images:
if: ((github.event_name == 'workflow_dispatch') || ((github.event_name == 'workflow_run') && ((github.event.workflow_run.event == 'push') || (github.event.workflow_run.event == 'workflow_dispatch')) && (github.event.workflow_run.conclusion == 'success'))) && ((github.repository == 'quarkusio/quarkus-super-heroes') && ((github.event.workflow_run.head_branch == 'main')))
needs:
- build-jvm-images
- build-native-images
runs-on: ubuntu-latest
strategy:
matrix:
java:
- '17'
kind:
- ""
- "native-"
project:
- { name: event-statistics }
- { name: rest-fights }
- { name: rest-heroes }
- { name: rest-villains }
- { name: rest-narration }
- { name: rest-narration, openai-type: azure-openai }
- { name: grpc-locations }
- { name: ui-super-heroes }
arch:
- amd64
- arm64
name: "Push app images (${{ matrix.arch }}-${{ matrix.project.name }}-${{ matrix.kind }}java${{ matrix.java }}-${{ matrix.project.openai-type }})"
steps:
- name: Calculate Branch (workflow_run event)
if: github.event_name == 'workflow_run'
run: |
echo "REF=${{ github.event.workflow_run.head_commit.id }}" >> $GITHUB_ENV
echo "BRANCH=${{ github.event.workflow_run.head_branch }}" >> $GITHUB_ENV
- name: Calculate Branch (workflow_dispatch event)
if: github.event_name == 'workflow_dispatch'
run: |
echo "REF=${{ github.sha }}" >> $GITHUB_ENV
echo "BRANCH=${{ github.ref_name }}" >> $GITHUB_ENV
- name: Checkout from ${{ env.REF }}
uses: actions/checkout@v4
with:
ref: ${{ env.REF }}
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: temurin
cache: maven
- name: Create env vars
working-directory: ${{ matrix.project.name }}
run: |
echo "QUARKUS_VERSION=$(./mvnw help:evaluate -Dexpression=quarkus.platform.version -q -DforceStdout)" >> $GITHUB_ENV &&
echo "APP_VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
- name: Create CONTAINER_TAG
working-directory: .github/workflows/scripts
shell: bash
run: echo "CONTAINER_TAG=$(./compute-container-tag.sh ${{ env.APP_VERSION }} ${{ env.QUARKUS_VERSION }} "${{ matrix.kind }}" ${{ matrix.java }} "${{ matrix.project.openai-type }}")" >> $GITHUB_ENV
- name: Create ADDITIONAL_TAG
working-directory: .github/workflows/scripts
shell: bash
run: echo "ADDITIONAL_TAG=$(./compute-additional-tag.sh "${{ matrix.kind }}" ${{ matrix.java }} ${{ env.LATEST_IMAGE_TAG }} ${{ env.BRANCH }} "${{ matrix.project.openai-type }}")" >> $GITHUB_ENV
- name: Get saved images (${{ matrix.project.name }}:${{ env.CONTAINER_TAG }}-${{ matrix.arch }})
uses: ishworkh/docker-image-artifact-download@v1
with:
image: "${{ env.IMAGE_BASE_NAME }}/${{ matrix.project.name }}:${{ env.CONTAINER_TAG }}-${{ matrix.arch }}"
- name: Login to quay
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_REPO_USERNAME }}
password: ${{ secrets.QUAY_REPO_TOKEN }}
- name: Tag image
working-directory: ${{ matrix.project.name }}
run: "docker tag ${{ env.IMAGE_BASE_NAME }}/${{ matrix.project.name }}:${{ env.CONTAINER_TAG }}-${{ matrix.arch }} ${{ env.IMAGE_BASE_NAME }}/${{ matrix.project.name }}:${{ env.ADDITIONAL_TAG }}-${{ matrix.arch }}"
- name: Push images
working-directory: ${{ matrix.project.name }}
run: "docker push -a ${{ env.IMAGE_BASE_NAME }}/${{ matrix.project.name }}"
create-app-multiarch-manifests:
if: ((github.event_name == 'workflow_dispatch') || ((github.event_name == 'workflow_run') && ((github.event.workflow_run.event == 'push') || (github.event.workflow_run.event == 'workflow_dispatch')) && (github.event.workflow_run.conclusion == 'success'))) && ((github.repository == 'quarkusio/quarkus-super-heroes') && ((github.event.workflow_run.head_branch == 'main')))
needs: push-app-images
runs-on: ubuntu-latest
strategy:
matrix:
java:
- '17'
kind:
- ""
- "native-"
project:
- { name: event-statistics }
- { name: rest-fights }
- { name: rest-heroes }
- { name: rest-villains }
- { name: rest-narration }
- { name: rest-narration, openai-type: azure-openai }
- { name: grpc-locations }
- { name: ui-super-heroes }
name: Create app multiarch manifests (${{ matrix.project.name }}-${{ matrix.kind }}java${{ matrix.java }}-${{ matrix.project.openai-type }})
steps:
- name: Calculate Branch (workflow_run)
if: github.event_name == 'workflow_run'
run: |
echo "REF=${{ github.event.workflow_run.head_commit.id }}" >> $GITHUB_ENV
echo "BRANCH=${{ github.event.workflow_run.head_branch }}" >> $GITHUB_ENV
- name: Calculate Branch (workflow_dispatch event)
if: github.event_name == 'workflow_dispatch'
run: |
echo "REF=${{ github.sha }}" >> $GITHUB_ENV
echo "BRANCH=${{ github.ref_name }}" >> $GITHUB_ENV
- name: Checkout from ${{ env.REF }}
uses: actions/checkout@v4
with:
ref: ${{ env.REF }}
- name: Setup Java
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: temurin
cache: maven
- name: Create env vars
working-directory: ${{ matrix.project.name }}
run: |
echo "QUARKUS_VERSION=$(./mvnw help:evaluate -Dexpression=quarkus.platform.version -q -DforceStdout)" >> $GITHUB_ENV &&
echo "APP_VERSION=$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
- name: Create CONTAINER_TAG
working-directory: .github/workflows/scripts
shell: bash
run: echo "CONTAINER_TAG=$(./compute-container-tag.sh ${{ env.APP_VERSION }} ${{ env.QUARKUS_VERSION }} "${{ matrix.kind }}" ${{ matrix.java }} "${{ matrix.project.openai-type }}")" >> $GITHUB_ENV
- name: Create ADDITIONAL_TAG
working-directory: .github/workflows/scripts
shell: bash
run: echo "ADDITIONAL_TAG=$(./compute-additional-tag.sh "${{ matrix.kind }}" ${{ matrix.java }} ${{ env.LATEST_IMAGE_TAG }} ${{ env.BRANCH }} "${{ matrix.project.openai-type }}")" >> $GITHUB_ENV
- name: Login to quay
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_REPO_USERNAME }}
password: ${{ secrets.QUAY_REPO_TOKEN }}
- name: Create and push multi-arch manifests
shell: bash
run: |
docker manifest create ${{ env.IMAGE_BASE_NAME }}/${{ matrix.project.name }}:${{ env.CONTAINER_TAG }} \
-a ${{ env.IMAGE_BASE_NAME }}/${{ matrix.project.name }}:${{ env.CONTAINER_TAG }}-amd64 \
-a ${{ env.IMAGE_BASE_NAME }}/${{ matrix.project.name }}:${{ env.CONTAINER_TAG }}-arm64
docker manifest push ${{ env.IMAGE_BASE_NAME }}/${{ matrix.project.name }}:${{ env.CONTAINER_TAG }}
docker manifest create ${{ env.IMAGE_BASE_NAME }}/${{ matrix.project.name }}:${{ env.ADDITIONAL_TAG }} \
-a ${{ env.IMAGE_BASE_NAME }}/${{ matrix.project.name }}:${{ env.ADDITIONAL_TAG }}-amd64 \
-a ${{ env.IMAGE_BASE_NAME }}/${{ matrix.project.name }}:${{ env.ADDITIONAL_TAG }}-arm64
docker manifest push ${{ env.IMAGE_BASE_NAME }}/${{ matrix.project.name }}:${{ env.ADDITIONAL_TAG }}
deploy-resources-workflow-run:
if: ((github.event_name == 'workflow_run') && ((github.event.workflow_run.event == 'push') || (github.event.workflow_run.event == 'workflow_dispatch')) && (github.event.workflow_run.conclusion == 'success') && (github.repository == 'quarkusio/quarkus-super-heroes')) && ((github.event.workflow_run.head_branch == 'main'))
needs: create-app-multiarch-manifests
uses: quarkusio/quarkus-super-heroes/.github/workflows/create-deploy-resources.yml@main
secrets: inherit
with:
commit_id: ${{ github.event.workflow_run.head_commit.id }}
branch: ${{ github.event.workflow_run.head_branch }}
deploy-resources-workflow-dispatch:
if: ((github.event_name == 'workflow_dispatch') && (github.repository == 'quarkusio/quarkus-super-heroes')) && ((github.ref_name == 'main'))
needs: create-app-multiarch-manifests
uses: quarkusio/quarkus-super-heroes/.github/workflows/create-deploy-resources.yml@main
secrets: inherit
with:
commit_id: ${{ github.sha }}
branch: ${{ github.ref_name }}
cleanup-artifacts:
needs:
- deploy-resources-workflow-run
- deploy-resources-workflow-dispatch
if: always()
runs-on: ubuntu-latest
steps:
- name: Delete artifacts
env:
WEBHOOK_SECRET: ${{ secrets.WEBHOOK_SECRET }}
run: |
echo "::add-mask::$WEBHOOK_SECRET"
curl --verbose --fail --show-error --location --request POST "https://api.github.com/repos/$GITHUB_REPOSITORY/dispatches" --header "Authorization: token $WEBHOOK_SECRET" --header 'Content-Type: application/json' --header 'Accept: application/vnd.github.everest-preview+json' --data-raw "{ \"event_type\": \"delete_all_artifacts\", \"client_payload\": {\"parent_runid\": \"$GITHUB_RUN_ID\", \"parent_repo\": \"$GITHUB_REPOSITORY\"} }"