github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/docker/Dockerfile-tools (about) 1 # Build the kubeblocks tools binaries 2 # includes kbcli, kubectl, and manager tools. 3 4 ## docker buildx build injected build-args: 5 #BUILDPLATFORM — matches the current machine. (e.g. linux/amd64) 6 #BUILDOS — os component of BUILDPLATFORM, e.g. linux 7 #BUILDARCH — e.g. amd64, arm64, riscv64 8 #BUILDVARIANT — used to set build ARM variant, e.g. v7 9 #TARGETPLATFORM — The value set with --platform flag on build 10 #TARGETOS - OS component from --platform, e.g. linux 11 #TARGETARCH - Architecture from --platform, e.g. arm64 12 #TARGETVARIANT - used to set target ARM variant, e.g. v7 13 14 ARG GO_VERSION=1.21 15 16 FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION} as builder 17 ARG TARGETOS 18 ARG TARGETARCH 19 ARG GOPROXY 20 #ARG GOPROXY=https://goproxy.cn 21 ARG LD_FLAGS="-s -w" 22 23 ENV GONOPROXY=github.com/apecloud 24 ENV GONOSUMDB=github.com/apecloud 25 ENV GOPRIVATE=github.com/apecloud 26 ENV GOPROXY=${GOPROXY} 27 28 WORKDIR /src 29 30 # Copy the Go Modules manifests 31 COPY go.mod go.mod 32 COPY go.sum go.sum 33 # cache deps before building and copying source so that we don't need to re-download as much 34 # and so that source changes don't invalidate our downloaded layer 35 # RUN go mod download 36 37 # Copy the go source 38 #COPY pkg/ pkg/ 39 #COPY controllers/ controllers/ 40 #COPY cmd/reloader/ cmd/reloader/ 41 #COPY cmd/lorry/ cmd/lorry/ 42 #COPY externalapis/ externalapis/ 43 #COPY version/ version/ 44 #COPY cmd/cli/ cmd/cli/ 45 #COPY apis/ apis/ 46 #COPY test/testdata/testdata.go test/testdata/testdata.go 47 RUN --mount=type=cache,target=/go/pkg/mod \ 48 go mod download 49 50 # Build 51 RUN --mount=type=bind,target=. \ 52 --mount=type=cache,target=/root/.cache/go-build \ 53 --mount=type=cache,target=/go/pkg/mod \ 54 go env && \ 55 CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="${LD_FLAGS}" -a -o /out/killer cmd/reloader/container_killer/killer.go 56 57 RUN --mount=type=bind,target=. \ 58 --mount=type=cache,target=/root/.cache/go-build \ 59 --mount=type=cache,target=/go/pkg/mod \ 60 CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="${LD_FLAGS}" -a -o /out/reloader cmd/reloader/main.go 61 62 RUN --mount=type=bind,target=. \ 63 --mount=type=cache,target=/root/.cache/go-build \ 64 --mount=type=cache,target=/go/pkg/mod \ 65 CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="${LD_FLAGS}" -a -o /out/config_render cmd/reloader/template/*.go 66 67 RUN --mount=type=bind,target=. \ 68 --mount=type=cache,target=/root/.cache/go-build \ 69 --mount=type=cache,target=/go/pkg/mod \ 70 CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="${LD_FLAGS}" -a -o /out/lorry cmd/lorry/main.go 71 72 RUN --mount=type=bind,target=. \ 73 --mount=type=cache,target=/root/.cache/go-build \ 74 --mount=type=cache,target=/go/pkg/mod \ 75 CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="${LD_FLAGS}" -a -o /out/lorryctl cmd/lorry/ctl/main.go 76 77 RUN --mount=type=bind,target=. \ 78 --mount=type=cache,target=/root/.cache/go-build \ 79 --mount=type=cache,target=/go/pkg/mod \ 80 CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="${LD_FLAGS}" -tags="containers_image_openpgp" -a -o /out/kbcli cmd/cli/main.go 81 82 RUN GRPC_HEALTH_PROBE_VERSION=v0.4.13 GOOS=${TARGETOS} GOARCH=${TARGETARCH} && \ 83 wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-${GOOS}-${GOARCH} 84 85 86 # Use alpine with tag 20230329 is corresponding to "edge" tag (latest release to date is 3.18) as of 20230625 87 FROM docker.io/alpine:edge as dist 88 ARG APK_MIRROR 89 90 # install tools via apk 91 ENV APK_MIRROR=${APK_MIRROR} 92 RUN if [ -n "${APK_MIRROR}" ]; then sed -i "s/dl-cdn.alpinelinux.org/${APK_MIRROR}/g" /etc/apk/repositories; fi 93 RUN apk add --no-cache curl kubectl helm jq --allow-untrusted \ 94 && rm -rf /var/cache/apk/* 95 96 # copy kubeblocks tools 97 COPY config/lorry config/lorry 98 COPY --from=builder /out/killer /bin 99 COPY --from=builder /out/reloader /bin 100 COPY --from=builder /out/config_render /bin 101 COPY --from=builder /out/lorry /bin 102 COPY --from=builder /out/lorryctl /bin 103 COPY --from=builder /out/kbcli /bin 104 COPY --from=builder /bin/grpc_health_probe /bin 105 106 # make breaking change compatible 107 RUN ln -s /bin/lorry /bin/probe 108 RUN ln -s /config/lorry /config/probe 109 110 # enable grpc_health_probe binary 111 RUN chmod +x /bin/grpc_health_probe 112 113 # mkdir kbcli config dir and helm cache dir. 114 RUN mkdir /.kbcli && chown -R 65532:65532 /.kbcli \ 115 && mkdir /.cache && chown -R 65532:65532 /.cache 116 USER 65532:65532 117