Skip to content

Commit 9bfb7cd

Browse files
committed
Support for multi-arch (x86 + ARM64) images
1 parent 58d38d5 commit 9bfb7cd

File tree

2 files changed

+86
-39
lines changed

2 files changed

+86
-39
lines changed

.github/workflows/ci.yml

+83-38
Original file line numberDiff line numberDiff line change
@@ -5,92 +5,137 @@ on: [push, pull_request]
55
jobs:
66
build-bin:
77
name: bin
8-
runs-on: ubuntu-22.04-xl
8+
runs-on: ubuntu-latest
99
steps:
1010
- name: Clone repository
1111
uses: actions/checkout@v4
12+
13+
- name: Cache docker registry
14+
uses: actions/cache@v3
15+
with:
16+
key: registry-${{ github.sha }}
17+
path: ${{ runner.temp }}/registry
18+
19+
- name: Cache Docker layers
20+
uses: actions/cache@v2
21+
with:
22+
path: /tmp/.buildx-cache
23+
# Key is named differently to avoid collision
24+
key: ${{ runner.os }}-multi-buildx-${{ github.sha }}
25+
restore-keys: |
26+
${{ runner.os }}-multi-buildx
1227
13-
- name: Build and export image
28+
- name: Start local Docker registry
1429
run: |
15-
docker build -f bin.dockerfile -t bin .
16-
docker save bin -o /tmp/bin-image.tar
30+
# Docker save / load does not support multi-arch images.
31+
# This sets up a local registry that I can push the images to.
32+
docker run -d -p 5000:5000 -e 'REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/var/lib/registry' -v '${{ runner.temp }}/registry:/var/lib/registry' registry:2
33+
34+
- name: Set up QEMU
35+
uses: docker/setup-qemu-action@v3
1736

18-
- name: Upload artifact
19-
uses: actions/upload-artifact@v4
37+
- name: Set up Docker Buildx
38+
uses: docker/setup-buildx-action@v3
2039
with:
21-
name: bin-image
22-
path: /tmp/bin-image.tar
40+
driver-opts: network=host
41+
42+
- name: Build image
43+
run: |
44+
docker buildx build -f bin.dockerfile --platform=linux/amd64,linux/arm64 -t localhost:5000/bin --push .
2345
2446
build:
2547
needs: build-bin
2648
name: ${{ matrix.kind }}
27-
runs-on: ubuntu-22.04-xl
49+
runs-on: ubuntu-latest
2850
strategy:
2951
matrix:
3052
kind: ["alpine", "centos", "debian", "distroless", "ubuntu"]
3153
steps:
3254
- name: Clone repository
3355
uses: actions/checkout@v4
56+
57+
- name: Cache docker registry
58+
uses: actions/cache@v3
59+
with:
60+
key: registry-${{ github.sha }}
61+
fail-on-cache-miss: true
62+
path: ${{ runner.temp }}/registry
3463

35-
- name: Download bin image artifact
36-
uses: actions/download-artifact@v4
64+
- name: Cache Docker layers
65+
uses: actions/cache@v2
3766
with:
38-
name: bin-image
39-
path: /tmp
67+
path: /tmp/.buildx-cache
68+
# Key is named differently to avoid collision
69+
key: ${{ runner.os }}-multi-buildx-${{ github.sha }}
70+
restore-keys: |
71+
${{ runner.os }}-multi-buildx
4072
41-
- name: Load bin image
73+
- name: Start local Docker registry
4274
run: |
43-
docker load --input /tmp/bin-image.tar
44-
docker inspect bin
75+
# Docker save / load does not support multi-arch images.
76+
# This sets up a local registry that I can push the images to.
77+
docker run -d -p 5000:5000 -e 'REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/var/lib/registry' -v '${{ runner.temp }}/registry:/var/lib/registry' registry:2
78+
79+
- name: Set up QEMU
80+
uses: docker/setup-qemu-action@v3
81+
82+
- name: Set up Docker Buildx
83+
uses: docker/setup-buildx-action@v3
84+
with:
85+
driver-opts: network=host
4586

