-
Notifications
You must be signed in to change notification settings - Fork 351
256 lines (253 loc) · 11.6 KB
/
docker-build.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
name: Publish Docker Image
on:
push:
tags:
- v1.*
concurrency:
group: ${{ github.head_ref || github.sha }}-${{ github.workflow }}
cancel-in-progress: true
env:
REPOSITORY: ${{ secrets.DOCKER_HUB_ORGS }}/${{ secrets.DOCKER_HUB_REPOSITORY }}
jobs:
define-matrix:
runs-on: ubuntu-latest
env:
ALL_COMPONENTS: >
[
"alpine",
"arm64",
"armhf",
"amd64",
]
outputs:
components: >
${{ steps.arrange-components.outputs.for_all == 'true' && env.ALL_COMPONENTS
|| format('["{0}"]', steps.arrange-components.outputs.component) }}
steps:
- id: arrange-components
run: |
echo "for_all=true" >> "$GITHUB_OUTPUT"
for component in ${{ join(fromJSON(env.ALL_COMPONENTS), ' ') }}; do
if [[ ${{ github.ref_name }} == *"$component"* ]]; then
echo "for_all=false" >> "$GITHUB_OUTPUT"
echo "component=$component" >> "$GITHUB_OUTPUT"
break
fi
done
build:
needs: define-matrix
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
component: ${{ fromJSON(needs.define-matrix.outputs.components) }}
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: linux/amd64,linux/arm64,linux/arm/v7 # armhf
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Setup tags
run: |
set -x
component=${{ matrix.component }}
for target in $(make echo-all-images); do
case $target in
*$component*)
;;
*)
continue
;;
esac
branch=$(echo $target | cut -d'/' -f1)
tags=$(echo $target | cut -d':' -f2-)
tag1=$(echo $tags | cut -d',' -f1)
tag2=$(echo $tags | cut -d',' -f2)
tag3=$(echo $tags | cut -d',' -f3)
case $component in
*alpine*)
echo "CONTEXT=${branch}/${component}" >> ${GITHUB_ENV}
echo "ALPINETAGS=${{ env.REPOSITORY }}:${tag1},${{ env.REPOSITORY }}:${tag2},${{ env.REPOSITORY }}:${tag3}" >> ${GITHUB_ENV}
;;
*arm64*)
echo "CONTEXT=${branch}/${component}/debian" >> ${GITHUB_ENV}
echo "ARM64TAGS=${{ env.REPOSITORY }}:${tag1},${{ env.REPOSITORY }}:${tag2},${{ env.REPOSITORY }}:${tag3}" >> ${GITHUB_ENV}
;;
*armhf*)
echo "CONTEXT=${branch}/${component}/debian" >> ${GITHUB_ENV}
echo "ARMHFTAGS=${{ env.REPOSITORY }}:${tag1},${{ env.REPOSITORY }}:${tag2},${{ env.REPOSITORY }}:${tag3}" >> ${GITHUB_ENV}
;;
*amd64*)
echo "CONTEXT=${branch}/debian" >> ${GITHUB_ENV}
echo "AMD64TAGS=${{ env.REPOSITORY }}:${tag1},${{ env.REPOSITORY }}:${tag2},${{ env.REPOSITORY }}:${tag3}" >> ${GITHUB_ENV}
;;
esac
done
- name: Build and push for alpine
if: ${{ env.ALPINETAGS }}
uses: docker/build-push-action@v6
with:
context: ${{ env.CONTEXT }}
provenance: false
push: true
platforms: linux/amd64
tags: ${{ env.ALPINETAGS }}
# dare to use old mediatype (application/vnd.docker.distribution.manifest.v2+json)
outputs: oci-mediatypes=false
- name: Build and push for amd64
if: ${{ env.AMD64TAGS }}
uses: docker/build-push-action@v6
with:
context: ${{ env.CONTEXT }}
provenance: false
push: true
platforms: linux/amd64
tags: ${{ env.AMD64TAGS }}
# dare to use old mediatype (application/vnd.docker.distribution.manifest.v2+json)
outputs: oci-mediatypes=false
- name: Build and push for arm64
if: ${{ env.ARM64TAGS }}
uses: docker/build-push-action@v6
with:
context: ${{ env.CONTEXT }}
provenance: false
push: true
platforms: linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ env.ARM64TAGS }}
# dare to use old mediatype (application/vnd.docker.distribution.manifest.v2+json)
outputs: oci-mediatypes=false
- name: Build and push for armhf
if: ${{ env.ARMHFTAGS }}
uses: docker/build-push-action@v6
with:
context: ${{ env.CONTEXT }}
provenance: false
push: true
platforms: linux/arm/v7
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ env.ARMHFTAGS }}
# dare to use old mediatype (application/vnd.docker.distribution.manifest.v2+json)
outputs: oci-mediatypes=false
manifest:
needs: [define-matrix, build]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
component: ${{ fromJSON(needs.define-matrix.outputs.components) }}
steps:
- uses: actions/checkout@v4
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Create manifest
if: ${{ matrix.component }} != "alpine"
run: |
component=${{ matrix.component }}
for target in $(make echo-all-images); do
tags=$(echo $target | cut -d':' -f2-)
tag1=$(echo $tags | cut -d',' -f1)
tag2=$(echo $tags | cut -d',' -f2)
tag3=$(echo $tags | cut -d',' -f3)
case $target in
*amd64*)
MULTIARCH_AMD64_TAG=${tag1/amd64-/}
MULTIARCH_AMD64_SHORT_TAG=${tag2/amd64-/}
AMD64TAG=${tag1}
SHORT_AMD64TAG=${tag2}
;;
*arm64*)
MULTIARCH_ARM64_TAG=${tag1/arm64-/}
MULTIARCH_ARM64_SHORT_TAG=${tag2/arm64-/}
ARM64TAG=${tag1}
SHORT_ARM64TAG=${tag2}
;;
*armhf*)
MULTIARCH_ARMHF_TAG=${tag1/armhf-/}
MULTIARCH_ARMHF_SHORT_TAG=${tag2/armhf-/}
ARMHFTAG=${tag1}
SHORT_ARMHFTAG=${tag2}
;;
*alpine*)
;;
esac
done
# v1.xx.y-debian-n.m
if [ ${MULTIARCH_AMD64_TAG} != ${MULTIARCH_ARM64_TAG} -o ${MULTIARCH_AMD64_TAG} != ${MULTIARCH_ARMHF_TAG} -o ${MULTIARCH_ARM64_TAG} != ${MULTIARCH_ARMHF_TAG} ]; then
echo "Multiarch tag (v1.x.y-debian-(ARCH)-n.m) must be same for amd64, arm64 and armhf: ${MULTIARCH_AMD64_TAG}, ${MULTIARCH_ARM64_TAG}, ${MULTIARCH_ARMHF_TAG}"
else
docker buildx imagetools create -t ${{ env.REPOSITORY }}:${MULTIARCH_AMD64_TAG} \
${{ env.REPOSITORY }}:${AMD64TAG} \
${{ env.REPOSITORY }}:${ARM64TAG} \
${{ env.REPOSITORY }}:${ARMHFTAG}
fi
# v1.xx-debian-n.m
if [ ${MULTIARCH_AMD64_SHORT_TAG} != ${MULTIARCH_ARM64_SHORT_TAG} -o ${MULTIARCH_AMD64_SHORT_TAG} != ${MULTIARCH_ARMHF_SHORT_TAG} -o ${MULTIARCH_ARM64_SHORT_TAG} != ${MULTIARCH_ARMHF_SHORT_TAG} ]; then
echo "Multiarch tag (v1.xx-debian-n.m must be same for amd64, arm64 and armhf: ${MULTIARCH_AMD64_SHORT_TAG}, ${MULTIARCH_ARM64_SHORT_TAG}, ${MULTIARCH_ARMHF_SHORT_TAG}"
else
docker buildx imagetools create -t ${{ env.REPOSITORY }}:${MULTIARCH_AMD64_SHORT_TAG} \
${{ env.REPOSITORY }}:${SHORT_AMD64TAG} \
${{ env.REPOSITORY }}:${SHORT_ARM64TAG} \
${{ env.REPOSITORY }}:${SHORT_ARMHFTAG}
fi
# edge-debian
docker buildx imagetools create -t ${{ env.REPOSITORY }}:edge-debian \
${{ env.REPOSITORY }}:edge-debian-amd64 \
${{ env.REPOSITORY }}:edge-debian-arm64 \
${{ env.REPOSITORY }}:edge-debian-armhf
echo "MULTIARCH_AMD64_TAG=${MULTIARCH_AMD64_TAG}" >> ${GITHUB_ENV}
echo "MULTIARCH_AMD64_SHORT_TAG=${MULTIARCH_AMD64_SHORT_TAG}" >> ${GITHUB_ENV}
echo "AMD64TAG=${AMD64TAG}" >> ${GITHUB_ENV}
echo "SHORT_AMD64TAG=${SHORT_ARM64TAG}" >> ${GITHUB_ENV}
echo "MULTIARCH_ARM64_TAG=${MULTIARCH_ARM64_TAG}" >> ${GITHUB_ENV}
echo "MULTIARCH_ARM64_SHORT_TAG=${MULTIARCH_ARM64_SHORT_TAG}" >> ${GITHUB_ENV}
echo "ARM64TAG=${ARM64TAG}" >> ${GITHUB_ENV}
echo "SHORT_ARM64TAG=${SHORT_ARM64TAG}" >> ${GITHUB_ENV}
echo "MULTIARCH_ARMHF_TAG=${MULTIARCH_ARMHF_TAG}" >> ${GITHUB_ENV}
echo "MULTIARCH_ARMHF_SHORT_TAG=${MULTIARCH_ARMHF_SHORT_TAG}" >> ${GITHUB_ENV}
echo "ARMHFTAG=${ARMHFTAG}" >> ${GITHUB_ENV}
echo "SHORT_ARMHFTAG=${SHORT_ARMHFTAG}" >> ${GITHUB_ENV}
- name: Inspect manifest ${{ env.AMD64TAG }}
run: docker manifest inspect ${{ env.REPOSITORY }}:${{ env.AMD64TAG }}
- name: Inspect manifest ${{ env.ARM64TAG }}
run: docker manifest inspect ${{ env.REPOSITORY }}:${{ env.ARM64TAG }}
- name: Inspect manifest ${{ env.ARMHFTAG }}
run: docker manifest inspect ${{ env.REPOSITORY }}:${{ env.ARMHFTAG }}
- name: Inspect manifest ${{ env.MULTIARCH_AMD64_TAG }}
run: docker manifest inspect ${{ env.REPOSITORY }}:${{ env.MULTIARCH_AMD64_TAG }}
- name: Inspect manifest ${{ env.MULTIARCH_ARM64_TAG }}
run: docker manifest inspect ${{ env.REPOSITORY }}:${{ env.MULTIARCH_ARM64_TAG }}
- name: Inspect manifest ${{ env.MULTIARCH_ARMHF_TAG }}
run: docker manifest inspect ${{ env.REPOSITORY }}:${{ env.MULTIARCH_ARMHF_TAG }}
- name: Inspect manifest ${{ env.MULTIARCH_AMD64_SHORT_TAG }}
run: docker manifest inspect ${{ env.REPOSITORY }}:${{ env.MULTIARCH_AMD64_SHORT_TAG }}
- name: Inspect manifest ${{ env.MULTIARCH_ARM64_SHORT_TAG }}
run: docker manifest inspect ${{ env.REPOSITORY }}:${{ env.MULTIARCH_ARM64_SHORT_TAG }}
- name: Inspect manifest ${{ env.MULTIARCH_ARMHF_SHORT_TAG }}
run: docker manifest inspect ${{ env.REPOSITORY }}:${{ env.MULTIARCH_ARMHF_SHORT_TAG }}
- name: Inspect ${{ env.AMD64TAG }} with buildx
run: docker buildx imagetools inspect ${{ env.REPOSITORY }}:${{ env.AMD64TAG }}
- name: Inspect ${{ env.ARM64TAG }} with buildx
run: docker buildx imagetools inspect ${{ env.REPOSITORY }}:${{ env.ARM64TAG }}
- name: Inspect ${{ env.ARMHFTAG }} with buildx
run: docker buildx imagetools inspect ${{ env.REPOSITORY }}:${{ env.ARMHFTAG }}
- name: Inspect ${{ env.MULTIARCH_AMD64_TAG }} with buildx
run: docker buildx imagetools inspect ${{ env.REPOSITORY }}:${{ env.MULTIARCH_AMD64_TAG }}
- name: Inspect ${{ env.MULTIARCH_ARM64_TAG }} with buildx
run: docker buildx imagetools inspect ${{ env.REPOSITORY }}:${{ env.MULTIARCH_ARM64_TAG }}
- name: Inspect ${{ env.MULTIARCH_ARMHF_TAG }} with buildx
run: docker buildx imagetools inspect ${{ env.REPOSITORY }}:${{ env.MULTIARCH_ARMHF_TAG }}
- name: Inspect ${{ env.MULTIARCH_AMD64_SHORT_TAG }} with buildx
run: docker buildx imagetools inspect ${{ env.REPOSITORY }}:${{ env.MULTIARCH_AMD64_SHORT_TAG }}
- name: Inspect ${{ env.MULTIARCH_ARM64_SHORT_TAG }} with buildx
run: docker buildx imagetools inspect ${{ env.REPOSITORY }}:${{ env.MULTIARCH_ARM64_SHORT_TAG }}
- name: Inspect ${{ env.MULTIARCH_ARMHF_SHORT_TAG }} with buildx
run: docker buildx imagetools inspect ${{ env.REPOSITORY }}:${{ env.MULTIARCH_ARMHF_SHORT_TAG }}