-
Notifications
You must be signed in to change notification settings - Fork 5
419 lines (379 loc) · 18.9 KB
/
build-custom-docker-images.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
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
408
409
410
411
412
413
414
415
416
417
418
419
name: Build and push custom Docker images
on:
workflow_dispatch:
inputs:
repository-owner:
type: string
required: true
description: The owner of the VMaNGOS code repository to use
default: vmangos
repository-name:
type: string
required: true
description: The name of the VMaNGOS code repository to use
default: core
revision:
type: string
required: true
description: The VMaNGOS code repository revision to use
default: development
client-version:
type: number
required: true
description: The client version for which to build VMaNGOS
default: 5875
world-db-repository-owner:
type: string
required: true
description: The owner of the VMaNGOS world database repository to use
default: brotalnia
world-db-repository-name:
type: string
required: true
description: The name of the VMaNGOS world database repository to use
default: database
world-db-dump-name:
type: string
required: true
description: The name of the VMaNGOS world database dump to use
default: world_full_14_june_2021
patches-repository-url:
type: string
required: false
description: (Optional) A URL to a repository that contains patches to apply to the VMaNGOS code (patches have to end in `.patch` and be located in the root of the repository)
custom-name:
type: string
required: false
description: (Optional) A custom name to use as part of the image tags (when provided, this overrides the default `{ owner }-{ repository }-{ revision }` naming scheme)
architectures:
type: choice
required: true
description: Which architectures should images be built for?
options:
- "Both x86_64 and aarch64"
- "x86_64 only"
- "aarch64 only"
default: "Both x86_64 and aarch64"
env:
REGISTRY: ghcr.io
IMAGE_NAME_SERVER: ${{ github.repository_owner }}/vmangos-server-custom
IMAGE_NAME_DATABASE: ${{ github.repository_owner }}/vmangos-database-custom
OCI_ANNOTATION_AUTHORS: ${{ vars.OCI_ANNOTATION_AUTHORS || github.repository_owner }}
OCI_ANNOTATION_URL: https://github.com/${{ github.repository }}
OCI_ANNOTATION_DOCUMENTATION: https://github.com/${{ github.repository }}/blob/master/README.md
OCI_ANNOTATION_SOURCE: https://github.com/${{ github.repository }}
OCI_ANNOTATION_VENDOR: ${{ vars.OCI_ANNOTATION_VENDOR || github.repository_owner }}
OCI_ANNOTATION_LICENSES: GPL-2.0
OCI_ANNOTATION_SERVER_TITLE: vmangos-deploy - Custom VMaNGOS server image
OCI_ANNOTATION_SERVER_DESCRIPTION: VMaNGOS is a server emulator supporting versions 1.6.1 to 1.12.1.
OCI_ANNOTATION_SERVER_BASE_NAME: ubuntu:24.04
OCI_ANNOTATION_DATABASE_TITLE: vmangos-deploy - Custom VMaNGOS database image
OCI_ANNOTATION_DATABASE_DESCRIPTION: Database for the VMaNGOS server emulator.
OCI_ANNOTATION_DATABASE_BASE_NAME: mariadb:11.4
jobs:
setup:
name: Setup
runs-on: ubuntu-24.04
steps:
# If the original MariaDB entrypoint script changes, we can't guarantee
# that our custom version (which relies on functions defined in the
# original) will still work, so we fail the workflow run at this point.
- name: Check if MariaDB entrypoint script has been updated
id: mariadb-entrypoint-check
run: |
known_entrypoint=https://raw.githubusercontent.com/MariaDB/mariadb-docker/64252135052f269ed2bb57134ad73537e93b7ab6/11.4/docker-entrypoint.sh
latest_entrypoint=https://raw.githubusercontent.com/MariaDB/mariadb-docker/master/11.4/docker-entrypoint.sh
curl -o known-entrypoint.sh $known_entrypoint
curl -o latest-entrypoint.sh $latest_entrypoint
diff known-entrypoint.sh latest-entrypoint.sh
build-and-push-server-images:
name: Build and push server images
needs: setup
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
if: inputs.architectures == 'Both x86_64 and aarch64' || inputs.architectures == 'aarch64 only'
uses: docker/setup-qemu-action@v3
# Work around QEMU 7.x compilation issues by explicitly using 8.x,
# which is not yet the default for the action.
# See https://github.com/tonistiigi/binfmt/issues/215
with:
image: tonistiigi/binfmt:qemu-v8.1.5
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate tags
uses: actions/github-script@v7
id: generate-tags
env:
IMAGE: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_SERVER }}
REPOSITORY_OWNER: ${{ inputs.repository-owner }}
REPOSITORY_NAME: ${{ inputs.repository-name }}
REVISION: ${{ inputs.revision }}
CLIENT_VERSION: ${{ inputs.client-version }}
CUSTOM_NAME: ${{ inputs.custom-name }}
with:
result-encoding: string
script: |
const tags = []
if (process.env.CUSTOM_NAME.trim() !== '') {
tags.push(`${process.env.IMAGE}:${process.env.CUSTOM_NAME}-${process.env.CLIENT_VERSION}`)
return tags.join(',')
}
tags.push(`${process.env.IMAGE}:${process.env.REPOSITORY_OWNER}-${process.env.REPOSITORY_NAME}-${process.env.REVISION}-${process.env.CLIENT_VERSION}`)
return tags.join(',')
- name: Generate timestamp
id: generate-timestamp
run: echo "timestamp=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_OUTPUT
# See https://github.com/opencontainers/image-spec/blob/main/annotations.md
- name: Generate OCI annotations
uses: actions/github-script@v7
id: generate-annotations
env:
IMAGE: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_SERVER }}
REPOSITORY_OWNER: ${{ inputs.repository-owner }}
REPOSITORY_NAME: ${{ inputs.repository-name }}
REVISION: ${{ inputs.revision }}
CLIENT_VERSION: ${{ inputs.client-version }}
CUSTOM_NAME: ${{ inputs.custom-name }}
MULTI_ARCH_BUILD: ${{ inputs.architectures == 'Both x86_64 and aarch64' }}
TIMESTAMP: ${{ steps.generate-timestamp.outputs.timestamp }}
with:
result-encoding: string
script: |
const refName = process.env.CUSTOM_NAME.trim() !== ''
? `${process.env.IMAGE}:${process.env.CUSTOM_NAME}-${process.env.CLIENT_VERSION}`
: `${process.env.IMAGE}:${process.env.REPOSITORY_OWNER}-${process.env.REPOSITORY_NAME}-${process.env.REVISION}-${process.env.CLIENT_VERSION}`
const annotations = [
{ key: 'created', value: process.env.TIMESTAMP },
{ key: 'authors', envKey: 'OCI_ANNOTATION_AUTHORS' },
{ key: 'url', envKey: 'OCI_ANNOTATION_URL' },
{ key: 'documentation', envKey: 'OCI_ANNOTATION_DOCUMENTATION' },
{ key: 'source', envKey: 'OCI_ANNOTATION_SOURCE' },
{ key: 'vendor', envKey: 'OCI_ANNOTATION_VENDOR' },
{ key: 'licenses', envKey: 'OCI_ANNOTATION_LICENSES' },
{ key: 'ref.name', value: refName },
{ key: 'title', envKey: 'OCI_ANNOTATION_SERVER_TITLE' },
{ key: 'description', envKey: 'OCI_ANNOTATION_SERVER_DESCRIPTION' },
{ key: 'base.name', envKey: 'OCI_ANNOTATION_SERVER_BASE_NAME' },
].map(({ key, value, envKey }) => {
const resolvedValue = value ?? process.env[envKey] ?? ''
const prefixes = ['manifest:']
if (process.env.MULTI_ARCH_BUILD === 'true') prefixes.push('index:')
return prefixes.map(prefix => `${prefix}org.opencontainers.image.${key}=${resolvedValue}`)
})
.flat()
.join('\n')
return annotations
# We also add the generated OCI metadata as labels because the GitHub
# Container registry does not correctly pick up the OCI annotations in
# some cases and prefers to pull displayed data from the image labels
# instead (which then results in data from the base images being shown if
# we do not provide values for the respective labels ourselves).
- name: Generate OCI labels
uses: actions/github-script@v7
id: generate-labels
env:
IMAGE: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_SERVER }}
REPOSITORY_OWNER: ${{ inputs.repository-owner }}
REPOSITORY_NAME: ${{ inputs.repository-name }}
REVISION: ${{ inputs.revision }}
CLIENT_VERSION: ${{ inputs.client-version }}
CUSTOM_NAME: ${{ inputs.custom-name }}
TIMESTAMP: ${{ steps.generate-timestamp.outputs.timestamp }}
with:
result-encoding: string
script: |
const refName = process.env.CUSTOM_NAME.trim() !== ''
? `${process.env.IMAGE}:${process.env.CUSTOM_NAME}-${process.env.CLIENT_VERSION}`
: `${process.env.IMAGE}:${process.env.REPOSITORY_OWNER}-${process.env.REPOSITORY_NAME}-${process.env.REVISION}-${process.env.CLIENT_VERSION}`
const labels = [
{ key: 'created', value: process.env.TIMESTAMP },
{ key: 'authors', envKey: 'OCI_ANNOTATION_AUTHORS' },
{ key: 'url', envKey: 'OCI_ANNOTATION_URL' },
{ key: 'documentation', envKey: 'OCI_ANNOTATION_DOCUMENTATION' },
{ key: 'source', envKey: 'OCI_ANNOTATION_SOURCE' },
{ key: 'vendor', envKey: 'OCI_ANNOTATION_VENDOR' },
{ key: 'licenses', envKey: 'OCI_ANNOTATION_LICENSES' },
{ key: 'ref.name', value: refName },
{ key: 'title', envKey: 'OCI_ANNOTATION_SERVER_TITLE' },
{ key: 'description', envKey: 'OCI_ANNOTATION_SERVER_DESCRIPTION' },
{ key: 'base.name', envKey: 'OCI_ANNOTATION_SERVER_BASE_NAME' },
].map(({ key, value, envKey }) => {
const resolvedValue = value ?? process.env[envKey] ?? ''
return `org.opencontainers.image.${key}=${resolvedValue}`
})
.join('\n')
return labels
- name: Build and push images
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ inputs.architectures == 'Both x86_64 and aarch64' && 'linux/amd64, linux/arm64' || inputs.architectures == 'aarch64 only' && 'linux/arm64' || 'linux/amd64' }}
file: ./docker/server/Dockerfile
push: true
provenance: false
build-args: |
VMANGOS_REPOSITORY_OWNER=${{ inputs.repository-owner }}
VMANGOS_REPOSITORY_NAME=${{ inputs.repository-name }}
VMANGOS_REVISION=${{ inputs.revision }}
VMANGOS_CLIENT_VERSION=${{ inputs.client-version }}
VMANGOS_PATCHES_REPOSITORY_URL=${{ inputs.patches-repository-url }}
tags: ${{ steps.generate-tags.outputs.result }}
annotations: ${{ steps.generate-annotations.outputs.result }}
labels: ${{ steps.generate-labels.outputs.result }}
# Since the database image builds only take a few minutes (and therefore
# always complete before the server image builds), we need to build after the
# server images; otherwise, we would push new database images without knowing
# if the server image builds will succeed (and if there is, e.g., a
# compilation error due to a bug upstream we would end up with a version
# mismatch between the latest database images and the latest server images).
build-and-push-database-images:
name: Build and push database images
needs: [setup, build-and-push-server-images]
runs-on: ubuntu-24.04
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
if: inputs.architectures == 'Both x86_64 and aarch64' || inputs.architectures == 'aarch64 only'
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate tags
uses: actions/github-script@v7
id: generate-tags
env:
IMAGE: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_DATABASE }}
REPOSITORY_OWNER: ${{ inputs.repository-owner }}
REPOSITORY_NAME: ${{ inputs.repository-name }}
REVISION: ${{ inputs.revision }}
CUSTOM_NAME: ${{ inputs.custom-name }}
with:
result-encoding: string
script: |
const tags = []
if (process.env.CUSTOM_NAME.trim() !== '') {
tags.push(`${process.env.IMAGE}:${process.env.CUSTOM_NAME}`)
return tags.join(',')
}
tags.push(`${process.env.IMAGE}:${process.env.REPOSITORY_OWNER}-${process.env.REPOSITORY_NAME}-${process.env.REVISION}`)
return tags.join(',')
- name: Generate timestamp
id: generate-timestamp
run: echo "timestamp=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_OUTPUT
# See https://github.com/opencontainers/image-spec/blob/main/annotations.md
- name: Generate OCI annotations
uses: actions/github-script@v7
id: generate-annotations
env:
IMAGE: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_DATABASE }}
REPOSITORY_OWNER: ${{ inputs.repository-owner }}
REPOSITORY_NAME: ${{ inputs.repository-name }}
REVISION: ${{ inputs.revision }}
CUSTOM_NAME: ${{ inputs.custom-name }}
MULTI_ARCH_BUILD: ${{ inputs.architectures == 'Both x86_64 and aarch64' }}
TIMESTAMP: ${{ steps.generate-timestamp.outputs.timestamp }}
with:
result-encoding: string
script: |
const refName = process.env.CUSTOM_NAME.trim() !== ''
? `${process.env.IMAGE}:${process.env.CUSTOM_NAME}`
: `${process.env.IMAGE}:${process.env.REPOSITORY_OWNER}-${process.env.REPOSITORY_NAME}-${process.env.REVISION}`
const annotations = [
{ key: 'created', value: process.env.TIMESTAMP },
{ key: 'authors', envKey: 'OCI_ANNOTATION_AUTHORS' },
{ key: 'url', envKey: 'OCI_ANNOTATION_URL' },
{ key: 'documentation', envKey: 'OCI_ANNOTATION_DOCUMENTATION' },
{ key: 'source', envKey: 'OCI_ANNOTATION_SOURCE' },
{ key: 'vendor', envKey: 'OCI_ANNOTATION_VENDOR' },
{ key: 'licenses', envKey: 'OCI_ANNOTATION_LICENSES' },
{ key: 'ref.name', value: refName },
{ key: 'title', envKey: 'OCI_ANNOTATION_DATABASE_TITLE' },
{ key: 'description', envKey: 'OCI_ANNOTATION_DATABASE_DESCRIPTION' },
{ key: 'base.name', envKey: 'OCI_ANNOTATION_DATABASE_BASE_NAME' },
].map(({ key, value, envKey }) => {
const resolvedValue = value ?? process.env[envKey] ?? ''
const prefixes = ['manifest:']
if (process.env.MULTI_ARCH_BUILD === 'true') prefixes.push('index:')
return prefixes.map(prefix => `${prefix}org.opencontainers.image.${key}=${resolvedValue}`)
})
.flat()
.join('\n')
return annotations
# We also add the generated OCI metadata as labels because the GitHub
# Container registry does not correctly pick up the OCI annotations in
# some cases and prefers to pull displayed data from the image labels
# instead (which then results in data from the base images being shown if
# we do not provide values for the respective labels ourselves).
- name: Generate OCI labels
uses: actions/github-script@v7
id: generate-labels
env:
IMAGE: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_DATABASE }}
REPOSITORY_OWNER: ${{ inputs.repository-owner }}
REPOSITORY_NAME: ${{ inputs.repository-name }}
REVISION: ${{ inputs.revision }}
CUSTOM_NAME: ${{ inputs.custom-name }}
TIMESTAMP: ${{ steps.generate-timestamp.outputs.timestamp }}
with:
result-encoding: string
script: |
const refName = process.env.CUSTOM_NAME.trim() !== ''
? `${process.env.IMAGE}:${process.env.CUSTOM_NAME}`
: `${process.env.IMAGE}:${process.env.REPOSITORY_OWNER}-${process.env.REPOSITORY_NAME}-${process.env.REVISION}`
const labels = [
{ key: 'created', value: process.env.TIMESTAMP },
{ key: 'authors', envKey: 'OCI_ANNOTATION_AUTHORS' },
{ key: 'url', envKey: 'OCI_ANNOTATION_URL' },
{ key: 'documentation', envKey: 'OCI_ANNOTATION_DOCUMENTATION' },
{ key: 'source', envKey: 'OCI_ANNOTATION_SOURCE' },
{ key: 'vendor', envKey: 'OCI_ANNOTATION_VENDOR' },
{ key: 'licenses', envKey: 'OCI_ANNOTATION_LICENSES' },
{ key: 'ref.name', value: refName },
{ key: 'title', envKey: 'OCI_ANNOTATION_DATABASE_TITLE' },
{ key: 'description', envKey: 'OCI_ANNOTATION_DATABASE_DESCRIPTION' },
{ key: 'base.name', envKey: 'OCI_ANNOTATION_DATABASE_BASE_NAME' },
].map(({ key, value, envKey }) => {
const resolvedValue = value ?? process.env[envKey] ?? ''
return `org.opencontainers.image.${key}=${resolvedValue}`
})
.join('\n')
return labels
- name: Build and push images
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ inputs.architectures == 'Both x86_64 and aarch64' && 'linux/amd64, linux/arm64' || inputs.architectures == 'aarch64 only' && 'linux/arm64' || 'linux/amd64' }}
file: ./docker/database/Dockerfile
push: true
provenance: false
build-args: |
VMANGOS_REPOSITORY_OWNER=${{ inputs.repository-owner }}
VMANGOS_REPOSITORY_NAME=${{ inputs.repository-name }}
VMANGOS_REVISION=${{ inputs.revision }}
VMANGOS_WORLD_DB_REPOSITORY_OWNER=${{ inputs.world-db-repository-owner }}
VMANGOS_WORLD_DB_REPOSITORY_NAME=${{ inputs.world-db-repository-name }}
VMANGOS_WORLD_DB_DUMP_NAME=${{ inputs.world-db-dump-name }}
tags: ${{ steps.generate-tags.outputs.result }}
annotations: ${{ steps.generate-annotations.outputs.result }}
labels: ${{ steps.generate-labels.outputs.result }}