Skip to content

Commit

Permalink
Added buildx function for building multi-arch image
Browse files Browse the repository at this point in the history
  • Loading branch information
Satyam Gupta authored and Satyam Gupta committed Apr 15, 2024
1 parent 015960f commit b8e9285
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ IMAGE_BUILD_FLAGS ?= --build-arg USE_LOCAL=false
OPERATOR_MAKE_ENV_FILE = local.mk
-include $(OPERATOR_MAKE_ENV_FILE)

# Buildx function for building multi-arch image
define func_buildx
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' $1 > Dockerfile.cross
- docker buildx create --name project-v3-builder
docker buildx use project-v3-builder
- docker buildx build --push --platform=$2 --tag $3 -f Dockerfile.cross .
- docker buildx rm project-v3-builder
rm Dockerfile.cross
endef

.PHONY: default
default: manifests lint unit-test build
Expand Down Expand Up @@ -185,13 +195,7 @@ build: generate fmt vet ## Build manager binary.
PLATFORMS ?= linux/amd64,linux/s390x,linux/ppc64le
.PHONY: docker-buildx
docker-buildx: ## Build and push docker image for the manager for cross-platform support
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' ./Dockerfiles/Dockerfile > ./Dockerfiles/Dockerfile.cross
- docker buildx create --name project-v3-builder
docker buildx use project-v3-builder
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f ./Dockerfiles/Dockerfile.cross .
- docker buildx rm project-v3-builder
rm ./Dockerfiles/Dockerfile.cross
$(call func_buildx,./Dockerfiles/Dockerfile,$(PLATFORMS),$(IMG))

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
Expand Down Expand Up @@ -300,13 +304,7 @@ bundle-build: bundle

.PHONY: bundle-docker-buildx
bundle-docker-buildx: ## Build and push docker image for the manager for cross-platform support
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' ./Dockerfiles/bundle.Dockerfile > ./Dockerfiles/bundle.Dockerfile.cross
- docker buildx create --name project-v3-builder
docker buildx use project-v3-builder
- docker buildx build --push --platform=$(PLATFORMS) --tag ${BUNDLE_IMG} -f ./Dockerfiles/bundle.Dockerfile.cross .
- docker buildx rm project-v3-builder
rm ./Dockerfiles/bundle.Dockerfile.cross
$(call func_buildx,./Dockerfiles/bundle.Dockerfile,$(PLATFORMS),$(BUNDLE_IMG))

.PHONY: bundle-push
bundle-push: ## Push the bundle image.
Expand Down

0 comments on commit b8e9285

Please sign in to comment.