-
Notifications
You must be signed in to change notification settings - Fork 3
/
Dockerfile
39 lines (30 loc) · 1.02 KB
/
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
27
28
29
30
31
32
33
34
35
36
37
38
39
# syntax=docker/dockerfile:1.1-experimental
# Build the manager binary
ARG GOVER=1.19.1
FROM --platform=$BUILDPLATFORM golang:${GOVER} as builder
ARG TARGETPLATFORM
ARG BUILDPLATFORM
WORKDIR /workspace
# Run this with docker build --build_arg $(go env GOPROXY) to override the goproxy
ARG goproxy=https://proxy.golang.org
ENV GOPROXY=$goproxy
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .
# Build
ARG TARGETARCH
ARG LDFLAGS
ARG BINARY=cloud-provider-phoenixnap
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} \
go build -a -ldflags "${LDFLAGS} -extldflags '-static'" \
-o "${BINARY}" .
# because you cannot use ARG or ENV in CMD when in [] mode
# 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 /
ARG BINARY=cloud-provider-phoenixnap
COPY --from=builder /workspace/${BINARY} ./cloud-provider-phoenixnap
USER nonroot:nonroot
ENTRYPOINT ["./cloud-provider-phoenixnap"]