-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDockerfile
More file actions
29 lines (21 loc) · 1.15 KB
/
Copy pathDockerfile
File metadata and controls
29 lines (21 loc) · 1.15 KB
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
# ── Build stage ──────────────────────────────────────────────────────────────
# BUILDPLATFORM is the host platform (where docker build runs).
# TARGETPLATFORM / TARGETOS / TARGETARCH describe the image being produced.
FROM --platform=$BUILDPLATFORM golang:1.22-alpine AS builder
ARG TARGETOS=linux
ARG TARGETARCH=amd64
WORKDIR /workspace
# Cache dependency downloads separately from source changes.
COPY go.mod go.sum ./
RUN go mod download
COPY cmd/ cmd/
COPY api/ api/
COPY internal/ internal/
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -a -ldflags="-s -w" -o bin/operator ./cmd/operator/...
# ── Runtime stage ─────────────────────────────────────────────────────────────
# distroless/static:nonroot already runs as UID 65532 — no USER override needed.
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/bin/operator .
ENTRYPOINT ["/operator"]