This repository has been archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
192 lines (190 loc) · 6.28 KB
/
generate-docker-image.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
name: 🧐 Generate Docker image 🎁
on:
pull_request:
branches:
- 'main'
push:
tags:
- 'v*'
branches:
- 'main'
workflow_dispatch:
schedule:
- cron: '12 0 * * *'
jobs:
build:
name: 👩🏼🏭 Build Native Quarkus 👩🏼🏭
runs-on: ubuntu-latest
steps:
- name: 🪅 Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: 🗄️ Checkout Source Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 🥸 Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17
check-latest: true
- name: 🔥 Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: 🤳 Build Native Quarkus
run: mvn -B install -Pnative -Dquarkus.native.native-image-xmx=5g
- name: 📤 Login to DockerHub
uses: docker/login-action@v2
env:
username: ${{ secrets.DOCKER_USERNAME }}
if: ${{env.username != ''}}
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: 📥 Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: kaotoio/backend
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: 🗃️ Build to test
uses: docker/build-push-action@v4
if: ${{ github.event_name == 'pull_request' }}
with:
context: "api"
file: './api/src/main/docker/Dockerfile.native'
platforms: linux/amd64
load: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: 🏃♀️ Run built image
if: ${{ github.event_name == 'pull_request' }}
run: |
docker images
docker run -d --rm -p 8081:8081 --name kaoto-backend kaotoio/backend:pr-${{ github.event.pull_request.number }}
- name: Check the deployed service URL
uses: jtalk/url-health-check-action@v3
if: ${{ github.event_name == 'pull_request' }}
with:
url: 'http://localhost:8081/q/health'
max-attempts: 5
retry-delay: 1s
- name: 🍱 Build and push
uses: docker/build-push-action@v4
if: ${{ github.event_name != 'pull_request' }}
with:
context: "api"
file: './api/src/main/docker/Dockerfile.native'
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-for-mac:
name: 👩🏼🏭 Build Native Quarkus for MacOS 👩🏼🏭
runs-on: macos-latest
steps:
- name: 🗄️ Checkout Source Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 🥸 Set up GraalVM
uses: graalvm/setup-graalvm@v1
with:
java-version: '17.0.7'
distribution: 'graalvm-community'
components: 'native-image'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: 🔥 Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-macos-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2-macos
- name: 🤳 Build Native Quarkus
run: mvn install -DskipTests -Pnative
- name: 📩 Save MacOS native build
uses: actions/upload-artifact@v3
with:
name: macos-native-build
path: api/target/*-runner
retention-days: 1
docker-for-mac:
name: 👩🏼🏭 Build Docker Image for MacOS 👩🏼🏭
runs-on: ubuntu-latest
needs: [build-for-mac, build]
steps:
- name: 🦤 Set up QEMU
uses: docker/setup-qemu-action@v2
- name: 🪅 Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: 🗄️ Checkout Source Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 📨 Retrieve saved MacOS native build
uses: actions/download-artifact@v3
with:
name: macos-native-build
path: api/target/kaoto-runner
- name: 📤 Login to DockerHub
uses: docker/login-action@v2
env:
username: ${{ secrets.DOCKER_USERNAME }}
if: ${{env.username != ''}}
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: 📥 Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: kaotoio/backend
flavor: |
latest=auto
prefix=
suffix=-arm64,onlatest=true
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: 🍱 Build and push
uses: docker/build-push-action@v4
if: ${{ github.event_name != 'pull_request' }}
with:
context: "api"
file: './api/src/main/docker/Dockerfile.native'
platforms: linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
standalone:
uses: ./.github/workflows/standalone-build-and-push.yml
needs:
- build
- build-for-mac
- docker-for-mac
if: ${{ github.event_name != 'pull_request' }}
with:
tag: "${{ github.ref_name }}-${{ github.sha }}"
alias: "latest"
frontend-version: main
backend-version: main
secrets:
docker-username: ${{ secrets.DOCKER_USERNAME }}
docker-password: ${{ secrets.DOCKER_PASSWORD }}
quay-username: ${{ secrets.QUAY_USERNAME }}
quay-password: ${{ secrets.QUAY_PASSWORD }}