Skip to content

Commit

Permalink
support docker multiarch(amd64,arm64)
Browse files Browse the repository at this point in the history
Signed-off-by: liheng.zms <[email protected]>
  • Loading branch information
zmberg committed Feb 20, 2023
1 parent 44c839c commit 4a2ea44
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
31 changes: 31 additions & 0 deletions Dockerfile_multiarch
Original file line number Diff line number Diff line change
@@ -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"]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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))
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 4a2ea44

Please sign in to comment.