|
1 | 1 | # Image URL to use all building/pushing image targets |
2 | 2 | TAG ?= latest |
3 | | -IMG ?= ghcr.io/lxc/cluster-api-provider-incus:$(TAG) |
| 3 | +REGISTRY ?= ghcr.io |
| 4 | +REPO ?= $(REGISTRY)/lxc/cluster-api-provider-incus |
| 5 | +IMG ?= $(REPO):$(TAG) |
| 6 | + |
| 7 | +# Used by ko build |
| 8 | +export KO_DOCKER_REPO = $(REPO) |
| 9 | + |
| 10 | +# PLATFORMS defines the target platforms for the manager image be built. |
| 11 | +PLATFORMS ?= linux/arm64,linux/amd64 |
| 12 | +LOCAL_PLATFORM ?= linux/$(shell go env GOARCH) |
4 | 13 |
|
5 | 14 | # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. |
6 | 15 | ENVTEST_K8S_VERSION = 1.31.0 |
@@ -94,8 +103,8 @@ _SKIP_ARGS := $(foreach arg,$(strip $(E2E_GINKGO_SKIP)),-skip="$(arg)") |
94 | 103 | endif |
95 | 104 |
|
96 | 105 | .PHONY: e2e-image |
97 | | -e2e-image: IMG = ghcr.io/lxc/cluster-api-provider-incus:e2e ## Build controller image for e2e tests |
98 | | -e2e-image: docker-build |
| 106 | +e2e-image: TAG = e2e ## Build controller image for e2e tests |
| 107 | +e2e-image: ko-build |
99 | 108 |
|
100 | 109 | E2E_DATA_DIR ?= $(REPO_ROOT)/test/e2e/data |
101 | 110 | ARTIFACTS ?= $(REPO_ROOT)/_artifacts |
@@ -154,33 +163,17 @@ V ?= 0 |
154 | 163 | run: manifests generate fmt vet ## Run a controller from your host. |
155 | 164 | go run ./cmd/main.go --diagnostics-address=":" --v=${V} |
156 | 165 |
|
157 | | -# If you wish to build the manager image targeting other platforms you can use the --platform flag. |
158 | | -# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it. |
159 | | -# More info: https://docs.docker.com/develop/develop-images/build_enhancements/ |
160 | | -.PHONY: docker-build |
161 | | -docker-build: ## Build docker image with the manager. |
162 | | - $(CONTAINER_TOOL) build -t ${IMG} . |
163 | | - |
164 | | -.PHONY: docker-push |
165 | | -docker-push: ## Push docker image with the manager. |
166 | | - $(CONTAINER_TOOL) push ${IMG} |
167 | | - |
168 | | -# PLATFORMS defines the target platforms for the manager image be built to provide support to multiple |
169 | | -# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to: |
170 | | -# - be able to use docker buildx. More info: https://docs.docker.com/build/buildx/ |
171 | | -# - have enabled BuildKit. More info: https://docs.docker.com/develop/develop-images/build_enhancements/ |
172 | | -# - 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) |
173 | | -# To adequately provide solutions that are compatible with multiple platforms, you should consider using this option. |
174 | | -PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le |
175 | | -.PHONY: docker-buildx |
176 | | -docker-buildx: ## Build and push docker image for the manager for cross-platform support |
177 | | - # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile |
178 | | - sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross |
179 | | - - $(CONTAINER_TOOL) buildx create --name test-builder |
180 | | - $(CONTAINER_TOOL) buildx use test-builder |
181 | | - - $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross . |
182 | | - - $(CONTAINER_TOOL) buildx rm test-builder |
183 | | - rm Dockerfile.cross |
| 166 | +.PHONY: ko-build |
| 167 | +ko-build: ko ## Build manager image and load to local docker instance. |
| 168 | + $(KO) build ./cmd --bare --tags $(TAG) --sbom=none --platform=$(LOCAL_PLATFORM) --local |
| 169 | + |
| 170 | +.PHONY: ko-login |
| 171 | +ko-login: ko ## Configure credentials for pushing images (needs USERNAME and PASSWORD). |
| 172 | + echo $(PASSWORD) | $(KO) login $(REGISTRY) --username $(USERNAME) --password-stdin |
| 173 | + |
| 174 | +.PHONY: ko-push |
| 175 | +ko-push: ko ## Build and push manager image. |
| 176 | + $(KO) build ./cmd --bare --tags $(TAG) --sbom=none --platform=$(PLATFORMS) |
184 | 177 |
|
185 | 178 | ##@ Release |
186 | 179 |
|
@@ -231,15 +224,17 @@ KUBECTL ?= kubectl |
231 | 224 | KUSTOMIZE ?= $(LOCALBIN)/kustomize |
232 | 225 | CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen |
233 | 226 | ENVTEST ?= $(LOCALBIN)/setup-envtest |
234 | | -GOLANGCI_LINT = $(LOCALBIN)/golangci-lint |
235 | | -GINKGO = $(LOCALBIN)/ginkgo |
236 | | -IMAGE_BUILDER = $(LOCALBIN)/image-builder |
| 227 | +GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint |
| 228 | +GINKGO ?= $(LOCALBIN)/ginkgo |
| 229 | +KO ?= $(LOCALBIN)/ko |
| 230 | +IMAGE_BUILDER ?= $(LOCALBIN)/image-builder |
237 | 231 |
|
238 | 232 | ## Tool Versions |
239 | 233 | KUSTOMIZE_VERSION ?= v5.5.0 |
240 | 234 | CONTROLLER_TOOLS_VERSION ?= v0.16.4 |
241 | 235 | ENVTEST_VERSION ?= release-0.19 |
242 | 236 | GOLANGCI_LINT_VERSION ?= v1.61.0 |
| 237 | +KO_VERSION ?= v0.18.0 |
243 | 238 |
|
244 | 239 | .PHONY: image-builder |
245 | 240 | image-builder: $(LOCALBIN) |
@@ -270,6 +265,11 @@ ginkgo: $(GINKGO) ## Download ginkgo locally if necessary. |
270 | 265 | $(GINKGO): $(LOCALBIN) |
271 | 266 | go build -o $@ github.com/onsi/ginkgo/v2/ginkgo |
272 | 267 |
|
| 268 | +.PHONY: ko |
| 269 | +ko: $(KO) ## Download ko locally if necessary. |
| 270 | +$(KO): $(LOCALBIN) |
| 271 | + $(call go-install-tool,$(KO),github.com/google/ko,$(KO_VERSION)) |
| 272 | + |
273 | 273 | # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist |
274 | 274 | # $1 - target path with name of binary |
275 | 275 | # $2 - package url which can be installed |
|
0 commit comments