forked from kubernetes-sigs/hierarchical-namespaces
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
26 lines (22 loc) · 867 Bytes
/
Dockerfile
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
# Build the manager binary
FROM golang:1.20 as builder
WORKDIR /workspace
# Copy the Go Modules manifests and all third-party libraries that are unlikely to change frequently
COPY go.mod go.mod
COPY go.sum go.sum
COPY vendor/ vendor/
# Copy the go source
COPY api/ api/
COPY cmd/ cmd/
COPY internal/ internal/
# Build
RUN CGO_ENABLED=0 GO111MODULE=on go build -a -o manager ./cmd/manager/main.go
# Copied from kubebuilder scaffold to run as nonroot at
# https://github.com/kubernetes-sigs/kubebuilder/blob/7af89cb00c224c57ece37dc14ea37caf1eb769db/pkg/scaffold/v2/dockerfile.go#L60
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager .
USER nonroot:nonroot
ENTRYPOINT ["/manager"]