-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathDockerfile
More file actions
33 lines (23 loc) · 982 Bytes
/
Dockerfile
File metadata and controls
33 lines (23 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# syntax=docker/dockerfile:1
# multi-stage build: cross-compile on builder platform, ship in scratch
# NB: --platform=$BUILDPLATFORM keeps the Go compiler native (no QEMU needed for build)
FROM --platform=$BUILDPLATFORM golang:1.26-alpine AS builder
ARG TARGETOS TARGETARCH TARGETVARIANT
ARG BUILD_VERSION=dev
WORKDIR /build
# fetch dependencies first (cached layer)
COPY go.mod go.sum ./
RUN go mod download
# cross-compile static binary
COPY . .
RUN GOARM="$(echo ${TARGETVARIANT} | tr -d v)" \
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOARM="${GOARM}" \
go build -ldflags="-s -w -X main.BuildVersion=${BUILD_VERSION}" -trimpath -o bgpipe .
# ---
# scratch: zero base overhead; ca-certificates copied from builder
FROM scratch
# ca-certificates: needed for HTTPS URLs (MRT archives, RPKI validators)
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /build/bgpipe /bgpipe
ENTRYPOINT ["/bgpipe"]
CMD ["--help"]