Skip to content

Commit 24af91b

Browse files
authored
Merge pull request #133 from firedexofficial/arm-support
Switch the nightly build to producing a multiarch docker image that supports both x86_64 and arm64
2 parents e13ed1f + bce06bd commit 24af91b

File tree

7 files changed

+481
-62
lines changed

7 files changed

+481
-62
lines changed

.github/workflows/nightly.yml

+127-19
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,158 @@ on:
99
branches:
1010
- 'main'
1111

12+
concurrency:
13+
group: ${{ github.ref }}-nightly
14+
cancel-in-progress: true
15+
16+
env:
17+
REGISTRY_IMAGE: clux/muslrust
18+
1219
jobs:
13-
docker:
20+
build:
1421
name: 'Nightly Build'
1522
runs-on: 'ubuntu-latest'
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
platform: [linux/amd64, linux/arm64]
27+
include:
28+
- platform: linux/amd64
29+
dockerfile: Dockerfile.x86_64
30+
arch: amd64
31+
target_dir: x86_64-unknown-linux-musl
32+
- platform: linux/arm64
33+
dockerfile: Dockerfile.arm64
34+
arch: arm64
35+
target_dir: aarch64-unknown-linux-musl
1636
steps:
1737
- uses: 'actions/checkout@v2'
1838
- uses: extractions/setup-just@v1
1939

2040
- name: Login to DockerHub
21-
if: github.event_name != 'pull_request'
2241
uses: docker/login-action@v1
2342
with:
2443
username: clux
2544
password: ${{ secrets.DOCKERHUB_TOKEN }}
2645

