From e999e353f7686029061ba9e30fd2c00c0c8b6cc8 Mon Sep 17 00:00:00 2001 From: Reactorcoremeltdown Date: Mon, 2 Nov 2026 16:44:42 +0100 Subject: [PATCH] Fixed cross-compilation --- Dockerfile | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9b09d76..981cabd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,18 +19,24 @@ FROM golang:1.26-alpine AS build ARG VERSION=dev +# The platform being built for, so `go build` cross-compiles to it rather than to +# the builder's own architecture. +ARG TARGETOS +ARG TARGETARCH WORKDIR /src # Only what the server is built from, so a change to the clients, the # Android app or the docs does not invalidate this layer. COPY go.mod go.sum ./ -RUN go mod download +RUN --mount=type=cache,target=/go/pkg/mod \ + go mod download COPY cmd/keeporgd ./cmd/keeporgd COPY internal ./internal -RUN CGO_ENABLED=0 GOOS=linux go build \ - -trimpath \ - -ldflags "-s -w -X main.Version=${VERSION}" \ +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -trimpath \ + -ldflags="-s -w -X main.version=${APP_VERSION}" \ -o /out/keeporgd ./cmd/keeporgd # Empty directories to copy into the scratch image with the right owner.