1
# Build the manager binary
2
FROM docker.io/golang:1.23 AS builder
3
ARG TARGETOS
4
ARG TARGETARCH
5
6
WORKDIR /workspace
7
# Copy the Go Modules manifests
8
COPY go.mod go.mod
9
COPY go.sum go.sum
10
# cache deps before building and copying source so that we don't need to re-download as much
11
# and so that source changes don't invalidate our downloaded layer
12
RUN go mod download
13
14
# Copy the go source
15
COPY cmd/enbi/main.go cmd/enbi/main.go
16
COPY api/ api/
17
COPY internal/ internal/
18
19
# Build
20
# the GOARCH has not a default value to allow the binary be built according to the host where the command
21
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
22
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
23
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
24
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o enbi cmd/enbi/main.go
25
26
# Use distroless as minimal base image to package the manager binary
27
# Refer to https://github.com/GoogleContainerTools/distroless for more details
28
FROM gcr.io/distroless/static:nonroot
29
WORKDIR /
30
COPY --from=builder /workspace/enbi .
31
USER 65532:65532
32
33
ENTRYPOINT ["/enbi"]
34