This repository has been archived by the owner on Dec 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
75 lines (59 loc) · 2.38 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Build the manager binary
FROM --platform=$BUILDPLATFORM golang:1.19.1 as builder
ARG GOARCH=''
ARG GITHUB_PAT=''
WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
COPY hack hack
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
go mod download
# Copy the go source
COPY api/ api/
COPY broker broker/
COPY client/ client/
COPY controllers/ controllers/
COPY handler/ handler/
COPY hash/ hash/
COPY index/ index/
COPY machinebrokerlet/ machinebrokerlet/
COPY multicluster/ multicluster/
COPY partitionlet/ partitionlet/
COPY predicate/ predicate/
COPY proxyvolumebrokerlet/ proxyvolumebrokerlet/
COPY volumebrokerlet/ volumebrokerlet
ARG TARGETOS TARGETARCH
RUN mkdir bin
# Build
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/machinebrokerlet ./machinebrokerlet && \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/partitionlet ./partitionlet && \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/proxyvolumebrokerlet ./proxyvolumebrokerlet && \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o bin/volumebrokerlet ./volumebrokerlet
# Use distroless as minimal base image to package any controller binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot as machinebrokerlet
WORKDIR /
COPY --from=builder /workspace/bin/machinebrokerlet /manager
USER 65532:65532
ENTRYPOINT ["/manager"]
FROM gcr.io/distroless/static:nonroot as partitionlet
WORKDIR /
COPY --from=builder /workspace/bin/partitionlet /manager
USER 65532:65532
ENTRYPOINT ["/manager"]
FROM gcr.io/distroless/static:nonroot as proxyvolumebrokerlet
WORKDIR /
COPY --from=builder /workspace/bin/proxyvolumebrokerlet /manager
USER 65532:65532
ENTRYPOINT ["/manager"]
FROM gcr.io/distroless/static:nonroot as volumebrokerlet
WORKDIR /
COPY --from=builder /workspace/bin/volumebrokerlet /manager
USER 65532:65532
ENTRYPOINT ["/manager"]