46+
- name: Prepare
47+
run: |
48+
platform=${{ matrix.platform }}
49+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
50+
51+
- name: Docker meta
52+
id: meta
53+
uses: docker/metadata-action@v5
54+
with:
55+
images: ${{ env.REGISTRY_IMAGE }}
56+
57+
- name: Set up QEMU
58+
uses: docker/setup-qemu-action@v3
59+
60+
- name: Set up Docker Buildx
61+
uses: docker/setup-buildx-action@v3
62+
2763
- name: Build nightly image
28-
uses: docker/build-push-action@v2
64+
id: build
65+
uses: docker/build-push-action@v3
2966
with:
3067
context: .
68+
platforms: ${{ matrix.platform }}
69+
labels: ${{ steps.meta.outputs.labels }}
70+
file: ${{ matrix.dockerfile }}
3171
push: false
72+
load: true
73+
tags: rustmusl-temp
3274
build-args: |
3375
CHANNEL=nightly
34-
tags: clux/muslrust:temp
3576
36-
- name: Compute tags
77+
- name: Run tests
78+
shell: bash
79+
run: |
80+
docker buildx build --platform ${{ matrix.platform }} --output type=docker -t test-runner - < Dockerfile.test-runner
81+
TARGET_DIR=${{ matrix.target_dir }} PLATFORM=${{ matrix.platform }} just test
82+
83+
# The date/channel/version are expected to be the same on both architectures and are needed for the merge step.
84+
# We store them here since it makes the merge step a bit easier - it doesn't need to figure out which of the
85+
# architectures it can run (to extract the rust version). The problem is that it appears we can't run images
86+
# that were built by docker buildx (the build-push-action step) locally. They get pushed to dockerhub but are
87+
# only identifiable by their digest and it appears docker does not let us select an image that way.
88+
# Not the most elegant, but it works.
89+
- name: Store tag info
3790
shell: bash
3891
run: |
39-
docker run clux/muslrust:temp rustc --version
40-
RUST_VER="$(docker run clux/muslrust:temp rustc --version | grep -oE "[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]")"
92+
mkdir -p /tmp/tags
4193
RUST_DATE="$(date +"%Y-%m-%d")"
4294
RUST_CHANNEL=nightly
43-
echo "TAG1=clux/muslrust:${RUST_CHANNEL}" >> $GITHUB_ENV
44-
echo "TAG2=clux/muslrust:${RUST_CHANNEL}-${RUST_DATE}" >> $GITHUB_ENV
45-
echo "TAG3=clux/muslrust:${RUST_VER}-${RUST_CHANNEL}-${RUST_DATE}" >> $GITHUB_ENV
95+
RUST_VER="$(docker run --platform ${{ matrix.platform }} rustmusl-temp rustc --version | grep -oE "[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]")"
4696
47-
- name: Run tests
97+
echo $RUST_DATE > /tmp/tags/rust-date
98+
echo $RUST_CHANNEL > /tmp/tags/rust-channel
99+
echo $RUST_VER > /tmp/tags/rust-ver
100+
101+
- name: Tag and push
48102
shell: bash
49-
run: just test
103+
run: |
104+
RUST_DATE=$(cat /tmp/tags/rust-date)
105+
RUST_CHANNEL=$(cat /tmp/tags/rust-channel)
106+
RUST_VER=$(cat /tmp/tags/rust-ver)
50107
51-
- name: Push image under computed tags
52-
uses: docker/build-push-action@v2
108+
TAG_NAME="${{ matrix.arch }}-${RUST_VER}-${RUST_CHANNEL}-${RUST_DATE}"
109+
110+
docker tag rustmusl-temp ${{ env.REGISTRY_IMAGE }}:$TAG_NAME
111+
docker push ${{ env.REGISTRY_IMAGE }}:$TAG_NAME
112+
113+
- name: Upload tags
114+
uses: actions/upload-artifact@v4
53115
with:
54-
context: .
55-
build-args: |
56-
CHANNEL=nightly
57-
push: ${{ github.event_name != 'pull_request' }}
58-
tags: clux/muslrust:latest,${{ env.TAG1 }},${{ env.TAG2 }},${{ env.TAG3 }}
116+
name: tags
117+
path: /tmp/tags
118+
if-no-files-found: error
119+
retention-days: 1
120+
overwrite: true
121+
122+
merge:
123+
runs-on: ubuntu-latest
124+
needs:
125+
- build
126+
steps:
127+
128+
-
129+
name: Download tags
130+
uses: actions/download-artifact@v4
131+
with:
132+
path: /tmp/tags
133+
name: tags
134+
135+
-
136+
name: Set up Docker Buildx
137+
uses: docker/setup-buildx-action@v3
138+
-
139+
name: Docker meta
140+
id: meta
141+
uses: docker/metadata-action@v5
142+
with:
143+
images: ${{ env.REGISTRY_IMAGE }}
144+
-
145+
name: Login to Docker Hub
146+
uses: docker/login-action@v3
147+
with:
148+
username: clux
149+
password: ${{ secrets.DOCKERHUB_TOKEN }}
150+
-
151+
name: Create manifest list and push multi-platform images
152+
run: |
153+
RUST_DATE=$(cat /tmp/tags/rust-date)
154+
RUST_CHANNEL=$(cat /tmp/tags/rust-channel)
155+
RUST_VER=$(cat /tmp/tags/rust-ver)
156+
157+
for tag in latest ${RUST_CHANNEL} ${RUST_CHANNEL}-${RUST_DATE} ${RUST_VER}-${RUST_CHANNEL}-${RUST_DATE}; do
158+
docker buildx imagetools create -t ${{ env.REGISTRY_IMAGE }}:$tag \
159+
${{ env.REGISTRY_IMAGE }}:amd64-${RUST_VER}-${RUST_CHANNEL}-${RUST_DATE} \
160+
${{ env.REGISTRY_IMAGE }}:arm64-${RUST_VER}-${RUST_CHANNEL}-${RUST_DATE}
161+
done
162+
163+
-
164+
name: Inspect image
165+
run: |
166+
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:latest

.github/workflows/stable.yml

+142-30
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,40 @@ on:
99
branches:
1010
- 'main'
1111

12+
concurrency:
13+
group: ${{ github.ref }}-stable
14+
cancel-in-progress: true
15+
16+
env:
17+
REGISTRY_IMAGE: clux/muslrust
18+
1219
jobs:
13-
docker:
20+
build:
1421
name: 'Stable Build'
1522
runs-on: 'ubuntu-latest'
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
platform: [linux/amd64, linux/arm64]
27+
include:
28+
- platform: linux/amd64
29+
dockerfile: Dockerfile.x86_64
30+
arch: amd64
31+
target_dir: x86_64-unknown-linux-musl
32+
- platform: linux/arm64
33+
dockerfile: Dockerfile.arm64
34+
arch: arm64
35+
target_dir: aarch64-unknown-linux-musl
1636
steps:
1737
- uses: 'actions/checkout@v2'
1838
- uses: extractions/setup-just@v1
1939

