-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile.multistage
48 lines (40 loc) · 1.34 KB
/
Dockerfile.multistage
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
40
41
42
43
44
45
46
47
48
# build args
ARG GOLANG_VERSION=1.19.2
# Build the log2rbac binary
# docker.io/golang:1.19.2
FROM docker.io/golang@sha256:fcae9e0e7313c6467a7c6632ebb5e5fab99bd39bd5eb6ee34a211353e647827a as builder
ARG GIT_SHA=unknown
ARG VERSION=unknown
WORKDIR /workspace
COPY go.mod go.mod
COPY go.sum go.sum
RUN go mod download
# Copy the go source
COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/
COPY internal/ internal/
ENV GOLANG_VERSION=${GOLANG_VERSION} \
GIT_SHA=${GIT_SHA} \
VERSION=${VERSION}
# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-w -s -X main.gitSha=${GIT_SHA} -X main.version=${VERSION}" -a -o log2rbac main.go
# Use distroless as minimal base image to package the log2rbac (manager) binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
# gcr.io/distroless/static:static
FROM gcr.io/distroless/static@sha256:41972110a1c1a5c0b6adb283e8aa092c43c31f7c5d79b8656fbffff2c3e61f05
ARG GOLANG_VERSION
ARG GIT_SHA
ARG VERSION
LABEL BASE_IMAGE="gcr.io/distroless/static:nonroot" \
GOLANG_VERSION=${GOLANG_VERSION} \
GIT_SHA=${GIT_SHA} \
VERSION=${VERSION}
ENV GOLANG_VERSION=${GOLANG_VERSION} \
GIT_SHA=${GIT_SHA} \
VERSION=${VERSION}
WORKDIR /
COPY --from=builder /workspace/log2rbac .
USER 65532:65532
ENTRYPOINT ["/log2rbac"]
CMD ["--zap-encoder=console"]