-
-
Notifications
You must be signed in to change notification settings - Fork 6
321 lines (297 loc) · 11.8 KB
/
toolchain.yml
File metadata and controls
321 lines (297 loc) · 11.8 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
name: Build Toolchains
permissions: {}
on:
push:
paths:
- ".github/workflows/toolchain.yml"
- "Dockerfile.toolchain"
- "config.mak"
branches:
- main
## ##
## To trigger this workflow using `act` (https://github.com/nektos/act) you can do the following.
## Full run
## act push -j toolchain
## ##
jobs:
# ###
# Generate variables used by other jobs
tbuild_vars:
if: ${{ github.repository == 'BlackDex/rust-musl' }}
name: Generate Build Variables
runs-on: ubuntu-24.04
env:
HAVE_DOCKERHUB_LOGIN: ${{ vars.DOCKERHUB_ENABLED == 'true' && secrets.DOCKERHUB_USERNAME != '' && secrets.DOCKERHUB_TOKEN != '' }}
HAVE_GHCR_LOGIN: ${{ vars.GHCR_ENABLED == 'true' && github.repository_owner != '' && secrets.GITHUB_TOKEN != '' }}
HAVE_QUAY_LOGIN: ${{ vars.QUAY_ENABLED == 'true' && secrets.QUAY_USERNAME != '' && secrets.QUAY_TOKEN != '' }}
outputs:
have_dockerhub_login: ${{ env.HAVE_DOCKERHUB_LOGIN }}
have_ghcr_login: ${{ env.HAVE_GHCR_LOGIN }}
have_quay_login: ${{ env.HAVE_QUAY_LOGIN }}
tag_date: ${{ steps.date.outputs.tag }}
registry_list: ${{ steps.registry.outputs.list }}
steps:
- name: Determine Container Date Tag
id: date
shell: bash
run: |
# Get the current date
echo "tag=$(date +'-%Y-%m-%d')" | tee -a "${GITHUB_OUTPUT}"
- name: Determine Container Registries
id: registry
env:
HAVE_DOCKERHUB_LOGIN: ${{ env.HAVE_DOCKERHUB_LOGIN }}
HAVE_GHCR_LOGIN: ${{ env.HAVE_GHCR_LOGIN }}
HAVE_QUAY_LOGIN: ${{ env.HAVE_QUAY_LOGIN }}
HAVE_LOCALHOST: ${{ github.event.act }}
shell: bash
run: |
registries=""
if [[ "${HAVE_DOCKERHUB_LOGIN}" = true ]]; then
registries="${registries:+${registries} }docker.io"
fi
if [[ "${HAVE_GHCR_LOGIN}" = true ]]; then
registries="${registries:+${registries} }ghcr.io"
fi
if [[ "${HAVE_QUAY_LOGIN}" = true ]]; then
registries="${registries:+${registries} }quay.io"
fi
if [[ "${HAVE_LOCALHOST}" = true ]]; then
registries="${registries:+${registries} }localhost:5000"
fi
echo "list=${registries}" | tee -a "${GITHUB_OUTPUT}"
# ###
# Building Toolchain
toolchain:
if: ${{ github.repository == 'BlackDex/rust-musl' }}
name: Build Toolchain - ${{ matrix.image_tag }} - ${{ matrix.os }}
needs:
- tbuild_vars
runs-on: ${{ matrix.os }}
permissions:
packages: write
contents: read
strategy:
max-parallel: ${{ github.event.act && 1 || 8 }}
matrix:
act:
- ${{ github.event.act }}
os:
- ubuntu-24.04
- ${{ (github.event.act && github.event_name == 'qemu') && 'ubuntu-24.04-qemu-arm' || 'ubuntu-24.04-arm' }}
image_tag:
- x86_64-musl
- aarch64-musl
- armv7-musleabihf
- arm-musleabi
# arch_common_config are based upon the `"COMMON_CONFIG +=` additions extracted
# from the MUSL Dockerfiles here: https://github.com/rust-embedded/cross/tree/master/docker
include:
- image_tag: x86_64-musl
target: x86_64-unknown-linux-musl
- image_tag: aarch64-musl
target: aarch64-unknown-linux-musl
- image_tag: armv7-musleabihf
target: armv7-unknown-linux-musleabihf
arch_common_config: "--with-arch=armv7-a --with-float=hard --with-mode=thumb --with-fpu=vfp"
- image_tag: arm-musleabi
target: arm-unknown-linux-musleabi
arch_common_config: "--with-arch=armv6 --with-float=soft --with-mode=arm"
exclude:
- os: ubuntu-24.04-arm
act: true
steps:
- name: "[act] Debug Matrix"
if: ${{ github.event.act }}
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
MATRIX_JSON: ${{ toJson(matrix) }}
NEEDS_JSON: ${{ toJson(needs)}}
# GITHUB_JSON: ${{ toJson(github) }}
run: |
echo "event_name = ${EVENT_NAME}"
echo ; echo "matrix = ${MATRIX_JSON}"
echo ; echo "needs = ${NEEDS_JSON}"
# echo ; echo "github = ${GITHUB_JSON}"
- name: Determine Arch Tag
id: arch
env:
MATRIX_OS: ${{ matrix.os }}
shell: bash
run: |
if [[ "${MATRIX_OS}" == *-arm ]]; then
echo "type=arm64-" | tee -a "${GITHUB_OUTPUT}"
else
echo "type=amd64-" | tee -a "${GITHUB_OUTPUT}"
fi
- name: Setup Docker Buildx (setup-buildx-action)
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
with:
driver: docker-container
cache-binary: false
driver-opts: |
network=host
- name: "[act] Start local registry"
if: ${{ github.event.act }}
shell: bash
run: |
# Start a local docker registry
docker run -d --name act-registry --network host registry:3 || \
docker start act-registry || true
- name: Login to DockerHub
if: ${{ needs.tbuild_vars.outputs.have_dockerhub_login == 'true' }}
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to ghcr.io
if: ${{ needs.tbuild_vars.outputs.have_ghcr_login == 'true' }}
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to quay.io
if: ${{ needs.tbuild_vars.outputs.have_quay_login == 'true' }}
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_TOKEN }}
- name: Generate Container Tags
continue-on-error: false
id: tags
shell: bash
env:
REGISTRIES: ${{ needs.tbuild_vars.outputs.registry_list }}
ARCH_TYPE: ${{ steps.arch.outputs.type }}
TAG_DATE: ${{ needs.tbuild_vars.outputs.tag_date }}
IMAGE_TAG: ${{ matrix.image_tag }}
run: |
tags=""
for registry in ${REGISTRIES}; do
echo "Generating tags for ${registry}:"
tags="${tags:+${tags},}${registry}/blackdex/musl-toolchain:${ARCH_TYPE}${IMAGE_TAG}"
tags="${tags:+${tags},}${registry}/blackdex/musl-toolchain:${ARCH_TYPE}${IMAGE_TAG}${TAG_DATE}"
done
if [[ "${tags}" = "" ]]; then
echo "::error::Unable to generate tags. Check if registries are available!"
exit 1
fi
echo "tags=${tags}" | tee -a "${GITHUB_OUTPUT}"
- name: Checkout Repo
uses: actions/checkout@71cf2267d89c5cb81562390fa70a37fa40b1305e # v6-beta
with:
persist-credentials: false
- name: Docker Build
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
env:
BUILDKIT_PROGRESS: plain
with:
platforms: ${{ (matrix.os == 'ubuntu-24.04-arm' || matrix.os == 'ubuntu-24.04-qemu-arm') && 'linux/arm64' || 'linux/amd64'}}
outputs: type=image,oci-mediatypes=true,compression=zstd,compression-level=3,force-compression=true,push=true
context: .
file: ./Dockerfile.toolchain
build-args: |
QEMU_CPU=${{ matrix.os == 'ubuntu-24.04-qemu-arm' && 'max,pmu=off,pauth-impdef=on' || ''}}
TARGET=${{ matrix.target }}
ARCH_COMMON_CONFIG=${{ matrix.arch_common_config }}
tags: ${{ steps.tags.outputs.tags }}
load: ${{ github.event.act && 'true' || 'false' }}
# Merge the separate build amd64 and arm64 builds into one
# https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners
toolchain_merge:
if: ${{ github.repository == 'BlackDex/rust-musl' }}
name: Merge Toolchain Container
runs-on: ubuntu-24.04
permissions:
packages: write
needs:
- tbuild_vars
- toolchain
strategy:
max-parallel: ${{ github.event.act && 1 || 8 }}
matrix:
image_tag:
- x86_64-musl
- aarch64-musl
- armv7-musleabihf
- arm-musleabi
steps:
- name: "[act] Debug Matrix"
if: ${{ github.event.act }}
shell: bash
env:
BUILD_JSON: ${{ toJson(needs.tbuild_vars) }}
NEEDS_JSON: ${{ toJson(needs.toolchain) }}
EVENT_NAME: ${{ github.event_name }}
MATRIX_JSON: ${{ toJson(matrix) }}
# GITHUB_JSON: ${{ toJson(github) }}
run: |
echo "event_name = ${EVENT_NAME}"
echo "build_json = ${BUILD_JSON}"
echo "needs_json = ${NEEDS_JSON}"
echo ; echo "matrix = ${MATRIX_JSON}"
# echo ; echo "github = ${GITHUB_JSON}"
- name: Setup Docker Buildx (setup-buildx-action)
uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
with:
driver: docker-container
cache-binary: false
driver-opts: |
network=host
- name: "[act] Start local registry"
if: ${{ github.event.act }}
shell: bash
run: |
# Start a local docker registry
docker run -d --name act-registry --network host registry:3 || \
docker start act-registry || true
- name: Login to DockerHub
if: ${{ needs.tbuild_vars.outputs.have_dockerhub_login == 'true' }}
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to ghcr.io
if: ${{ needs.tbuild_vars.outputs.have_ghcr_login == 'true' }}
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to quay.io
if: ${{ needs.tbuild_vars.outputs.have_quay_login == 'true' }}
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_TOKEN }}
- name: Create combined manifests for amd64/arm64
shell: bash
env:
REGISTRIES: ${{ needs.tbuild_vars.outputs.registry_list }}
TAG_DATE: ${{ needs.tbuild_vars.outputs.tag_date }}
IMAGE_TAG: ${{ matrix.image_tag }}
run: |
tags=""
for registry in ${REGISTRIES}; do
echo "Generating manifest for ${registry}:"
docker buildx imagetools create \
-t ${registry}/blackdex/musl-toolchain:${IMAGE_TAG} \
-t ${registry}/blackdex/musl-toolchain:${IMAGE_TAG}${TAG_DATE} \
${registry}/blackdex/musl-toolchain:amd64-${IMAGE_TAG}${TAG_DATE} \
${registry}/blackdex/musl-toolchain:arm64-${IMAGE_TAG}${TAG_DATE}
done
- name: Inspect manifests for amd64/arm64
shell: bash
env:
REGISTRIES: ${{ needs.tbuild_vars.outputs.registry_list }}
IMAGE_TAG: ${{ matrix.image_tag }}
run: |
tags=""
for registry in ${REGISTRIES}; do
echo "Inspecting manifest for ${registry}:"
docker buildx imagetools inspect ${registry}/blackdex/musl-toolchain:${IMAGE_TAG}
done