Build with xx cross-compile and run on scratch-rootless image

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Jonas Leder 2026-11-09 17:37:59 +01:00
commit 58a57bb2e6
2 changed files with 12 additions and 8 deletions

View file

@ -2,4 +2,5 @@
data
.env
deploy
bin
*.md

View file

@ -1,15 +1,18 @@
# syntax=docker/dockerfile:1
FROM golang:1.27 AS build
WORKDIR /src
FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.9.0 AS xx
FROM --platform=$BUILDPLATFORM golang:1.27-alpine AS build
ARG TARGETPLATFORM
ARG VERSION=dev
COPY --from=xx / /
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
ARG VERSION=dev
RUN CGO_ENABLED=0 go build -trimpath -ldflags "-s -w -X main.version=${VERSION}" -o /out/adblock-dns ./cmd/adblock-dns
RUN CGO_ENABLED=0 GOOS=linux xx-go build -trimpath -ldflags "-w -s -X main.version=${VERSION}" -o /adblock-dns ./cmd/adblock-dns
# static, no shell, runs as uid 65532 – listens on unprivileged ports only
FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /out/adblock-dns /adblock-dns
USER 65532:65532
# static, no shell, non-root; listens on unprivileged ports only (5353, 8853, 8443, 9153, 8080)
FROM jonasled.dev/infra/images/scratch-rootless:latest@sha256:8c33ba4e489ce0decd60f00ce63af60994b9b72cd39668284daea8eae1d809b7
COPY --from=build /adblock-dns /adblock-dns
ENV DATA_DIR=/data
EXPOSE 5353/udp 5353/tcp 8853 8443 9153 8080
ENTRYPOINT ["/adblock-dns"]