40+
- name: Login to DockerHub
41+
uses: docker/login-action@v1
42+
with:
43+
username: clux
44+
password: ${{ secrets.DOCKERHUB_TOKEN }}
45+
2046
- name: Check if we need a new stable
2147
id: stablecheck
2248
shell: bash
@@ -27,59 +53,145 @@ jobs:
2753
echo '::set-output name=BUILD::YES'
2854
else
2955
echo "Stable tag found; skipping all build steps"
30-
# Setting dummy tag evars to prevent steps below from failing
31-
echo "TAG1=clux/muslrust:no1" >> $GITHUB_ENV
32-
echo "TAG2=clux/muslrust:no2" >> $GITHUB_ENV
33-
echo "TAG3=clux/muslrust:no3" >> $GITHUB_ENV
3456
fi
3557
58+
- name: Prepare
59+
run: |
60+
platform=${{ matrix.platform }}
61+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
62+
63+
- name: Docker meta
64+
id: meta
65+
uses: docker/metadata-action@v5
66+
with:
67+
images: ${{ env.REGISTRY_IMAGE }}
68+
69+
- name: Set up QEMU
70+
uses: docker/setup-qemu-action@v3
71+
72+
- name: Set up Docker Buildx
73+
uses: docker/setup-buildx-action@v3
74+
3675
- name: Build stable image
76+
id: build
3777
uses: docker/build-push-action@v3
3878
with:
3979
context: .
80+
platforms: ${{ matrix.platform }}
81+
labels: ${{ steps.meta.outputs.labels }}
82+
file: ${{ matrix.dockerfile }}
83+
push: false
4084
load: true
85+
tags: rustmusl-temp
4186
build-args: |
4287
CHANNEL=stable
43-
tags: clux/muslrust:temp
4488
if: ${{ steps.stablecheck.outputs.BUILD }}
4589

46-
- name: Compute tags
90+
- name: Run tests
91+
if: ${{ steps.stablecheck.outputs.BUILD }}
4792
shell: bash
4893
run: |
49-
docker run clux/muslrust:temp rustc --version
50-
RUST_VER="$(docker run clux/muslrust:temp rustc --version | grep -oE "[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]")"
94+
docker buildx build --platform ${{ matrix.platform }} --output type=docker -t test-runner - < Dockerfile.test-runner
95+
TARGET_DIR=${{ matrix.target_dir }} PLATFORM=${{ matrix.platform }} just test
96+
97+
# The date/channel/version are expected to be the same on both architectures and are needed for the merge step.
98+
# We store them here since it makes the merge step a bit easier - it doesn't need to figure out which of the
99+
# architectures it can run (to extract the rust version). The problem is that it appears we can't run images
100+
# that were built by docker buildx (the build-push-action step) locally. They get pushed to dockerhub but are
101+
# only identifiable by their digest and it appears docker does not let us select an image that way.
102+
# Not the most elegant, but it works.
103+
- name: Store tag info
104+
if: ${{ steps.stablecheck.outputs.BUILD }}
105+
shell: bash
106+
run: |
107+
mkdir -p /tmp/tags
51108
RUST_DATE="$(date +"%Y-%m-%d")"
52109
RUST_CHANNEL=stable
53-
echo "TAG1=clux/muslrust:${RUST_CHANNEL}" >> $GITHUB_ENV
54-
echo "TAG2=clux/muslrust:${RUST_VER}-${RUST_CHANNEL}" >> $GITHUB_ENV
55-
echo "TAG3=clux/muslrust:${RUST_VER}" >> $GITHUB_ENV
56-
if: ${{ steps.stablecheck.outputs.BUILD }}
110+
RUST_VER="$(docker run --platform ${{ matrix.platform }} rustmusl-temp rustc --version | grep -oE "[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]")"
111+
112+
echo $RUST_DATE > /tmp/tags/rust-date
113+
echo $RUST_CHANNEL > /tmp/tags/rust-channel
114+
echo $RUST_VER > /tmp/tags/rust-ver
57115
58-
- name: Echo tags
116+
- name: Tag and push
117+
if: ${{ steps.stablecheck.outputs.BUILD }}
59118
shell: bash
60119
run: |
61-
echo $TAG1
62-
echo $TAG2
63-
echo $TAG3
120+
RUST_DATE=$(cat /tmp/tags/rust-date)
121+
RUST_CHANNEL=$(cat /tmp/tags/rust-channel)
122+
RUST_VER=$(cat /tmp/tags/rust-ver)
64123
65-
- name: Run tests
124+
TAG_NAME="${{ matrix.arch }}-${RUST_VER}-${RUST_CHANNEL}-${RUST_DATE}"
125+
126+
docker tag rustmusl-temp ${{ env.REGISTRY_IMAGE }}:$TAG_NAME
127+
docker push ${{ env.REGISTRY_IMAGE }}:$TAG_NAME
128+
129+
- name: Upload tags
130+
if: ${{ steps.stablecheck.outputs.BUILD }}
131+
uses: actions/upload-artifact@v4
132+
with:
133+
name: tags
134+
path: /tmp/tags
135+
if-no-files-found: error
136+
retention-days: 1
137+
overwrite: true
138+
139+
merge:
140+
name: 'Stable merge'
141+
runs-on: ubuntu-latest
142+
needs:
143+
- build
144+
steps:
145+
- uses: 'actions/checkout@v2'
146+
- name: Check if we need a new stable
147+
id: stablecheck
66148
shell: bash
149+
run: |
150+
pip3 install --user toml
151+
if python3 check_stable.py; then
152+
echo "Stable tag missing; running all build steps"
153+
echo '::set-output name=BUILD::YES'
154+
else
155+
echo "Stable tag found; skipping all build steps"
156+
fi
157+
158+
- name: Download tags
67159
if: ${{ steps.stablecheck.outputs.BUILD }}
68-
run: just test
160+
uses: actions/download-artifact@v4
161+
with:
162+
path: /tmp/tags
163+
name: tags
69164

