-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
329 lines (298 loc) · 12.9 KB
/
Copy pathosrm-backend-docker.yml
File metadata and controls
329 lines (298 loc) · 12.9 KB
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
name: build and publish container image
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
ref:
description: 'Git ref (tag) to build the images from'
required: true
type: string
env:
SEMVER_REF: ${{ inputs.ref || github.ref_name }}
jobs:
build-amd64:
if: github.repository == 'Project-OSRM/osrm-backend'
strategy: &docker-base-image-matrix
matrix:
docker-base-image: ["debian"]
runs-on: ubuntu-latest
steps:
- name: Configure DNS servers
if: runner.os == 'Linux'
run: |
sudo rm -f /etc/resolv.conf
{
echo "nameserver 1.1.1.1"
echo "nameserver 8.8.8.8"
} | sudo tee /etc/resolv.conf > /dev/null
- name: Check out the repo
uses: actions/checkout@v7
with:
ref: ${{ inputs.ref || github.ref }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v6
with:
images: ghcr.io/${{ github.repository }}
flavor: |
latest=false
tags: |
type=raw,value=latest,suffix=-amd64-${{ matrix.docker-base-image }}
type=semver,pattern=v{{version}},value=${{ env.SEMVER_REF }},suffix=-amd64-${{ matrix.docker-base-image }}
type=semver,pattern={{version}},value=${{ env.SEMVER_REF }},suffix=-amd64-${{ matrix.docker-base-image }}
type=semver,pattern={{major}}.{{minor}},value=${{ env.SEMVER_REF }},suffix=-amd64-${{ matrix.docker-base-image }}
type=ref,event=tag,suffix=-amd64-${{ matrix.docker-base-image }}
type=ref,event=branch,enable=${{ inputs.ref == '' }},suffix=-amd64-${{ matrix.docker-base-image }}
- name: Docker meta - debug
id: metadebug
uses: docker/metadata-action@v6
with:
images: ghcr.io/${{ github.repository }}
flavor: |
latest=false
suffix=-debug-amd64-${{ matrix.docker-base-image }},onlatest=false
tags: |
type=semver,pattern=v{{version}},value=${{ env.SEMVER_REF }}
type=semver,pattern={{version}},value=${{ env.SEMVER_REF }}
type=semver,pattern={{major}}.{{minor}},value=${{ env.SEMVER_REF }}
type=ref,event=tag
type=ref,event=branch,enable=${{ inputs.ref == '' }}
- name: Docker meta - assertions
id: metaassertions
uses: docker/metadata-action@v6
with:
images: ghcr.io/${{ github.repository }}
flavor: |
latest=false
suffix=-assertions-amd64-${{ matrix.docker-base-image }},onlatest=false
tags: |
type=semver,pattern=v{{version}},value=${{ env.SEMVER_REF }}
type=semver,pattern={{version}},value=${{ env.SEMVER_REF }}
type=semver,pattern={{major}}.{{minor}},value=${{ env.SEMVER_REF }}
type=ref,event=tag
type=ref,event=branch,enable=${{ inputs.ref == '' }}
- name: Log in to GitHub Docker Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build container image - debug
uses: docker/build-push-action@v7
with:
push: true
platforms: linux/amd64
file: ./docker/Dockerfile-${{ matrix.docker-base-image }}
tags: ${{ steps.metadebug.outputs.tags }}
labels: ${{ steps.metadebug.outputs.labels }}
cache-from: type=gha,scope=docker-${{ matrix.docker-base-image }}
build-args: |
DOCKER_TAG=${{ join(steps.metadebug.outputs.tags ) }}-${{ matrix.docker-base-image }}
- name: Build container image - assertions
uses: docker/build-push-action@v7
with:
push: true
platforms: linux/amd64
file: ./docker/Dockerfile-${{ matrix.docker-base-image }}
tags: ${{ steps.metaassertions.outputs.tags }}
labels: ${{ steps.metaassertions.outputs.labels }}
cache-from: type=gha,scope=docker-${{ matrix.docker-base-image }}
build-args: |
DOCKER_TAG=${{ join(steps.metaassertions.outputs.tags ) }}-${{ matrix.docker-base-image }}
- name: Build container image - normal
uses: docker/build-push-action@v7
with:
push: true
platforms: linux/amd64
file: ./docker/Dockerfile-${{ matrix.docker-base-image }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=docker-${{ matrix.docker-base-image }}
build-args: |
DOCKER_TAG=${{ join(steps.meta.outputs.tags ) }}-${{ matrix.docker-base-image }}
build-arm64:
if: github.repository == 'Project-OSRM/osrm-backend'
strategy: *docker-base-image-matrix
runs-on: ubuntu-24.04-arm
steps:
- name: Configure DNS servers
if: runner.os == 'Linux'
run: |
sudo rm -f /etc/resolv.conf
{
echo "nameserver 1.1.1.1"
echo "nameserver 8.8.8.8"
} | sudo tee /etc/resolv.conf > /dev/null
- name: Check out the repo
uses: actions/checkout@v7
with:
ref: ${{ inputs.ref || github.ref }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v6
with:
images: ghcr.io/${{ github.repository }}
flavor: |
latest=false
tags: |
type=raw,value=latest,suffix=-arm64-${{ matrix.docker-base-image }}
type=semver,pattern=v{{version}},value=${{ env.SEMVER_REF }},suffix=-arm64-${{ matrix.docker-base-image }}
type=semver,pattern={{version}},value=${{ env.SEMVER_REF }},suffix=-arm64-${{ matrix.docker-base-image }}
type=semver,pattern={{major}}.{{minor}},value=${{ env.SEMVER_REF }},suffix=-arm64-${{ matrix.docker-base-image }}
type=ref,event=tag,suffix=-arm64-${{ matrix.docker-base-image }}
type=ref,event=branch,enable=${{ inputs.ref == '' }},suffix=-arm64-${{ matrix.docker-base-image }}
- name: Docker meta - debug
id: metadebug
uses: docker/metadata-action@v6
with:
images: ghcr.io/${{ github.repository }}
flavor: |
latest=false
suffix=-debug-arm64-${{ matrix.docker-base-image }},onlatest=false
tags: |
type=semver,pattern=v{{version}},value=${{ env.SEMVER_REF }}
type=semver,pattern={{version}},value=${{ env.SEMVER_REF }}
type=semver,pattern={{major}}.{{minor}},value=${{ env.SEMVER_REF }}
type=ref,event=tag
type=ref,event=branch,enable=${{ inputs.ref == '' }}
- name: Docker meta - assertions
id: metaassertions
uses: docker/metadata-action@v6
with:
images: ghcr.io/${{ github.repository }}
flavor: |
latest=false
suffix=-assertions-arm64-${{ matrix.docker-base-image }},onlatest=false
tags: |
type=semver,pattern=v{{version}},value=${{ env.SEMVER_REF }}
type=semver,pattern={{version}},value=${{ env.SEMVER_REF }}
type=semver,pattern={{major}}.{{minor}},value=${{ env.SEMVER_REF }}
type=ref,event=tag
type=ref,event=branch,enable=${{ inputs.ref == '' }}
- name: Log in to GitHub Docker Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build container image - debug
uses: docker/build-push-action@v7
with:
push: true
platforms: linux/arm64
file: ./docker/Dockerfile-${{ matrix.docker-base-image }}
tags: ${{ steps.metadebug.outputs.tags }}
labels: ${{ steps.metadebug.outputs.labels }}
cache-from: type=gha,scope=docker-${{ matrix.docker-base-image }}
build-args: |
DOCKER_TAG=${{ join(steps.metadebug.outputs.tags ) }}-${{ matrix.docker-base-image }}
- name: Build container image - assertions
uses: docker/build-push-action@v7
with:
push: true
platforms: linux/arm64
file: ./docker/Dockerfile-${{ matrix.docker-base-image }}
tags: ${{ steps.metaassertions.outputs.tags }}
labels: ${{ steps.metaassertions.outputs.labels }}
cache-from: type=gha,scope=docker-${{ matrix.docker-base-image }}
build-args: |
DOCKER_TAG=${{ join(steps.metaassertions.outputs.tags ) }}-${{ matrix.docker-base-image }}
- name: Build container image - normal
uses: docker/build-push-action@v7
with:
push: true
platforms: linux/arm64
file: ./docker/Dockerfile-${{ matrix.docker-base-image }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=docker-${{ matrix.docker-base-image }}
build-args: |
DOCKER_TAG=${{ join(steps.meta.outputs.tags ) }}-${{ matrix.docker-base-image }}
combine-manifests:
needs: [build-amd64, build-arm64]
if: github.repository == 'Project-OSRM/osrm-backend'
strategy: *docker-base-image-matrix
runs-on: ubuntu-latest
steps:
- name: Configure DNS servers
if: runner.os == 'Linux'
run: |
sudo rm -f /etc/resolv.conf
{
echo "nameserver 1.1.1.1"
echo "nameserver 8.8.8.8"
} | sudo tee /etc/resolv.conf > /dev/null
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GitHub Docker Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push manifests
run: |
REGISTRY_REPOSITORY="$(printf '%s' "$GITHUB_REPOSITORY" | tr '[:upper:]' '[:lower:]')"
REGISTRY="ghcr.io/$REGISTRY_REPOSITORY"
# Determine tag name based on trigger type
if [ "${{ inputs.ref }}" != "" ]; then
# workflow_dispatch with explicit ref/tag
RAW_REF="${{ inputs.ref }}"
elif [ "${{ github.ref_name }}" != "" ]; then
# push:tags trigger
RAW_REF="${{ github.ref_name }}"
else
RAW_REF="${{ github.ref }}"
fi
# Normalize refs/tags/v26.4.0 -> v26.4.0
REF_NAME="${RAW_REF#refs/tags/}"
if [ -z "$REF_NAME" ]; then
echo "Unable to determine tag name from ref: $RAW_REF" >&2
exit 1
fi
# Always create a manifest for the exact pushed tag, and also
# keep the existing semver aliases for plain release tags.
TAGS=("$REF_NAME")
if [[ "$REF_NAME" =~ ^v?([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
VERSION="${BASH_REMATCH[1]}"
MAJOR_MINOR="${VERSION%.*}"
TAGS+=("$VERSION" "$MAJOR_MINOR")
fi
# Always include latest so the multi-arch manifest serves as the
# default image for docker pull without an explicit version tag.
TAGS+=("latest")
# Deduplicate tags while preserving order
MANIFEST_TAGS=()
declare -A SEEN_TAGS=()
for TAG in "${TAGS[@]}"; do
if [ -n "$TAG" ] && [ -z "${SEEN_TAGS[$TAG]}" ]; then
MANIFEST_TAGS+=("$TAG")
SEEN_TAGS[$TAG]=1
fi
done
echo "Creating manifests for ${{ matrix.docker-base-image }}..."
for IMAGE_SUFFIX in "" "-debug" "-assertions"; do
for TAG in "${MANIFEST_TAGS[@]}"; do
# The "latest" tag only applies to the base image, not to
# -debug or -assertions variant suffixes.
if [ "$TAG" = "latest" ] && [ -n "$IMAGE_SUFFIX" ]; then
continue
fi
docker buildx imagetools create -t "$REGISTRY:${TAG}${IMAGE_SUFFIX}-${{ matrix.docker-base-image }}" \
"$REGISTRY:${TAG}${IMAGE_SUFFIX}-amd64-${{ matrix.docker-base-image }}" \
"$REGISTRY:${TAG}${IMAGE_SUFFIX}-arm64-${{ matrix.docker-base-image }}"
# Additionally create a bare "latest" multi-arch manifest (no
# -debian suffix) so that "docker pull …:latest" works as expected.
if [ "$TAG" = "latest" ] && [ -z "$IMAGE_SUFFIX" ]; then
docker buildx imagetools create -t "$REGISTRY:latest" \
"$REGISTRY:latest-amd64-${{ matrix.docker-base-image }}" \
"$REGISTRY:latest-arm64-${{ matrix.docker-base-image }}"
fi
done
done