github.com/ferryproxy/api@v0.4.2/Makefile (about) 1 2 # Image URL to use all building/pushing image targets 3 IMG ?= controller:latest 4 # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. 5 ENVTEST_K8S_VERSION = 1.24.2 6 7 # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) 8 ifeq (,$(shell go env GOBIN)) 9 GOBIN=$(shell go env GOPATH)/bin 10 else 11 GOBIN=$(shell go env GOBIN) 12 endif 13 14 # Setting SHELL to bash allows bash commands to be executed by recipes. 15 # This is a requirement for 'setup-envtest.sh' in the test target. 16 # Options are set to exit when a recipe line exits non-zero or a piped command fails. 17 SHELL = /usr/bin/env bash -o pipefail 18 .SHELLFLAGS = -ec 19 20 .PHONY: all 21 all: build 22 23 ##@ General 24 25 # The help target prints out all targets with their descriptions organized 26 # beneath their categories. The categories are represented by '##@' and the 27 # target descriptions by '##'. The awk commands is responsible for reading the 28 # entire set of makefiles included in this invocation, looking for lines of the 29 # file as xyz: ## something, and then pretty-format the target and help. Then, 30 # if there's a line with ##@ something, that gets pretty-printed as a category. 31 # More info on the usage of ANSI control characters for terminal formatting: 32 # https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters 33 # More info on the awk command: 34 # http://linuxcommand.org/lc3_adv_awk.php 35 36 .PHONY: help 37 help: ## Display this help. 38 @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) 39 40 ##@ Development 41 42 .PHONY: manifests 43 manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. 44 $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases 45 46 .PHONY: generate 47 generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. 48 $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." 49 50 .PHONY: fmt 51 fmt: ## Run go fmt against code. 52 go fmt ./... 53 54 .PHONY: vet 55 vet: ## Run go vet against code. 56 go vet ./... 57 58 .PHONY: test 59 test: manifests generate fmt vet envtest ## Run tests. 60 KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out 61 62 ##@ Build 63 64 .PHONY: build 65 build: generate fmt vet ## Build manager binary. 66 go build -o bin/manager main.go 67 68 .PHONY: run 69 run: manifests generate fmt vet ## Run a controller from your host. 70 go run ./main.go 71 72 .PHONY: docker-build 73 docker-build: test ## Build docker image with the manager. 74 docker build -t ${IMG} . 75 76 .PHONY: docker-push 77 docker-push: ## Push docker image with the manager. 78 docker push ${IMG} 79 80 ##@ Deployment 81 82 ifndef ignore-not-found 83 ignore-not-found = false 84 endif 85 86 .PHONY: install 87 install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config. 88 $(KUSTOMIZE) build config/crd | kubectl apply -f - 89 90 .PHONY: uninstall 91 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. 92 $(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f - 93 94 .PHONY: deploy 95 deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config. 96 cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} 97 $(KUSTOMIZE) build config/default | kubectl apply -f - 98 99 .PHONY: undeploy 100 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. 101 $(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f - 102 103 ##@ Build Dependencies 104 105 ## Location to install dependencies to 106 LOCALBIN ?= $(shell pwd)/bin 107 $(LOCALBIN): 108 mkdir -p $(LOCALBIN) 109 110 ## Tool Binaries 111 KUSTOMIZE ?= $(LOCALBIN)/kustomize 112 CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen 113 ENVTEST ?= $(LOCALBIN)/setup-envtest 114 115 ## Tool Versions 116 KUSTOMIZE_VERSION ?= v3.8.7 117 CONTROLLER_TOOLS_VERSION ?= v0.9.2 118 119 KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" 120 .PHONY: kustomize 121 kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. 122 $(KUSTOMIZE): $(LOCALBIN) 123 test -s $(LOCALBIN)/kustomize || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); } 124 125 .PHONY: controller-gen 126 controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. 127 $(CONTROLLER_GEN): $(LOCALBIN) 128 GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) 129 130 .PHONY: envtest 131 envtest: $(ENVTEST) ## Download envtest-setup locally if necessary. 132 $(ENVTEST): $(LOCALBIN) 133 GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest