github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/docker/Dockerfile-dataprotection (about) 1 # Build the dataprotection binary 2 ARG DIST_IMG=gcr.io/distroless/static:nonroot 3 4 ARG GO_VERSION=1.21 5 6 FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} as builder 7 8 ## docker buildx build injected build-args: 9 #BUILDPLATFORM — matches the current machine. (e.g. linux/amd64) 10 #BUILDOS — os component of BUILDPLATFORM, e.g. linux 11 #BUILDARCH — e.g. amd64, arm64, riscv64 12 #BUILDVARIANT — used to set ARM variant, e.g. v7 13 #TARGETPLATFORM — The value set with --platform flag on build 14 #TARGETOS - OS component from --platform, e.g. linux 15 #TARGETARCH - Architecture from --platform, e.g. arm64 16 #TARGETVARIANT 17 18 ARG TARGETOS 19 ARG TARGETARCH 20 21 ARG GOPROXY 22 #ARG GOPROXY=https://goproxy.cn 23 ARG LD_FLAGS="-s -w" 24 25 ENV GOPROXY=${GOPROXY} 26 27 WORKDIR /src 28 # Copy the Go Modules manifests 29 COPY go.mod go.mod 30 COPY go.sum go.sum 31 # cache deps before building and copying source so that we don't need to re-download as much 32 # and so that source changes don't invalidate our downloaded layer 33 RUN --mount=type=cache,target=/go/pkg/mod \ 34 go mod download 35 36 # Copy the go source 37 #COPY cmd/manager/main.go cmd/manager/main.go 38 #COPY cmd/manager/ cmd/manager/ 39 #COPY apis/ apis/ 40 #COPY pkg/ pkg/ 41 #COPY controllers/ controllers/ 42 #COPY test/testdata/testdata.go test/testdata/testdata.go 43 44 RUN --mount=type=bind,target=. \ 45 --mount=type=cache,target=/root/.cache/go-build \ 46 --mount=type=cache,target=/go/pkg/mod \ 47 go env && \ 48 CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="${LD_FLAGS}" -o /out/dataprotection ./cmd/dataprotection/main.go 49 50 # Use distroless as minimal base image to package the manager binary 51 # Refer to https://github.com/GoogleContainerTools/distroless for more details 52 FROM ${DIST_IMG} as dist 53 54 WORKDIR / 55 COPY --from=builder /out/dataprotection . 56 USER 65532:65532 57 58 ENTRYPOINT ["/dataprotection"]