forked from Apicurio/apicurio-registry-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
263 lines (206 loc) · 8.7 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# Parse target documentation from '##' comments
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.DEFAULT_GOAL = help
########## Config
OPERAND_VERSION ?= 2.x
LC_OPERAND_VERSION = $(shell echo $(OPERAND_VERSION) | tr A-Z a-z)
OPERATOR_VERSION = $(shell sed -n 's/^.*Version.*=.*"\(.*\)".*$$/\1/p' ./version/version.go)
DASH_VERSION = $(shell echo "$(OPERATOR_VERSION)" | sed -n 's/^[0-9\.]*-\([^-+]*\).*$$/-\1/p')
### Bundle
CHANNELS = "2.x"
DEFAULT_CHANNEL = "2.x"
ifneq ($(origin CHANNELS), undefined)
BUNDLE_CHANNELS = --channels=$(CHANNELS)
endif
ifneq ($(origin DEFAULT_CHANNEL), undefined)
BUNDLE_DEFAULT_CHANNEL = --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
### Package Manifests
CHANNEL ?= "2.x"
IS_DEFAULT_CHANNEL ?= 1
FROM_VERSION = 1.0.0-v2.0.0.final
ifneq ($(origin FROM_VERSION), undefined)
PACKAGE_FROM_VERSION := --from-version=$(FROM_VERSION)
endif
ifneq ($(origin CHANNEL), undefined)
PACKAGE_CHANNELS := --channel=$(CHANNEL)
endif
ifeq ($(IS_DEFAULT_CHANNEL), 1)
PACKAGE_IS_DEFAULT_CHANNEL := --default-channel
endif
PACKAGE_MANIFESTS_OPTS ?= $(PACKAGE_FROM_VERSION) $(PACKAGE_CHANNELS) $(PACKAGE_IS_DEFAULT_CHANNEL)
PACKAGE_VERSION = $(OPERATOR_VERSION)-v$(LC_OPERAND_VERSION)
###
OPERATOR_IMAGE_REPOSITORY ?= quay.io/apicurio
OPERATOR_IMAGE_NAME = $(OPERATOR_IMAGE_REPOSITORY)/apicurio-registry-operator
OPERATOR_IMAGE = $(OPERATOR_IMAGE_NAME):$(OPERATOR_VERSION)
BUNDLE_IMAGE_NAME = $(OPERATOR_IMAGE_NAME)-bundle
BUNDLE_IMAGE = $(BUNDLE_IMAGE_NAME):$(OPERATOR_VERSION)
CATALOG_IMAGE_NAME = $(OPERATOR_IMAGE_NAME)-catalog
CATALOG_IMAGE = $(CATALOG_IMAGE_NAME):$(OPERATOR_VERSION)
NAMESPACE ?= "apicurio-registry-operator-namespace"
CLIENT ?= kubectl
OPERATOR_SDK = $(shell which operator-sdk)
########## Env
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
all: build
########## Tools
# go-install-tool will 'go install' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-install-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
.PHONY: install-controller-gen
install-controller-gen: ## Install [email protected]
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
KUSTOMIZE = $(shell pwd)/bin/kustomize
.PHONY: install-kustomize
install-kustomize: ## Install [email protected]
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
########## Targets
.PHONY: generate
generate: install-controller-gen ## Generate code
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
.PHONY: fmt
fmt: ## Run 'go fmt' against code
go fmt ./...
.PHONY: vet
vet: ## Run 'go vet' against code
go vet ./...
.PHONY: manager
manager: generate fmt vet ## Build manager binary
go build -o bin/manager main.go
.PHONY: manifests
manifests: install-controller-gen ## Generate manifests e.g. CRD, RBAC etc.
$(CONTROLLER_GEN) rbac:roleName=apicurio-registry-operator-role crd paths="./..." output:crd:artifacts:config=config/crd/resources output:rbac:artifacts:config=config/rbac/resources
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.23
.PHONY: test
test: generate fmt vet manifests ## Run tests
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.0/hack/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
ifndef ignore-not-found
ignore-not-found = false
endif
.PHONY: deploy
deploy: manifests install-kustomize ## TODO
cd config/manager && $(KUSTOMIZE) edit set image REGISTRY_OPERATOR_IMAGE=${OPERATOR_IMAGE}
cd config/default && $(KUSTOMIZE) edit set namespace ${NAMESPACE}
$(KUSTOMIZE) build config/default | $(CLIENT) apply -f - -n ${NAMESPACE}
.PHONY: undeploy
undeploy: ## TODO
$(KUSTOMIZE) build config/build-namespaced | $(CLIENT) delete --ignore-not-found=$(ignore-not-found) -f -
.PHONY: docker-build
docker-build: test ## Build Operator image
docker build -t ${OPERATOR_IMAGE} .
.PHONY: docker-push
docker-push: ## Push Operator image
ifeq ($(LATEST),true)
docker tag $(OPERATOR_IMAGE) $(OPERATOR_IMAGE_NAME):latest$(DASH_VERSION)
docker push $(OPERATOR_IMAGE_NAME):latest$(DASH_VERSION)
endif
docker push ${OPERATOR_IMAGE}
.PHONY: build
build: manager docker-build ## Build Operator image
.PHONY: bundle
bundle: manifests install-kustomize ## Generate bundle manifests and metadata
$(OPERATOR_SDK) generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image REGISTRY_OPERATOR_IMAGE=$(OPERATOR_IMAGE)
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q --overwrite --version $(OPERATOR_VERSION) $(BUNDLE_METADATA_OPTS)
$(OPERATOR_SDK) bundle validate ./bundle
.PHONY: bundle-build
bundle-build: bundle ## Build bundle image
docker build -f bundle.Dockerfile -t $(BUNDLE_IMAGE) .
.PHONY: bundle-push
bundle-push: ## Push bundle image
ifeq ($(LATEST),true)
docker tag $(BUNDLE_IMAGE) $(BUNDLE_IMAGE_NAME):latest$(DASH_VERSION)
docker push $(BUNDLE_IMAGE_NAME):latest$(DASH_VERSION)
endif
docker push $(BUNDLE_IMAGE)
DATE=$(shell date -Idate)
.PHONY: packagemanifests
packagemanifests: install-kustomize manifests ## Generate package manifests
echo "⚠️ Warning: This command requires 'yq' version 4.x"
which yq
$(OPERATOR_SDK) generate kustomize manifests -q
cd config/manager && $(KUSTOMIZE) edit set image REGISTRY_OPERATOR_IMAGE=$(OPERATOR_IMAGE)
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate packagemanifests -q --version $(PACKAGE_VERSION) $(PACKAGE_MANIFESTS_OPTS)
yq e ".metadata.annotations.createdAt = \"$(DATE)\"" -i \
"packagemanifests/$(PACKAGE_VERSION)/apicurio-registry-operator.clusterserviceversion.yaml"
yq e ".metadata.annotations.containerImage = \"$(OPERATOR_IMAGE)\"" -i \
"packagemanifests/$(PACKAGE_VERSION)/apicurio-registry-operator.clusterserviceversion.yaml"
.PHONY: docs
docs: ## Build documentation
cd ./docs && antora local-test-playbook.yml
echo "file:$(shell pwd)/docs/target/dist/"
.PHONY: dist
dist: install-kustomize docs ## Generate distribution bundle
mkdir -p dist
cp -rt ./dist ./dist-base/*
cp -t ./dist ./LICENSE
# Examples
cp -t ./dist/examples ./config/examples/resources/*
cp -rt ./dist/examples ./docs/modules/ROOT/examples/*
#cp -t ./dist/examples/keycloak ./docs/modules/ROOT/examples/keycloak/*
# Docs
cp -rt ./dist ./docs/target/dist && mv ./dist/dist ./dist/docs
# Install
cd config/manager && $(KUSTOMIZE) edit set image REGISTRY_OPERATOR_IMAGE=$(OPERATOR_IMAGE)
$(KUSTOMIZE) build config/default/ > ./dist/install.yaml
$(KUSTOMIZE) build config/default/ > ./docs/resources/install.yaml # Deprecated!
# Archive
tar -zcf apicurio-registry-operator-$(PACKAGE_VERSION).tar.gz -C ./dist .
.PHONY: clean
clean: ## Remove temporary and generated files
rm apicurio-registry-operator-$(PACKAGE_VERSION).tar.gz cover.out || true
rm -r bin build bundle dist docs/target testbin || true
OS = $(shell go env GOOS)
ARCH = $(shell go env GOARCH)
.PHONY: opm
OPM = ./bin/opm
opm:
ifeq (,$(wildcard $(OPM)))
ifeq (,$(shell which opm 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(OPM)) ;\
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.19.1/$(OS)-$(ARCH)-opm ;\
chmod +x $(OPM) ;\
}
else
OPM = $(shell which opm)
endif
endif
BUNDLE_IMGS ?= $(BUNDLE_IMAGE)
CATALOG_IMG ?= $(BUNDLE_IMAGE_NAME)-catalog:v$(DASH_VERSION) ifneq ($(origin CATALOG_IMAGE_NAME), undefined) FROM_INDEX_OPT := --from-index $(CATALOG_IMAGE_NAME) endif
.PHONY: catalog-build
catalog-build: opm
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
.PHONY: catalog-push
catalog-push: ## Push the catalog image.
docker push $(CATALOG_IMG)