Skip to content

Commit 77dd4e2

Browse files
authored
Fixes #6037: Add multi-arch builder to ansible and helm plugins (#6093)
* Fixes #6037: Add multi-arch builder to ansible and helm plugins Signed-off-by: jesus m. rodriguez <[email protected]>
1 parent 1e1a6b1 commit 77dd4e2

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# entries is a list of entries to include in
2+
# release notes and/or the migration guide
3+
entries:
4+
- description: >
5+
(ansible/v1, helm/v1) Added support to build multi-arch images
6+
from the project Makefile. A docker-buildx target will build
7+
the images for the platforms specified by the PLATFORMS variable.
8+
kind: "change"
9+
breaking: false # entries is a list of entries to include in
10+
11+
# Migration can be defined to automatically add a section to
12+
# the migration guide. This is required for breaking changes.
13+
migration:
14+
header: For multi-arch build support, add docker-buildx target to project Makefile
15+
body: |
16+
17+
In the project `Makefile` below the `docker-push` target add the new `docker-buildx`
18+
target.
19+
20+
```yaml
21+
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
22+
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
23+
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
24+
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
25+
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> than the export will fail)
26+
# To properly provided solutions that supports more than one platform you should use this option.
27+
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
28+
.PHONY: docker-buildx
29+
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
30+
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
31+
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
32+
- docker buildx create --name project-v3-builder
33+
docker buildx use project-v3-builder
34+
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross
35+
- docker buildx rm project-v3-builder
36+
rm Dockerfile.cross
37+
```

internal/plugins/ansible/v1/scaffolds/internal/templates/makefile.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,23 @@ docker-build: ## Build docker image with the manager.
102102
docker-push: ## Push docker image with the manager.
103103
docker push ${IMG}
104104
105+
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
106+
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
107+
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
108+
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
109+
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> than the export will fail)
110+
# To properly provided solutions that supports more than one platform you should use this option.
111+
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
112+
.PHONY: docker-buildx
113+
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
114+
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
115+
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
116+
- docker buildx create --name project-v3-builder
117+
docker buildx use project-v3-builder
118+
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
119+
- docker buildx rm project-v3-builder
120+
rm Dockerfile.cross
121+
105122
##@ Deployment
106123
107124
.PHONY: install

internal/plugins/helm/v1/scaffolds/internal/templates/makefile.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,23 @@ docker-build: ## Build docker image with the manager.
102102
docker-push: ## Push docker image with the manager.
103103
docker push ${IMG}
104104
105+
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
106+
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
107+
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
108+
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
109+
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> than the export will fail)
110+
# To properly provided solutions that supports more than one platform you should use this option.
111+
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
112+
.PHONY: docker-buildx
113+
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
114+
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
115+
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
116+
- docker buildx create --name project-v3-builder
117+
docker buildx use project-v3-builder
118+
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
119+
- docker buildx rm project-v3-builder
120+
rm Dockerfile.cross
121+
105122
##@ Deployment
106123
107124
.PHONY: install

testdata/ansible/memcached-operator/Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,23 @@ docker-build: ## Build docker image with the manager.
8383
docker-push: ## Push docker image with the manager.
8484
docker push ${IMG}
8585

86+
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
87+
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
88+
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
89+
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
90+
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> than the export will fail)
91+
# To properly provided solutions that supports more than one platform you should use this option.
92+
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
93+
.PHONY: docker-buildx
94+
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
95+
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
96+
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
97+
- docker buildx create --name project-v3-builder
98+
docker buildx use project-v3-builder
99+
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
100+
- docker buildx rm project-v3-builder
101+
rm Dockerfile.cross
102+
86103
##@ Deployment
87104

88105
.PHONY: install

testdata/helm/memcached-operator/Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,23 @@ docker-build: ## Build docker image with the manager.
8383
docker-push: ## Push docker image with the manager.
8484
docker push ${IMG}
8585

86+
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
87+
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
88+
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
89+
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
90+
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> than the export will fail)
91+
# To properly provided solutions that supports more than one platform you should use this option.
92+
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
93+
.PHONY: docker-buildx
94+
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
95+
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
96+
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
97+
- docker buildx create --name project-v3-builder
98+
docker buildx use project-v3-builder
99+
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
100+
- docker buildx rm project-v3-builder
101+
rm Dockerfile.cross
102+
86103
##@ Deployment
87104

88105
.PHONY: install

0 commit comments

Comments
 (0)