diff --git a/Dockerfile_multiarch b/Dockerfile_multiarch new file mode 100644 index 0000000..d57f841 --- /dev/null +++ b/Dockerfile_multiarch @@ -0,0 +1,31 @@ +# Build the manager and daemon binaries +ARG BASE_IMAGE=alpine +ARG BASE_IMAGE_VERION=3.17 +FROM --platform=$BUILDPLATFORM golang:1.18-alpine3.17 as builder + +WORKDIR /workspace +# Copy the Go Modules manifests +COPY go.mod go.mod +COPY go.sum go.sum + +# Copy the go source +COPY main.go main.go +COPY internal/ internal/ +COPY pkg/ pkg/ +COPY vendor/ vendor/ + +# Build +ARG TARGETOS +ARG TARGETARCH +RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 GO111MODULE=on go build -mod=vendor -a -o kruise-state-metrics main.go + +ARG BASE_IMAGE +ARG BASE_IMAGE_VERION +FROM ${BASE_IMAGE}:${BASE_IMAGE_VERION} + +RUN apk add --no-cache ca-certificates=~20220614-r4 bash=~5.2.15-r0 expat=~2.5.0-r0 \ + && rm -rf /var/cache/apk/* + +WORKDIR / +COPY --from=builder /workspace/kruise-state-metrics . +ENTRYPOINT ["/kruise-state-metrics"] diff --git a/Makefile b/Makefile index 81281b5..aac74bf 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # Image URL to use all building/pushing image targets IMG ?= openkruise/kruise-state-metrics:test # Platforms to build the image for -PLATFORMS ?= linux/amd64,linux/arm64,linux/arm +PLATFORMS ?= linux/amd64,linux/arm64 # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) @@ -41,7 +41,7 @@ docker-push: # Build and push the multiarchitecture docker images and manifest. docker-multiarch: - docker buildx build --pull --no-cache --platform=$(PLATFORMS) --push . -t $(IMG) + docker buildx build -f ./Dockerfile_multiarch --pull --no-cache --platform=$(PLATFORMS) --push . -t $(IMG) deploy: kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. cd deploy && $(KUSTOMIZE) edit set image kruise-state-metrics=${IMG}