|
5 | 5 | # - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
|
6 | 6 | VERSION ?= 1.5.0
|
7 | 7 |
|
| 8 | +# BUILD_PLATFORMS contains a set of tuples [os arch buildx_platform suffix base_image addon_image] |
| 9 | +# separated by semicolon. An empty variable or empty entry (= just a |
| 10 | +# semicolon) builds for the default platform of the current Go |
| 11 | +# toolchain. This approach was adapted from the CSI driver release-tools.1 |
| 12 | +BUILD_PLATFORMS = |
| 13 | + |
8 | 14 | # CHANNELS define the bundle channels used in the bundle.
|
9 | 15 | # Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
|
10 | 16 | # To re-generate a bundle for other specific channels without changing the standard setup, you can:
|
@@ -110,15 +116,24 @@ test: manifests generate fmt vet envtest ## Run tests.
|
110 | 116 | KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test -v ./... -coverprofile cover.out
|
111 | 117 |
|
112 | 118 | ##@ Build
|
113 |
| - |
114 | 119 | .PHONY: build
|
115 | 120 | build: generate fmt vet ## Build manager binary.
|
116 |
| - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/manager main.go |
| 121 | + mkdir -p bin |
| 122 | + echo '$(BUILD_PLATFORMS)' | tr ';' '\n' | while read -r os arch buildx_platform suffix base_image addon_image; do \ |
| 123 | + if ! (set -x; CGO_ENABLED=0 GOOS="$$os" GOARCH="$$arch" go build $(GOFLAGS_VENDOR) -a -ldflags \ |
| 124 | + '$(FULL_LDFLAGS)' -o "./bin/manager$$suffix" main.go); then \ |
| 125 | + echo "Building manager for GOOS=$$os GOARCH=$$arch failed, see error(s) above."; \ |
| 126 | + exit 1; \ |
| 127 | + fi; \ |
| 128 | + done |
117 | 129 |
|
118 | 130 | .PHONY: run
|
119 | 131 | run: manifests generate fmt vet ## Run a controller from your host.
|
120 | 132 | go run ./main.go --zap-devel=true --zap-log-level=5
|
121 | 133 |
|
| 134 | +# Note the Makefile doesn't build multiarch images (only the current architecture). |
| 135 | +# Multiarch images are currently built/published using GitHub actions or manually. |
| 136 | + |
122 | 137 | .PHONY: docker-build
|
123 | 138 | docker-build: test ## Build docker image with the manager.
|
124 | 139 | docker build -t ${IMG} .
|
@@ -249,9 +264,14 @@ PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
|
249 | 264 | .PHONY: docker-buildx
|
250 | 265 | docker-buildx: test ## Build and push docker image for the manager for cross-platform support
|
251 | 266 | # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
|
252 |
| - sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross |
253 |
| - - docker buildx create --name project-v3-builder |
254 |
| - docker buildx use project-v3-builder |
255 |
| - - docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross |
256 |
| - - docker buildx rm project-v3-builder |
257 |
| - rm Dockerfile.cross |
| 267 | + # sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross |
| 268 | + # - docker buildx create --name project-v3-builder |
| 269 | + # docker buildx use project-v3-builder |
| 270 | + # - docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross |
| 271 | + # - docker buildx rm project-v3-builder |
| 272 | + # rm Dockerfile.cross |
| 273 | + # This has not been updated to work with how we build multiarch images using GitHub actions. |
| 274 | + # Fail the target to prevent accidental usage. |
| 275 | + @echo "Using the docker-buildx target is not currently supported" |
| 276 | + @exit 1 |
| 277 | + |
0 commit comments