70-
- name: Login to DockerHub
71-
if: github.event_name != 'pull_request'
72-
uses: docker/login-action@v1
165+
- name: Set up Docker Buildx
166+
uses: docker/setup-buildx-action@v3
167+
168+
- name: Docker meta
169+
id: meta
170+
uses: docker/metadata-action@v5
171+
with:
172+
images: ${{ env.REGISTRY_IMAGE }}
173+
174+
- name: Login to Docker Hub
175+
uses: docker/login-action@v3
176+
if: false
73177
with:
74178
username: clux
75179
password: ${{ secrets.DOCKERHUB_TOKEN }}
76180

77-
- name: Push image under computed tags
78-
uses: docker/build-push-action@v3
181+
- name: Create manifest list and push multi-platform images
79182
if: ${{ steps.stablecheck.outputs.BUILD }}
80-
with:
81-
context: .
82-
build-args: |
83-
CHANNEL=stable
84-
push: ${{ steps.stablecheck.outputs.BUILD == 'YES' && github.event_name != 'pull_request' }}
85-
tags: ${{ env.TAG1 }},${{ env.TAG2 }},${{ env.TAG3 }}
183+
run: |
184+
RUST_DATE=$(cat /tmp/tags/rust-date)
185+
RUST_CHANNEL=$(cat /tmp/tags/rust-channel)
186+
RUST_VER=$(cat /tmp/tags/rust-ver)
187+
188+
for tag in ${RUST_CHANNEL} ${RUST_CHANNEL}-${RUST_DATE} ${RUST_VER}-${RUST_CHANNEL}-${RUST_DATE}; do
189+
docker buildx imagetools create -t ${{ env.REGISTRY_IMAGE }}:$tag \
190+
${{ env.REGISTRY_IMAGE }}:amd64-${RUST_VER}-${RUST_CHANNEL}-${RUST_DATE} \
191+
${{ env.REGISTRY_IMAGE }}:arm64-${RUST_VER}-${RUST_CHANNEL}-${RUST_DATE}
192+
done
193+
194+
- name: Inspect image
195+
if: ${{ steps.stablecheck.outputs.BUILD }}
196+
run: |
197+
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:latest

0 commit comments

Comments
 (0)