github.com/IBM-Blockchain/fabric-operator@v1.0.4/Makefile (about) 1 # 2 # Copyright contributors to the Hyperledger Fabric Operator project 3 # 4 # SPDX-License-Identifier: Apache-2.0 5 # 6 # Licensed under the Apache License, Version 2.0 (the "License"); 7 # you may not use this file except in compliance with the License. 8 # You may obtain a copy of the License at: 9 # 10 # http://www.apache.org/licenses/LICENSE-2.0 11 # 12 # Unless required by applicable law or agreed to in writing, software 13 # distributed under the License is distributed on an "AS IS" BASIS, 14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 # See the License for the specific language governing permissions and 16 # limitations under the License. 17 # 18 19 IMAGE ?= hyperledger-labs/fabric-operator 20 ARCH ?= $(shell go env GOARCH) 21 OS = $(shell go env GOOS) 22 SEMREV_LABEL ?= v1.0.0-$(shell git rev-parse --short HEAD) 23 BUILD_DATE = $(shell date -u +"%Y-%m-%dT%H:%M:%SZ") 24 GO_VER ?= 1.18.4 25 26 # For compatibility with legacy install-fabric.sh conventions, strip the 27 # leading semrev 'v' character when preparing dist and release artifacts. 28 VERSION=$(shell echo $(SEMREV_LABEL) | sed -e 's/^v\(.*\)/\1/') 29 30 31 DOCKER_BUILD ?= docker build 32 33 BUILD_ARGS+=--build-arg BUILD_ID=$(VERSION) 34 BUILD_ARGS+=--build-arg BUILD_DATE=$(BUILD_DATE) 35 BUILD_ARGS+=--build-arg GO_VER=$(GO_VER) 36 37 .PHONY: build 38 39 build: 40 mkdir -p bin && go build -o bin/operator 41 42 image: setup 43 $(DOCKER_BUILD) -f Dockerfile $(BUILD_ARGS) -t $(IMAGE) . 44 45 govendor: 46 @go mod vendor 47 48 setup: govendor manifests bundle generate 49 50 51 ####################################### 52 #### part of autogenerate makefile #### 53 ####################################### 54 55 # Current Operator version 56 VERSION ?= "1.0.0" 57 # Default bundle image tag 58 BUNDLE_IMG ?= controller-bundle:$(VERSION) 59 # Options for 'bundle-build' 60 ifneq ($(origin CHANNELS), undefined) 61 BUNDLE_CHANNELS := --channels=$(CHANNELS) 62 endif 63 ifneq ($(origin DEFAULT_CHANNEL), undefined) 64 BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL) 65 endif 66 BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) 67 68 # Image URL to use all building/pushing image targets 69 IMG ?= controller:latest 70 # Produce CRDs that work back to Kubernetes 1.11 (no version conversion) 71 CRD_OPTIONS ?= "crd:crdVersions=v1" 72 73 # KIND cluster for local development, integration, and E2E testing 74 KIND_CLUSTER_NAME ?= fabric 75 KIND_KUBE_VERSION ?= v1.20.15 # Matches integ IKS cluster rev. v1.23.4 is current 76 KIND_NODE_IMAGE ?= kindest/node:$(KIND_KUBE_VERSION) 77 78 # Integration test parameters 79 INT_TEST_TIMEOUT ?= 60m 80 INT_TEST_NAME ?= * 81 82 # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) 83 ifeq (,$(shell go env GOBIN)) 84 GOBIN=$(shell go env GOPATH)/bin 85 else 86 GOBIN=$(shell go env GOBIN) 87 endif 88 89 all: manager 90 91 # Run tests 92 test: generate fmt vet manifests 93 @scripts/run-unit-tests.sh 94 95 # Build manager binary 96 manager: generate fmt vet 97 go build -o bin/manager main.go 98 99 # Run against the configured Kubernetes cluster in ~/.kube/config 100 run: generate fmt vet manifests 101 go run ./main.go 102 103 # Install CRDs into a cluster 104 install: manifests kustomize 105 $(KUSTOMIZE) build config/crd | kubectl apply -f - 106 107 # Uninstall CRDs from a cluster 108 uninstall: manifests kustomize 109 $(KUSTOMIZE) build config/crd | kubectl delete -f - 110 111 # Deploy controller in the configured Kubernetes cluster in ~/.kube/config 112 deploy: manifests kustomize 113 cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} 114 $(KUSTOMIZE) build config/default | kubectl apply -f - 115 116 # Generate manifests e.g. CRD, RBAC etc. 117 manifests: controller-gen 118 $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases 119 120 # Create a KIND K8s and Nginx ingress controller on :80 / :443 121 kind: kustomize 122 kind create cluster --name $(KIND_CLUSTER_NAME) --config=integration/kind-config.yaml --image $(KIND_NODE_IMAGE) 123 $(KUSTOMIZE) build config/ingress/kind | kubectl apply -f - 124 125 # Destroy the local KIND cluster 126 unkind: 127 kind delete cluster --name $(KIND_CLUSTER_NAME) 128 129 # Run integration tests. Target a specific test package by specifying INT_TEST in the make env. 130 # If INT_TEST is unspecified, run ALL tests (slow!!) 131 integration-tests: 132 ginkgo -v -failFast -timeout $(INT_TEST_TIMEOUT) ./integration/$(INT_TEST_NAME) 133 134 # Run go fmt against code 135 fmt: 136 go fmt ./... 137 138 # Run go vet against code 139 vet: 140 @scripts/checks.sh 141 142 # Generate code 143 generate: controller-gen 144 $(CONTROLLER_GEN) object:headerFile="boilerplate/boilerplate.go.txt" paths="./..." 145 146 # find or download controller-gen 147 # download controller-gen if necessary 148 controller-gen: 149 ifeq (, $(shell which controller-gen)) 150 @{ \ 151 set -e ;\ 152 CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\ 153 cd $$CONTROLLER_GEN_TMP_DIR ;\ 154 go mod init tmp ;\ 155 go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0 ;\ 156 rm -rf $$CONTROLLER_GEN_TMP_DIR ;\ 157 } 158 CONTROLLER_GEN=$(GOBIN)/controller-gen 159 else 160 CONTROLLER_GEN=$(shell which controller-gen) 161 endif 162 163 kustomize: 164 ifeq (, $(shell which kustomize)) 165 @{ \ 166 set -e ;\ 167 KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\ 168 cd $$KUSTOMIZE_GEN_TMP_DIR ;\ 169 go mod init tmp ;\ 170 go install sigs.k8s.io/kustomize/kustomize/v4@v4.5.7 ;\ 171 rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\ 172 } 173 KUSTOMIZE=$(GOBIN)/kustomize 174 else 175 KUSTOMIZE=$(shell which kustomize) 176 endif 177 178 # Generate bundle manifests and metadata, then validate generated files. 179 bundle: manifests 180 operator-sdk generate kustomize manifests -q 181 kustomize build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) 182 operator-sdk bundle validate ./bundle 183 184 # Build the bundle image. 185 bundle-build: 186 docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . 187 188 .PHONY: opm 189 OPM = ./bin/opm 190 opm: 191 ifeq (,$(wildcard $(OPM))) 192 ifeq (,$(shell which opm 2>/dev/null)) 193 @{ \ 194 set -e ;\ 195 mkdir -p $(dir $(OPM)) ;\ 196 curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.15.1/$(OS)-$(ARCH)-opm ;\ 197 chmod +x $(OPM) ;\ 198 } 199 else 200 OPM = $(shell which opm) 201 endif 202 endif 203 BUNDLE_IMGS ?= $(BUNDLE_IMG) 204 CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION) ifneq ($(origin CATALOG_BASE_IMG), undefined) FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG) endif 205 .PHONY: catalog-build 206 catalog-build: opm 207 $(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT) 208 209 .PHONY: catalog-push 210 catalog-push: ## Push the catalog image. 211 $(MAKE) docker-push IMG=$(CATALOG_IMG)