4687
- name: Build image
4788
run: |
48-
docker build -f ${{ matrix.kind }}.dockerfile --build-arg BIN_IMAGE=bin -t ${{ matrix.kind }} .
89+
docker buildx build -f ${{ matrix.kind }}.dockerfile --platform=linux/amd64,linux/arm64 --build-arg BIN_IMAGE=localhost:5000/bin -t localhost:5000/${{ matrix.kind }} --push .
4990
5091
- name: Test default CMD
5192
run: |
52-
docker run -t ${{ matrix.kind }}
93+
docker run -t localhost:5000/${{ matrix.kind }}
5394
5495
- name: Test if entry script forwards to deno binary
5596
run: |
56-
docker run -t ${{ matrix.kind }} eval "console.log('Welcome to Deno!')"
97+
docker run -t localhost:5000/${{ matrix.kind }} eval "console.log('Welcome to Deno!')"
5798
5899
# if typescript is present in the output, then probably deno --version worked
59-
docker run -t ${{ matrix.kind }} --version | grep typescript
100+
docker run -t localhost:5000/${{ matrix.kind }} --version | grep typescript
60101
61102
- name: Test if entry script forwards to other binaries
62103
if: ${{ matrix.kind != 'distroless' }}
63104
run: |
64-
docker run -t ${{ matrix.kind }} deno eval "console.log('Welcome to Deno!')"
65-
docker run -t ${{ matrix.kind }} echo 'test entry script'
105+
docker run -t localhost:5000/${{ matrix.kind }} deno eval "console.log('Welcome to Deno!')"
106+
docker run -t localhost:5000/${{ matrix.kind }} echo 'test entry script'
107+
108+
- name: Print image information
109+
if: ${{ matrix.kind == 'debian' }}
110+
run: |
111+
docker buildx imagetools inspect localhost:5000/${{ matrix.kind }}
112+
113+
echo "x86..."
114+
115+
docker run --rm --platform linux/amd64 localhost:5000/${{ matrix.kind }} sh -c 'apt-get update -y && apt-get install -y file && file /usr/bin/deno'
116+
117+
118+
echo "ARM..."
119+
docker run --rm --platform linux/arm64 localhost:5000/${{ matrix.kind }} sh -c 'apt-get update -y && apt-get install -y file && file /usr/bin/deno'
66120
67121
- name: Login to Docker Hub
68-
if: github.repository == 'denoland/deno_docker' && startsWith(github.ref, 'refs/tags/')
122+
if: github.repository == 'denoland/deno_docker' && github.ref_type == 'tag'
69123
uses: docker/login-action@v3
70124
with:
71125
username: ${{ secrets.DOCKERHUB_USERNAME }}
72126
password: ${{ secrets.DOCKERHUB_PASSWORD }}
73127

74128
- name: Push named images
75-
if: github.repository == 'denoland/deno_docker' && startsWith(github.ref, 'refs/tags/')
129+
if: github.repository == 'denoland/deno_docker' && github.ref_type == 'tag'
76130
run: |
77-
docker tag ${{ matrix.kind }} denoland/deno:${{ matrix.kind }}-${GITHUB_REF#refs/*/}
78-
docker tag ${{ matrix.kind }} denoland/deno:${{ matrix.kind }}
79-
docker push denoland/deno:${{ matrix.kind }}-${GITHUB_REF#refs/*/}
80-
docker push denoland/deno:${{ matrix.kind }}
131+
docker buildx imagetools create localhost:5000/${{ matrix.kind }} -t denoland/deno:${{ matrix.kind }}-${{ github.ref_name }} -t denoland/deno:${{ matrix.kind }}
81132
82133
- name: Push bin image
83-
if: github.repository == 'denoland/deno_docker' && startsWith(github.ref, 'refs/tags/') && matrix.kind == 'debian'
134+
if: github.repository == 'denoland/deno_docker' && github.ref_type == 'tag' && matrix.kind == 'debian'
84135
run: |
85-
docker tag bin denoland/deno:bin-${GITHUB_REF#refs/*/}
86-
docker tag bin denoland/deno:bin
87-
docker push denoland/deno:bin-${GITHUB_REF#refs/*/}
88-
docker push denoland/deno:bin
136+
docker buildx imagetools create localhost:5000/bin -t denoland/deno:bin-${{ github.ref_name }} -t denoland/deno:bin
89137
90138
- name: Push default image
91-
if: github.repository == 'denoland/deno_docker' && startsWith(github.ref, 'refs/tags/') && matrix.kind == 'debian'
139+
if: github.repository == 'denoland/deno_docker' && github.ref_type == 'tag' && matrix.kind == 'debian'
92140
run: |
93-
docker tag ${{ matrix.kind }} denoland/deno:${GITHUB_REF#refs/*/}
94-
docker tag ${{ matrix.kind }} denoland/deno:latest
95-
docker push denoland/deno:${GITHUB_REF#refs/*/}
96-
docker push denoland/deno:latest
141+
docker buildx imagetools create localhost:5000/${{ matrix.kind }} -t denoland/deno:${{ matrix.kind }}-${{ github.ref_name }} -t denoland/deno:latest

bin.dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ RUN export DEBIAN_FRONTEND=noninteractive \
99
&& rm -rf /var/lib/apt/lists/*
1010

1111
ARG DENO_VERSION
12-
RUN curl -fsSL https://github.com/denoland/deno/releases/download/v${DENO_VERSION}/deno-x86_64-unknown-linux-gnu.zip \
12+
ARG TARGETARCH
13+
14+
RUN curl -fsSL https://github.com/denoland/deno/releases/download/v${DENO_VERSION}/deno-$(echo $TARGETARCH | sed -e 's/arm64/aarch64/' -e 's/amd64/x86_64/')-unknown-linux-gnu.zip \
1315
--output deno.zip \
1416
&& unzip deno.zip \
1517
&& rm deno.zip \

0 commit comments

Comments
 (0)