|
1 |
| -GIT_TAG = $(shell git tag --points-at | tail -n 1) |
2 |
| -GIT_BRANCH = $(shell git branch --show-current) |
3 |
| - |
4 |
| -IMAGE_TAG ?= ${GIT_TAG} |
5 |
| -ifeq ($(IMAGE_TAG),) |
6 |
| - IMAGE_TAG := ${GIT_BRANCH} |
7 |
| -endif |
8 |
| -ifeq ($(IMAGE_TAG),) |
9 |
| - IMAGE_TAG := latest |
10 |
| -endif |
11 |
| -ifeq ($(IMAGE_TAG),main) |
12 |
| - IMAGE_TAG := latest |
13 |
| -endif |
14 |
| - |
15 |
| -RELEASE_NAME ?= move2kube |
16 |
| - |
17 |
| -# Current Operator version |
18 |
| -VERSION ?= latest |
19 |
| -REGISTRYNS := quay.io/konveyor |
20 |
| - |
21 |
| -# Default bundle image tag |
22 |
| -BUNDLE_IMG ?= ${REGISTRYNS}/move2kube-bundle:$(VERSION) |
23 |
| -# Options for 'bundle-build' |
| 1 | +# VERSION defines the project version for the bundle. |
| 2 | +# Update this value when you upgrade the version of your project. |
| 3 | +# To re-generate a bundle for another specific version without changing the standard setup, you can: |
| 4 | +# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2) |
| 5 | +# - use environment variables to overwrite this value (e.g export VERSION=0.0.2) |
| 6 | +VERSION ?= 0.3.8 |
| 7 | + |
| 8 | +# CHANNELS define the bundle channels used in the bundle. |
| 9 | +# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable") |
| 10 | +# To re-generate a bundle for other specific channels without changing the standard setup, you can: |
| 11 | +# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=candidate,fast,stable) |
| 12 | +# - use environment variables to overwrite this value (e.g export CHANNELS="candidate,fast,stable") |
24 | 13 | ifneq ($(origin CHANNELS), undefined)
|
25 | 14 | BUNDLE_CHANNELS := --channels=$(CHANNELS)
|
26 | 15 | endif
|
| 16 | + |
| 17 | +# DEFAULT_CHANNEL defines the default channel used in the bundle. |
| 18 | +# Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable") |
| 19 | +# To re-generate a bundle for any other default channel without changing the default setup, you can: |
| 20 | +# - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable) |
| 21 | +# - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable") |
27 | 22 | ifneq ($(origin DEFAULT_CHANNEL), undefined)
|
28 | 23 | BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
|
29 | 24 | endif
|
30 | 25 | BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
|
31 | 26 |
|
| 27 | +# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images. |
| 28 | +# This variable is used to construct full image tags for bundle and catalog images. |
| 29 | +# |
| 30 | +# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both |
| 31 | +# quay.io/konveyor/move2kube-operator-bundle:$VERSION and quay.io/konveyor/move2kube-operator-catalog:$VERSION. |
| 32 | +IMAGE_TAG_BASE ?= quay.io/konveyor/move2kube |
| 33 | + |
| 34 | +# BUNDLE_IMG defines the image:tag used for the bundle. |
| 35 | +# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>) |
| 36 | +BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION) |
| 37 | + |
| 38 | +# BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command |
| 39 | +BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) |
| 40 | + |
| 41 | +# USE_IMAGE_DIGESTS defines if images are resolved via tags or digests |
| 42 | +# You can enable this value if you would like to use SHA Based Digests |
| 43 | +# To enable set flag to true |
| 44 | +USE_IMAGE_DIGESTS ?= false |
| 45 | +ifeq ($(USE_IMAGE_DIGESTS), true) |
| 46 | + BUNDLE_GEN_FLAGS += --use-image-digests |
| 47 | +endif |
| 48 | + |
| 49 | +# Set the Operator SDK version to use. By default, what is installed on the system is used. |
| 50 | +# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit. |
| 51 | +OPERATOR_SDK_VERSION ?= v1.31.0 |
| 52 | + |
32 | 53 | # Image URL to use all building/pushing image targets
|
33 |
| -IMG ?= ${REGISTRYNS}/move2kube-operator:$(VERSION) |
| 54 | +IMG ?= $(IMAGE_TAG_BASE)-operator:v$(VERSION) |
34 | 55 |
|
35 |
| -# Setting container tool |
36 |
| -DOCKER_CMD := $(shell command -v docker 2> /dev/null) |
37 |
| -PODMAN_CMD := $(shell command -v podman 2> /dev/null) |
| 56 | +.PHONY: all |
| 57 | +all: docker-build |
38 | 58 |
|
39 |
| -ifdef DOCKER_CMD |
40 |
| - CONTAINER_TOOL = 'docker' |
41 |
| -else ifdef PODMAN_CMD |
42 |
| - CONTAINER_TOOL = 'podman' |
43 |
| -endif |
| 59 | +##@ General |
| 60 | + |
| 61 | +# The help target prints out all targets with their descriptions organized |
| 62 | +# beneath their categories. The categories are represented by '##@' and the |
| 63 | +# target descriptions by '##'. The awk commands is responsible for reading the |
| 64 | +# entire set of makefiles included in this invocation, looking for lines of the |
| 65 | +# file as xyz: ## something, and then pretty-format the target and help. Then, |
| 66 | +# if there's a line with ##@ something, that gets pretty-printed as a category. |
| 67 | +# More info on the usage of ANSI control characters for terminal formatting: |
| 68 | +# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters |
| 69 | +# More info on the awk command: |
| 70 | +# http://linuxcommand.org/lc3_adv_awk.php |
44 | 71 |
|
45 |
| -all: container-build |
| 72 | +.PHONY: help |
| 73 | +help: ## Display this help. |
| 74 | + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) |
46 | 75 |
|
47 |
| -# Run against the configured Kubernetes cluster in ~/.kube/config |
48 |
| -run: helm-operator |
| 76 | +##@ Build |
| 77 | + |
| 78 | +.PHONY: run |
| 79 | +run: helm-operator ## Run against the configured Kubernetes cluster in ~/.kube/config |
49 | 80 | $(HELM_OPERATOR) run
|
50 | 81 |
|
51 |
| -# Install CRDs into a cluster |
52 |
| -install: kustomize |
| 82 | +.PHONY: docker-build |
| 83 | +docker-build: ## Build docker image with the manager. |
| 84 | + docker build -t ${IMG} . |
| 85 | + |
| 86 | +.PHONY: docker-push |
| 87 | +docker-push: ## Push docker image with the manager. |
| 88 | + docker push ${IMG} |
| 89 | + |
| 90 | +# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple |
| 91 | +# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to: |
| 92 | +# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/ |
| 93 | +# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/ |
| 94 | +# - 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) |
| 95 | +# To properly provided solutions that supports more than one platform you should use this option. |
| 96 | +PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le |
| 97 | +.PHONY: docker-buildx |
| 98 | +docker-buildx: test ## Build and push docker image for the manager for cross-platform support |
| 99 | + # copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile |
| 100 | + sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross |
| 101 | + - docker buildx create --name project-v3-builder |
| 102 | + docker buildx use project-v3-builder |
| 103 | + - docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross . |
| 104 | + - docker buildx rm project-v3-builder |
| 105 | + rm Dockerfile.cross |
| 106 | + |
| 107 | +##@ Deployment |
| 108 | + |
| 109 | +.PHONY: install |
| 110 | +install: kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. |
53 | 111 | $(KUSTOMIZE) build config/crd | kubectl apply -f -
|
54 | 112 |
|
55 |
| -# Uninstall CRDs from a cluster |
56 |
| -uninstall: kustomize |
| 113 | +.PHONY: uninstall |
| 114 | +uninstall: kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. |
57 | 115 | $(KUSTOMIZE) build config/crd | kubectl delete -f -
|
58 | 116 |
|
59 |
| -# Deploy controller in the configured Kubernetes cluster in ~/.kube/config |
60 |
| -deploy: kustomize |
| 117 | +.PHONY: deploy |
| 118 | +deploy: kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. |
61 | 119 | cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
|
62 | 120 | $(KUSTOMIZE) build config/default | kubectl apply -f -
|
63 | 121 |
|
64 |
| -# Undeploy controller in the configured Kubernetes cluster in ~/.kube/config |
65 |
| -undeploy: kustomize |
| 122 | +.PHONY: undeploy |
| 123 | +undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. |
66 | 124 | $(KUSTOMIZE) build config/default | kubectl delete -f -
|
67 | 125 |
|
68 |
| -# Build the docker image |
69 |
| -container-build: |
70 |
| -ifndef CONTAINER_TOOL |
71 |
| - $(error No container tool (docker, podman) found in your environment. Please, install one) |
72 |
| -endif |
73 |
| - |
74 |
| - @echo "Building image with $(CONTAINER_TOOL)" |
75 |
| - |
76 |
| - ${CONTAINER_TOOL} build . -t ${IMG} |
| 126 | +OS := $(shell uname -s | tr '[:upper:]' '[:lower:]') |
| 127 | +ARCH := $(shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/') |
77 | 128 |
|
78 |
| -# Push the docker image |
79 |
| -container-push: |
80 |
| -ifndef CONTAINER_TOOL |
81 |
| - $(error No container tool (docker, podman) found in your environment. Please, install one) |
| 129 | +.PHONY: kustomize |
| 130 | +KUSTOMIZE = $(shell pwd)/bin/kustomize |
| 131 | +kustomize: ## Download kustomize locally if necessary. |
| 132 | +ifeq (,$(wildcard $(KUSTOMIZE))) |
| 133 | +ifeq (,$(shell which kustomize 2>/dev/null)) |
| 134 | + @{ \ |
| 135 | + set -e ;\ |
| 136 | + mkdir -p $(dir $(KUSTOMIZE)) ;\ |
| 137 | + curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v4.5.7/kustomize_v4.5.7_$(OS)_$(ARCH).tar.gz | \ |
| 138 | + tar xzf - -C bin/ ;\ |
| 139 | + } |
| 140 | +else |
| 141 | +KUSTOMIZE = $(shell which kustomize) |
| 142 | +endif |
82 | 143 | endif
|
83 | 144 |
|
84 |
| - @echo "Pushing image with $(CONTAINER_TOOL)" |
85 |
| - |
86 |
| - ${CONTAINER_TOOL} push ${IMG} |
87 |
| - |
88 |
| -PATH := $(PATH):$(PWD)/bin |
89 |
| -SHELL := env PATH=$(PATH) /bin/sh |
90 |
| -OS = $(shell uname -s | tr '[:upper:]' '[:lower:]') |
91 |
| -ARCH = $(shell uname -m | sed 's/x86_64/amd64/') |
92 |
| -OSOPER = $(shell uname -s | tr '[:upper:]' '[:lower:]' | sed 's/darwin/apple-darwin/' | sed 's/linux/linux-gnu/') |
93 |
| -ARCHOPER = $(shell uname -m ) |
94 |
| - |
95 |
| -kustomize: |
96 |
| -ifeq (, $(shell which kustomize 2>/dev/null)) |
| 145 | +.PHONY: helm-operator |
| 146 | +HELM_OPERATOR = $(shell pwd)/bin/helm-operator |
| 147 | +helm-operator: ## Download helm-operator locally if necessary, preferring the $(pwd)/bin path over global if both exist. |
| 148 | +ifeq (,$(wildcard $(HELM_OPERATOR))) |
| 149 | +ifeq (,$(shell which helm-operator 2>/dev/null)) |
97 | 150 | @{ \
|
98 | 151 | set -e ;\
|
99 |
| - mkdir -p bin ;\ |
100 |
| - curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v3.5.4/kustomize_v3.5.4_$(OS)_$(ARCH).tar.gz | tar xzf - -C bin/ ;\ |
| 152 | + mkdir -p $(dir $(HELM_OPERATOR)) ;\ |
| 153 | + curl -sSLo $(HELM_OPERATOR) https://github.com/operator-framework/operator-sdk/releases/download/v1.31.0/helm-operator_$(OS)_$(ARCH) ;\ |
| 154 | + chmod +x $(HELM_OPERATOR) ;\ |
101 | 155 | }
|
102 |
| -KUSTOMIZE=$(realpath ./bin/kustomize) |
103 | 156 | else
|
104 |
| -KUSTOMIZE=$(shell which kustomize) |
| 157 | +HELM_OPERATOR = $(shell which helm-operator) |
| 158 | +endif |
105 | 159 | endif
|
106 | 160 |
|
107 |
| -helm-operator: |
108 |
| -ifeq (, $(shell which helm-operator 2>/dev/null)) |
| 161 | +.PHONY: operator-sdk |
| 162 | +OPERATOR_SDK ?= ./bin/operator-sdk |
| 163 | +operator-sdk: ## Download operator-sdk locally if necessary. |
| 164 | +ifeq (,$(wildcard $(OPERATOR_SDK))) |
| 165 | +ifeq (, $(shell which operator-sdk 2>/dev/null)) |
109 | 166 | @{ \
|
110 | 167 | set -e ;\
|
111 |
| - mkdir -p bin ;\ |
112 |
| - curl -LO https://github.com/operator-framework/operator-sdk/releases/download/v1.0.1/helm-operator-v1.0.1-$(ARCHOPER)-$(OSOPER) ;\ |
113 |
| - mv helm-operator-v1.0.1-$(ARCHOPER)-$(OSOPER) ./bin/helm-operator ;\ |
114 |
| - chmod +x ./bin/helm-operator ;\ |
| 168 | + mkdir -p $(dir $(OPERATOR_SDK)) ;\ |
| 169 | + curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$(OS)_$(ARCH) ;\ |
| 170 | + chmod +x $(OPERATOR_SDK) ;\ |
115 | 171 | }
|
116 |
| -HELM_OPERATOR=$(realpath ./bin/helm-operator) |
117 | 172 | else
|
118 |
| -HELM_OPERATOR=$(shell which helm-operator) |
| 173 | +OPERATOR_SDK = $(shell which operator-sdk) |
| 174 | +endif |
119 | 175 | endif
|
120 | 176 |
|
121 |
| -# Generate bundle manifests and metadata, then validate generated files. |
122 | 177 | .PHONY: bundle
|
123 |
| -bundle: kustomize |
124 |
| - operator-sdk generate kustomize manifests -q |
| 178 | +bundle: kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files. |
| 179 | + $(OPERATOR_SDK) generate kustomize manifests -q |
125 | 180 | cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
|
126 |
| - $(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) |
127 |
| - operator-sdk bundle validate ./bundle |
| 181 | + $(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS) |
| 182 | + $(OPERATOR_SDK) bundle validate ./bundle |
128 | 183 |
|
129 |
| -# Build the bundle image. |
130 | 184 | .PHONY: bundle-build
|
131 |
| -bundle-build: |
| 185 | +bundle-build: ## Build the bundle image. |
132 | 186 | docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
|
133 | 187 |
|
134 |
| -.PHONY: helm-install |
135 |
| -helm-install: |
136 |
| - helm upgrade --install --set deployment.api.imageTag="${IMAGE_TAG}" ${RELEASE_NAME} helm-charts/move2kube/ |
| 188 | +.PHONY: bundle-push |
| 189 | +bundle-push: ## Push the bundle image. |
| 190 | + $(MAKE) docker-push IMG=$(BUNDLE_IMG) |
| 191 | + |
| 192 | +.PHONY: opm |
| 193 | +OPM = ./bin/opm |
| 194 | +opm: ## Download opm locally if necessary. |
| 195 | +ifeq (,$(wildcard $(OPM))) |
| 196 | +ifeq (,$(shell which opm 2>/dev/null)) |
| 197 | + @{ \ |
| 198 | + set -e ;\ |
| 199 | + mkdir -p $(dir $(OPM)) ;\ |
| 200 | + curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$(OS)-$(ARCH)-opm ;\ |
| 201 | + chmod +x $(OPM) ;\ |
| 202 | + } |
| 203 | +else |
| 204 | +OPM = $(shell which opm) |
| 205 | +endif |
| 206 | +endif |
| 207 | + |
| 208 | +# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0). |
| 209 | +# These images MUST exist in a registry and be pull-able. |
| 210 | +BUNDLE_IMGS ?= $(BUNDLE_IMG) |
| 211 | + |
| 212 | +# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0). |
| 213 | +CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION) |
| 214 | + |
| 215 | +# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image. |
| 216 | +ifneq ($(origin CATALOG_BASE_IMG), undefined) |
| 217 | +FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG) |
| 218 | +endif |
| 219 | + |
| 220 | +# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'. |
| 221 | +# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see: |
| 222 | +# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator |
| 223 | +.PHONY: catalog-build |
| 224 | +catalog-build: opm ## Build a catalog image. |
| 225 | + $(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT) |
| 226 | + |
| 227 | +# Push the catalog image. |
| 228 | +.PHONY: catalog-push |
| 229 | +catalog-push: ## Push a catalog image. |
| 230 | + $(MAKE) docker-push IMG=$(CATALOG_IMG) |
0 commit comments