From c0778c8adb2541cef002723fc93b163eea7bd1df Mon Sep 17 00:00:00 2001 From: Stephan Seifermann <9149072+seiferma@users.noreply.github.com> Date: Fri, 2 Oct 2026 11:49:32 +0200 Subject: [PATCH] Docker: provide images for amd64 and arm64 (#13) The connector is cross-compiled with tonistiigi/xx on the build platform (pinned by digest); web-builder and gateway-builder also run natively there since their output is platform-independent JS. Only the runtime stage runs per target platform. README mentions the arm64 image. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU --- .github/workflows/docker-publish.yml | 4 ++++ Dockerfile | 31 ++++++++++++++++++++-------- README.md | 2 +- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 5601ade..c7c9dfc 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -24,6 +24,9 @@ jobs: with: submodules: recursive + - name: Set up QEMU + uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3 @@ -53,5 +56,6 @@ jobs: context: . push: true tags: ${{ steps.tags.outputs.tags }} + platforms: linux/amd64,linux/arm64 cache-from: type=gha cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile index 6238d26..5a9bd50 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,37 @@ # --- Rust connector ----------------------------------------------------- -FROM rust:1-bookworm AS connector-builder -RUN apt-get update && apt-get install -y --no-install-recommends cmake && rm -rf /var/lib/apt/lists/* +# Cross-compiled on the build machine for the target platform via xx, so an +# arm64 image doesn't have to run rustc under QEMU. xx is copied into the +# builder's root, hence pinned by digest rather than a movable tag. +FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.9.0@sha256:c64defb9ed5a91eacb37f96ccc3d4cd72521c4bd18d5442905b95e2226b0e707 AS xx +FROM --platform=$BUILDPLATFORM rust:1-bookworm AS connector-builder +COPY --from=xx / / +ARG TARGETPLATFORM +RUN apt-get update && apt-get install -y --no-install-recommends cmake clang && rm -rf /var/lib/apt/lists/* +RUN xx-apt-get update && xx-apt-get install -y libc6-dev gcc g++ && rm -rf /var/lib/apt/lists/* +RUN rustup target add $(xx-cargo --print-target-triple) WORKDIR /src COPY tsclientlib/ tsclientlib/ COPY connector/ connector/ WORKDIR /src/connector ENV CMAKE_POLICY_VERSION_MINIMUM=3.5 -RUN cargo build --release +RUN xx-cargo build --release # --- Web frontend --------------------------------------------------------- -FROM node:22-bookworm-slim AS web-builder +# The bundle is plain JS/CSS, identical for every target platform - build it +# natively on the build machine instead of under emulation. +FROM --platform=$BUILDPLATFORM node:22-bookworm-slim AS web-builder WORKDIR /src/web COPY web/package*.json ./ RUN npm ci # Vite 8 pulls in Rolldown, which ships its bundler as a platform-specific -# optional dependency (@rolldown/binding-linux-x64-gnu here). `npm ci` -# intermittently fails to install it due to a long-standing npm bug +# optional dependency (@rolldown/binding-linux--gnu, being +# Node's process.arch). `npm ci` intermittently fails to install it due to a +# long-standing npm bug # (https://github.com/npm/cli/issues/4828) without raising a non-zero exit # code, so `vite build` only fails later with a confusing MODULE_NOT_FOUND. # Verify the binding actually loaded and self-heal via the workaround from # npm's own error message before wasting a full build on a broken install. -RUN node -e "require('@rolldown/binding-linux-x64-gnu')" \ +RUN node -e "require('@rolldown/binding-linux-' + process.arch + '-gnu')" \ || (rm -rf node_modules package-lock.json && npm install) COPY web/ ./ # The UI carries a small Ko-fi donation button (see web/src/App.tsx). @@ -45,7 +56,9 @@ RUN if [ "$DONATE_URL" = "keep" ]; then DONATE_URL_ENV=; else DONATE_URL_ENV="VI env $DONATE_URL_ENV VITE_DEFAULT_SERVER="$DEFAULT_SERVER" VITE_DEFAULT_CHANNEL="$DEFAULT_CHANNEL" VITE_STORE_URL="$STORE_URL" npx vite build # --- Gateway ---------------------------------------------------------------- -FROM node:22-bookworm-slim AS gateway-builder +# tsc output is platform-independent too; only the runtime stage below +# installs the (pure-JS) production deps for the target platform. +FROM --platform=$BUILDPLATFORM node:22-bookworm-slim AS gateway-builder WORKDIR /src/gateway COPY gateway/package*.json ./ RUN npm ci @@ -73,7 +86,7 @@ RUN npm ci --omit=dev \ && rm -rf /root/.npm /usr/local/lib/node_modules/npm \ && rm -f /usr/local/bin/npm /usr/local/bin/npx COPY --from=gateway-builder /src/gateway/dist ./dist -COPY --from=connector-builder /src/connector/target/release/ts-connector /app/connector-bin/ts-connector +COPY --from=connector-builder /src/connector/target/*/release/ts-connector /app/connector-bin/ts-connector COPY --from=web-builder /src/web/dist /app/web/dist ENV PORT=8080 diff --git a/README.md b/README.md index 0c10efd..34e8687 100644 --- a/README.md +++ b/README.md @@ -172,7 +172,7 @@ services: Then `docker compose up -d` and open `http://localhost:8080` (or whatever host port you chose). -Prefer to skip the build entirely? A prebuilt image is published on [Docker Hub](https://hub.docker.com/r/moepchi/webspeak3): +Prefer to skip the build entirely? A prebuilt image for `linux/amd64` and `linux/arm64` (e.g. a Raspberry Pi 4/5 on a 64-bit OS) is published on [Docker Hub](https://hub.docker.com/r/moepchi/webspeak3): ```bash docker run -d -p 8080:8080 --name webspeak3 moepchi/webspeak3:latest