Skip to content

Commit b5af315

Browse files
authored
Cross-compile zookeeper operator for amd64 and arm64. (#30)
* Cross-compile zookeeper operator for amd64 and arm64. * Implement review
1 parent bba92c4 commit b5af315

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ GIT_SHA=$(shell git rev-parse --short HEAD)
2323
TEST_IMAGE=$(TEST_REPO)-testimages:$(VERSION)
2424
DOCKER_TEST_PASS=testzkop@123
2525
DOCKER_TEST_USER=testzkop
26+
IMG?=$(REPO):$(VERSION)
2627
.PHONY: all build check clean test
2728
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
2829
ifeq (,$(shell go env GOBIN))
@@ -133,6 +134,23 @@ build-image:
133134
docker build --build-arg VERSION=$(VERSION) --build-arg DOCKER_REGISTRY=$(DOCKER_REGISTRY) --build-arg DISTROLESS_DOCKER_REGISTRY=$(DISTROLESS_DOCKER_REGISTRY) --build-arg GIT_SHA=$(GIT_SHA) -t $(REPO):$(VERSION) .
134135
docker tag $(REPO):$(VERSION) $(REPO):latest
135136

137+
# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
138+
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
139+
# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/
140+
# - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/
141+
# - be able to push the image to your registry (i.e. if you do not set a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
142+
# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
143+
PLATFORMS ?= linux/arm64,linux/amd64
144+
.PHONY: docker-buildx
145+
docker-buildx: ## Build and push docker image for the manager for cross-platform support
146+
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
147+
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
148+
- docker buildx create --name zookeeper-builder
149+
docker buildx use zookeeper-builder
150+
docker buildx build --push --platform=$(PLATFORMS) --tag $(IMG) -f Dockerfile.cross .
151+
- docker buildx rm zookeeper-builder
152+
rm Dockerfile.cross
153+
136154
build-zk-image:
137155

138156
docker build --build-arg VERSION=$(VERSION) --build-arg DOCKER_REGISTRY=$(DOCKER_REGISTRY) --build-arg GIT_SHA=$(GIT_SHA) -t $(APP_REPO):$(VERSION) ./docker

0 commit comments

Comments
 (0)