github.com/redhat-appstudio/release-service@v0.0.0-20240507045911-a8558ef3422a/Makefile (about) 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.0.1 7 TAG_NAME ?= next 8 CERT_MANAGER_VERSION ?= v1.8.0 9 ENABLE_WEBHOOKS ?= true 10 11 # DEFAULT_PERSISTENT_VOLUME_CLAIM defines the default PVC to be used in the managed Release Pipeline workspace declaration. 12 DEFAULT_RELEASE_PVC ?= release-pvc 13 14 # DEFAULT_WORKSPACE_NAME defines the default name for the workspace that will be used in the managed Release Pipeline. 15 DEFAULT_RELEASE_WORKSPACE_NAME ?= release-workspace 16 17 # DEFAULT_WORKSPACE_SIZE defines the default size for the workspace that will be used in the managed Release Pipeline. 18 DEFAULT_RELEASE_WORKSPACE_SIZE ?= 1Gi 19 20 # CHANNELS define the bundle channels used in the bundle. 21 # Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable") 22 # To re-generate a bundle for other specific channels without changing the standard setup, you can: 23 # - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=candidate,fast,stable) 24 # - use environment variables to overwrite this value (e.g export CHANNELS="candidate,fast,stable") 25 ifneq ($(origin CHANNELS), undefined) 26 BUNDLE_CHANNELS := --channels=$(CHANNELS) 27 endif 28 29 # DEFAULT_CHANNEL defines the default channel used in the bundle. 30 # Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable") 31 # To re-generate a bundle for any other default channel without changing the default setup, you can: 32 # - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable) 33 # - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable") 34 ifneq ($(origin DEFAULT_CHANNEL), undefined) 35 BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL) 36 endif 37 BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) 38 39 # IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images. 40 # This variable is used to construct full image tags for bundle and catalog images. 41 # 42 # For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both 43 # redhat.com/release-service-bundle:$VERSION and redhat.com/release-service-catalog:$VERSION. 44 IMAGE_TAG_BASE ?= quay.io/redhat-appstudio/release-service 45 46 # BUNDLE_IMG defines the image:tag used for the bundle. 47 # You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>) 48 BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(TAG_NAME) 49 50 # BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command 51 BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) 52 53 # USE_IMAGE_DIGESTS defines if images are resolved via tags or digests 54 # You can enable this value if you would like to use SHA Based Digests 55 # To enable set flag to true 56 USE_IMAGE_DIGESTS ?= false 57 ifeq ($(USE_IMAGE_DIGESTS), true) 58 BUNDLE_GEN_FLAGS += --use-image-digests 59 endif 60 61 # Image URL to use all building/pushing image targets 62 IMG ?= $(IMAGE_TAG_BASE):$(TAG_NAME) 63 # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. 64 ENVTEST_K8S_VERSION = 1.27.1 65 66 # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) 67 ifeq (,$(shell go env GOBIN)) 68 GOBIN=$(shell go env GOPATH)/bin 69 else 70 GOBIN=$(shell go env GOBIN) 71 endif 72 73 # Setting SHELL to bash allows bash commands to be executed by recipes. 74 # This is a requirement for 'setup-envtest.sh' in the test target. 75 # Options are set to exit when a recipe line exits non-zero or a piped command fails. 76 SHELL = /usr/bin/env bash -o pipefail 77 .SHELLFLAGS = -ec 78 79 .PHONY: all 80 all: build 81 82 ##@ General 83 84 # The help target prints out all targets with their descriptions organized 85 # beneath their categories. The categories are represented by '##@' and the 86 # target descriptions by '##'. The awk commands is responsible for reading the 87 # entire set of makefiles included in this invocation, looking for lines of the 88 # file as xyz: ## something, and then pretty-format the target and help. Then, 89 # if there's a line with ##@ something, that gets pretty-printed as a category. 90 # More info on the usage of ANSI control characters for terminal formatting: 91 # https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters 92 # More info on the awk command: 93 # http://linuxcommand.org/lc3_adv_awk.php 94 95 .PHONY: help 96 help: ## Display this help. 97 @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) 98 99 ##@ Development 100 101 .PHONY: manifests 102 manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. 103 $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases 104 105 .PHONY: generate 106 generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. 107 $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." 108 109 .PHONY: fmt 110 fmt: ## Run go fmt against code. 111 go fmt ./... 112 113 .PHONY: vet 114 vet: ## Run go vet against code. 115 go vet ./... 116 117 .PHONY: test 118 test: manifests generate fmt vet envtest ## Run tests. 119 KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out 120 121 ##@ Build 122 123 .PHONY: build 124 build: generate fmt vet ## Build manager binary. 125 go build -o bin/manager main.go 126 127 .PHONY: run 128 run: manifests generate fmt vet ## Run a controller from your host. 129 go run ./main.go 130 131 .PHONY: docker-build 132 docker-build: test ## Build docker image with the manager. 133 docker build --build-arg ENABLE_WEBHOOKS=${ENABLE_WEBHOOKS} -t ${IMG} . 134 135 .PHONY: docker-push 136 docker-push: ## Push docker image with the manager. 137 docker push ${IMG} 138 139 install-cert: ## Install cert manager for webhooks 140 kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/$(CERT_MANAGER_VERSION)/cert-manager.yaml 141 142 uninstall-cert: 143 kubectl delete -f https://github.com/cert-manager/cert-manager/releases/download/$(CERT_MANAGER_VERSION)/cert-manager.yaml 144 145 ##@ Deployment 146 147 ifndef ignore-not-found 148 ignore-not-found = false 149 endif 150 151 .PHONY: install 152 install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. 153 $(KUSTOMIZE) build config/crd | kubectl apply -f - 154 155 .PHONY: uninstall 156 uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. 157 $(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f - 158 159 .PHONY: deploy 160 deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. 161 cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} 162 DEFAULT_RELEASE_PVC=${DEFAULT_RELEASE_PVC} \ 163 DEFAULT_RELEASE_WORKSPACE_NAME=${DEFAULT_RELEASE_WORKSPACE_NAME} \ 164 DEFAULT_RELEASE_WORKSPACE_SIZE=${DEFAULT_RELEASE_WORKSPACE_SIZE} \ 165 $(KUSTOMIZE) build config/default | kubectl apply -f - 166 167 .PHONY: undeploy 168 undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion. 169 $(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f - 170 171 LOCAL_CERT_DIR := /tmp/k8s-webhook-server/serving-certs 172 .PHONY: create-local-certs 173 create-local-certs: ## Create the local certs required for running the operator manually 174 mkdir -p $(LOCAL_CERT_DIR) 175 openssl genrsa -out $(LOCAL_CERT_DIR)/tls.key 176 openssl req -key $(LOCAL_CERT_DIR)/tls.key -new -out $(LOCAL_CERT_DIR)/tls.csr -subj "/C=XX/L=Default City/O=Red Hat" 177 openssl x509 -signkey $(LOCAL_CERT_DIR)/tls.key -in $(LOCAL_CERT_DIR)/tls.csr -req -days 365 -out $(LOCAL_CERT_DIR)/tls.crt 178 179 ##@ Build Dependencies 180 181 ## Location to install dependencies to 182 LOCALBIN ?= $(shell pwd)/bin 183 $(LOCALBIN): 184 mkdir -p $(LOCALBIN) 185 186 ## Tool Binaries 187 KUSTOMIZE ?= $(LOCALBIN)/kustomize 188 CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen 189 ENVTEST ?= $(LOCALBIN)/setup-envtest 190 191 ## Tool Versions 192 KUSTOMIZE_VERSION ?= v3.8.7 193 CONTROLLER_TOOLS_VERSION ?= v0.8.0 194 195 KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" 196 .PHONY: kustomize 197 kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. 198 $(KUSTOMIZE): $(LOCALBIN) 199 @[ -f $(KUSTOMIZE) ] || curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN) 200 201 .PHONY: controller-gen 202 controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. 203 $(CONTROLLER_GEN): $(LOCALBIN) 204 GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) 205 206 .PHONY: envtest 207 envtest: $(ENVTEST) ## Download envtest-setup locally if necessary. 208 $(ENVTEST): $(LOCALBIN) 209 GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest 210 211 .PHONY: bundle 212 bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files. 213 operator-sdk generate kustomize manifests --interactive=false -q 214 cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) 215 $(KUSTOMIZE) build config/manifests | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS) 216 operator-sdk bundle validate ./bundle 217 218 .PHONY: bundle-build 219 bundle-build: ## Build the bundle image. 220 docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . 221 222 .PHONY: bundle-push 223 bundle-push: ## Push the bundle image. 224 $(MAKE) docker-push IMG=$(BUNDLE_IMG) 225 226 .PHONY: opm 227 OPM = ./bin/opm 228 opm: ## Download opm locally if necessary. 229 ifeq (,$(wildcard $(OPM))) 230 ifeq (,$(shell which opm 2>/dev/null)) 231 @{ \ 232 set -e ;\ 233 mkdir -p $(dir $(OPM)) ;\ 234 OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \ 235 curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.19.1/$${OS}-$${ARCH}-opm ;\ 236 chmod +x $(OPM) ;\ 237 } 238 else 239 OPM = $(shell which opm) 240 endif 241 endif 242 243 # 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). 244 # These images MUST exist in a registry and be pull-able. 245 BUNDLE_IMGS ?= $(BUNDLE_IMG) 246 247 # The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0). 248 CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(TAG_NAME) 249 250 # Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image. 251 ifneq ($(origin CATALOG_BASE_IMG), undefined) 252 FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG) 253 endif 254 255 # Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'. 256 # This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see: 257 # https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator 258 .PHONY: catalog-build 259 catalog-build: opm ## Build a catalog image. 260 $(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT) 261 262 # Push the catalog image. 263 .PHONY: catalog-push 264 catalog-push: ## Push a catalog image. 265 $(MAKE) docker-push IMG=$(CATALOG_IMG)