support docker multiarch(amd64,arm64)

Signed-off-by: liheng.zms <liheng.zms@alibaba-inc.com>
This commit is contained in:
liheng.zms 2023-02-20 11:19:19 +08:00
parent 44c839c4c1
commit 4a2ea44501
2 changed files with 33 additions and 2 deletions

31
Dockerfile_multiarch Normal file
View File

@ -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"]

View File

@ -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}