Skip to content

Commit 8816187

Browse files
committed
Add configurable multi-arch build support
Signed-off-by: Catherine Chan-Tse <[email protected]>
1 parent 0eed476 commit 8816187

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

Diff for: docs/tutorial.md

+11-6
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ The `java-operator-plugins` project uses the APIs from [java-operator-sdk](https
8787

8888
#### `MemcachedSpec`
8989

90-
Initially, the scaffolded Spec file will be empty. The operator developer needs
90+
Initially, the scaffolded Spec file, `MemcachedSpec`, will be empty. The operator developer needs
9191
to add attributes to this file according to their needs. For the `Memcached`
9292
example, we will add the size field as shown in the example below.
9393

@@ -564,15 +564,20 @@ The following steps will show how to run your operator in the cluster.
564564

565565
The `java-operator-plugins` project will scaffold out a Makefile to give
566566
Operator SDK users a familiar interface. Using the `docker-*` targets you can
567-
conveniently build your and push your operator's image to registry. In our
568-
example, we are using `quay.io`, but any docker registry should work.
567+
conveniently build and push your operator's image to a registry.
568+
569+
To build and push the docker image, you will need to specify the name of the image, `IMG`,
570+
that will be built as well as the operating system, `OS`, and the architecture,
571+
`ARCH`, that the image will be built for. In this example, we are using
572+
`quay.io` as the registry the image will be pushed to, but any docker registry should work.
569573

570574
```
571-
make docker-build docker-push IMG=quay.io/YOURUSER/memcached-quarkus-operator:v0.0.1
575+
make docker-build docker-push IMG=quay.io/YOURUSER/memcached-quarkus-operator:v0.0.1 OS=linux ARCH=arm64
572576
```
573577

574-
This will build the docker image
575-
`quay.io/YOURUSER/memcached-quarkus-operator:v0.0.1` and push it to the registry.
578+
This will build the docker image
579+
`quay.io/YOURUSER/memcached-quarkus-operator:v0.0.1` for linux/arm64 and push it
580+
to the `quay.io` registry.
576581

577582
You can verify it is in your docker registry:
578583

Diff for: pkg/quarkus/v1alpha/scaffolds/internal/templates/makefile.go

+20-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ type Makefile struct {
2929
// Image is controller manager image name
3030
Image string
3131

32+
// OS is the operating system to use for building the image
33+
OS string
34+
35+
// Arch is the architecture to use for building the image
36+
Arch string
37+
3238
// Kustomize version to use in the project
3339
KustomizeVersion string
3440

@@ -50,6 +56,15 @@ func (f *Makefile) SetTemplateDefaults() error {
5056
f.Image = "controller:latest"
5157
}
5258

59+
if f.OS == "" && f.Arch == "" {
60+
// Default OS/Arch to linux/amd64
61+
f.OS = "linux"
62+
f.Arch = "amd64"
63+
} else if f.OS == "" || f.Arch == "" {
64+
// Require both OS and Arch
65+
return errors.New("Both OS and Arch are required to be set if not using default")
66+
}
67+
5368
if f.KustomizeVersion == "" {
5469
return errors.New("kustomize version is required in scaffold")
5570
}
@@ -62,8 +77,11 @@ func (f *Makefile) SetTemplateDefaults() error {
6277
}
6378

6479
const makefileTemplate = `
65-
# Image URL to use all building/pushing image targets
80+
# Image URL to use for all building/pushing image targets
6681
IMG ?= {{ .Image }}
82+
# Operating system and architecture to use for building image
83+
OS ?= {{ .OS }}
84+
ARCH ?= {{ .Arch }}
6785
6886
all: docker-build
6987
@@ -86,7 +104,7 @@ help: ## Display this help.
86104
##@ Build
87105
88106
docker-build: ## Build docker image with the manager.
89-
mvn package -Dquarkus.container-image.build=true -Dquarkus.container-image.image=${IMG}
107+
mvn package -Dquarkus.container-image.build=true -Dquarkus.container-image.builder=docker -Dquarkus.container-image.image=${IMG} -Dquarkus.docker.buildx.platform=${OS}/${ARCH}
90108
91109
docker-push: ## Push docker image with the manager.
92110
mvn package -Dquarkus.container-image.push=true -Dquarkus.container-image.image=${IMG}

0 commit comments

Comments
 (0)