From 57c78e65ba8b0066b179ce48573fd62429ff1d97 Mon Sep 17 00:00:00 2001 From: Siddharth Kumar Sah Date: Wed, 15 Apr 2026 23:11:47 +0800 Subject: [PATCH] fix(docker): use BUILDPLATFORM for caire to fix amd64 cross-compilation on Apple Silicon MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The caire-builder stage now runs the Go toolchain on the native build platform instead of under QEMU emulation. For cross-arch builds (arm64 host → amd64 image) CGO_ENABLED=0 avoids needing a full C cross-toolchain; the display window is unused in server mode anyway. The binary is staged to /tmp/caire so the COPY path is stable across both native and cross-compiled builds. --- docker/Dockerfile | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 5186f982..d997f8e1 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -38,16 +38,35 @@ RUN --mount=type=cache,id=turbo-cache,target=/app/.turbo \ # ============================================ # Stage 2: Build caire (content-aware resize) # ============================================ -FROM golang:1.23-bookworm AS caire-builder +# Run the Go toolchain on the native build platform to avoid QEMU crashes +# on Apple Silicon when cross-compiling for linux/amd64. +FROM --platform=$BUILDPLATFORM golang:1.23-bookworm AS caire-builder -RUN apt-get update && apt-get install -y --no-install-recommends \ - libwayland-dev libx11-dev libx11-xcb-dev libxkbcommon-x11-dev \ - libgles2-mesa-dev libegl1-mesa-dev libffi-dev libxcursor-dev \ - libxrandr-dev libxinerama-dev libxi-dev libxxf86vm-dev \ - libvulkan-dev libxfixes-dev pkg-config \ - && rm -rf /var/lib/apt/lists/* +ARG TARGETOS=linux +ARG TARGETARCH -RUN go install github.com/esimov/caire/cmd/caire@v1.5.0 +# Graphics libs are only needed for native-arch CGO builds (the display window). +# For cross-arch builds we use CGO_ENABLED=0 — the server never shows a display. +RUN NATIVE=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/') && \ + if [ "$TARGETARCH" = "$NATIVE" ]; then \ + apt-get update && apt-get install -y --no-install-recommends \ + libwayland-dev libx11-dev libx11-xcb-dev libxkbcommon-x11-dev \ + libgles2-mesa-dev libegl1-mesa-dev libffi-dev libxcursor-dev \ + libxrandr-dev libxinerama-dev libxi-dev libxxf86vm-dev \ + libvulkan-dev libxfixes-dev pkg-config \ + && rm -rf /var/lib/apt/lists/*; \ + fi + +# Build and copy to a fixed path so the COPY step below is always the same. +RUN NATIVE=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/') && \ + if [ "$TARGETARCH" = "$NATIVE" ]; then \ + go install github.com/esimov/caire/cmd/caire@v1.5.0 && \ + cp /go/bin/caire /tmp/caire; \ + else \ + CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \ + go install github.com/esimov/caire/cmd/caire@v1.5.0 && \ + cp /go/bin/${TARGETOS}_${TARGETARCH}/caire /tmp/caire; \ + fi # ============================================ # Stage 3: Platform-specific base images @@ -106,7 +125,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ && rm -rf /var/lib/apt/lists/* # Caire binary (content-aware seam carving) -COPY --from=caire-builder /go/bin/caire /usr/local/bin/caire +COPY --from=caire-builder /tmp/caire /usr/local/bin/caire # Python venv - Layer 1: Base packages (rarely change, ~3 GB) RUN python3 -m venv /opt/venv && \