Skip to content

Commit e563c6b

Browse files
authored
F #-: Adds multi-arch image build Makefile recipe (#10)
Signed-off-by: Aleix Ramírez <aramirez@opennebula.io>
1 parent d7d94b9 commit e563c6b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,25 @@ docker-publish: docker-build
7474
$(CONTAINER_TOOL) tag $(CCM_IMG) $(RELEASE_IMG)
7575
$(CONTAINER_TOOL) push $(RELEASE_IMG)
7676

77+
# _PLATFORMS defines the target platforms for the manager image be built to provide support to multiple
78+
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
79+
# - be able to use docker buildx. More info: https://docs.docker.com/reference/cli/docker/buildx/
80+
# - have enabled BuildKit. More info:h ttps://docs.docker.com/build/buildkit/
81+
# - 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)
82+
# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option.
83+
# NOTE: BUILDPLATFORM is a Docker BuildKit build-time variable that represents the platform (architecture/OS) on which the build is running (for example, linux/amd64).
84+
# More info: https://docs.docker.com/build/building/multi-platform/#automatic-platform-args-in-the-global-scope
85+
_PLATFORMS ?= linux/arm64,linux/amd64
86+
.PHONY: docker-multiarch-build-and-push
87+
docker-multiarch-build-and-push: ## Build and push docker image for the manager for cross-platform support)
88+
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile (https://docs.docker.com/build/building/multi-platform/#cross-compilation)
89+
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
90+
- $(CONTAINER_TOOL) buildx create --name cloud-provider-opennebula-builder
91+
$(CONTAINER_TOOL) buildx use cloud-provider-opennebula-builder
92+
- $(CONTAINER_TOOL) buildx build --push --platform=$(_PLATFORMS) --tag ${CCM_IMG} -f Dockerfile.cross .
93+
- $(CONTAINER_TOOL) buildx rm cloud-provider-opennebula-builder
94+
rm Dockerfile.cross
95+
7796
# Deployment
7897

7998
ifndef ignore-not-found

0 commit comments

Comments
 (0)