Skip to content

Commit

Permalink
docker: Add arm64 builds to Dockerfile and CI
Browse files Browse the repository at this point in the history
Convert Dockerfile so multiple target architecturebuilds are possible. Also
modify the CI pipeline, in order to built a single multi-platform container.

Note that at the current time-being docker cannot export multi-platform
containers without an intermediate registry. Thus only the amd64 image
is exported for the test stage. Nevertheless the arm64 image is built in
the pipeline and also published later to the registry.

Co-authored-by: Thomas Böhler <t.boehler@kunbus.com>
Signed-off-by: Nicolai Buchwitz <n.buchwitz@kunbus.com>
  • Loading branch information
nbuchwitz and tboehler1 committed Aug 19, 2024
1 parent 25468f1 commit d77997b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ jobs:
- name: Repository checkout
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3

Expand All @@ -67,6 +70,26 @@ jobs:
push: false
pull: true
file: docker/Dockerfile
platforms: linux/amd64,linux/arm64
tags: debos
cache-from: type=local,src=/tmp/.build-cache
cache-to: type=local,dest=/tmp/.build-cache,mode=max

# WORKAROUND:
# Docker buildx cannot export multi-platform images with type=docker,
# but only with type=oci. The latter cannot be imported without an
# intermediate registry. Thus export only the amd64 image for usage
# in the test stage.
#
# see https://docs.docker.com/reference/cli/docker/buildx/build/#docker
- name: Export amd64 Docker image for later usage
uses: docker/build-push-action@v6
with:
context: .
push: false
pull: true
file: docker/Dockerfile
platforms: linux/amd64
tags: debos
cache-from: type=local,src=/tmp/.build-cache
cache-to: type=local,dest=/tmp/.build-cache,mode=max
Expand Down Expand Up @@ -158,6 +181,7 @@ jobs:
with:
name: debos-image
path: /tmp

- name: Load image
run: |
docker load --input /tmp/debos-image.tar
Expand Down Expand Up @@ -241,6 +265,7 @@ jobs:
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: docker/Dockerfile
Expand Down Expand Up @@ -320,6 +345,7 @@ jobs:
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: docker/Dockerfile
Expand Down
25 changes: 20 additions & 5 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Global ARGs shared by all stages
ARG ARCH=
ARG DEBIAN_FRONTEND=noninteractive
ARG GOPATH=/usr/local/go

### first stage - builder ###
FROM debian:bookworm-slim as builder
FROM ${ARCH}debian:bookworm-slim AS builder

ARG DEBIAN_FRONTEND
ARG GOPATH
Expand Down Expand Up @@ -34,7 +35,24 @@ COPY docker/get-archlinux-keyring.sh /
RUN /get-archlinux-keyring.sh /arch-keyring

### second stage - runner ###
FROM debian:bookworm-slim as runner
FROM ${ARCH}debian:bookworm-slim AS runner-amd64
RUN apt-get update && \
apt-get install -y --no-install-recommends \
linux-image-amd64 \
qemu-system-x86 \
user-mode-linux && \
rm -rf /var/lib/apt/lists/*

FROM ${ARCH}debian:bookworm-slim AS runner-arm64
RUN apt-get update && \
apt-get install -y --no-install-recommends \
linux-image-arm64 \
qemu-system-arm \
# fixes: qemu-system-aarch64: failed to find romfile "efi-virtio.rom"
ipxe-qemu && \
rm -rf /var/lib/apt/lists/*

FROM runner-${TARGETARCH} AS runner

ARG DEBIAN_FRONTEND
ARG GOPATH
Expand Down Expand Up @@ -78,11 +96,9 @@ RUN apt-get update && \
pigz \
libostree-1-1 \
libslirp-helper \
linux-image-amd64 \
openssh-client \
parted \
pkg-config \
qemu-system-x86 \
qemu-user-static \
qemu-utils \
rsync \
Expand All @@ -91,7 +107,6 @@ RUN apt-get update && \
systemd-resolved \
u-boot-tools \
unzip \
user-mode-linux \
xfsprogs \
xz-utils \
zip \
Expand Down

0 comments on commit d77997b

Please sign in to comment.