Skip to content

Commit

Permalink
Support multiarch image build and push
Browse files Browse the repository at this point in the history
Add docker-build-multiarch/docker-push-multiarch in Makefile

Signed-off-by: roc <[email protected]>
  • Loading branch information
imroc committed Dec 4, 2024
1 parent 7976e90 commit 72337b4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.21 as builder
FROM golang:1.21 AS builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -16,7 +16,7 @@ COPY pkg/ pkg/
COPY cloudprovider/ cloudprovider/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
RUN CGO_ENABLED=0 go build -a -o manager main.go

# Use distroless as minimal base images to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

# Image URL to use all building/pushing images targets
IMG ?= kruise-game-manager:test
IMAGE_PLATFORMS ?= linux_amd64 linux_arm64
# Convert to linux/arm64,linux/amd64
$(eval BUILDX_PLATFORMS = $(shell echo "${IMAGE_PLATFORMS}" | sed "s# #,#;s#_#/#g"))

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.24.1

Expand Down Expand Up @@ -77,6 +81,14 @@ docker-build: ## Build docker images with the manager.
docker-push: ## Push docker images with the manager.
docker push ${IMG}

.PHONY: docker-build-multiarch
docker-build-multiarch: ## Build multiarch docker images with the manager.
docker buildx build --platform "${BUILDX_PLATFORMS}" -t ${IMG} .

.PHONY: docker-push-multiarch
docker-push-multiarch: ## Push multiarch docker images with the manager.
docker buildx build --push --sbom=false --provenance=false --platform "${BUILDX_PLATFORMS}" -t ${IMG} .

##@ Deployment

ifndef ignore-not-found
Expand Down Expand Up @@ -137,4 +149,4 @@ helm: ## Download helm locally if necessary.
$(call go-get-tool,$(HELM),helm.sh/helm/[email protected])

ginkgo: ## Download ginkgo locally if necessary.
GOBIN=$(LOCALBIN) go install github.com/onsi/ginkgo/[email protected]
GOBIN=$(LOCALBIN) go install github.com/onsi/ginkgo/[email protected]

0 comments on commit 72337b4

Please sign in to comment.