-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
208 lines (156 loc) · 7.79 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
VERSION = v1.0.1
REGISTRY ?=
BASE_IMAGE ?= alpine
TAG_LOBSTER_STORE ?= $(REGISTRY)/lobster-store:$(VERSION)
DOCKERFILE_LOBSTER_STORE ?= build/lobster-store/Dockerfile
TAG_LOBSTER_QUERY ?= $(REGISTRY)/lobster-query:$(VERSION)
DOCKERFILE_LOBSTER_QUERY ?= build/lobster-query/Dockerfile
TAG_LOBSTER_GLOBAL_QUERY ?= $(REGISTRY)/lobster-global-query:$(VERSION)
DOCKERFILE_LOBSTER_GLOBAL_QUERY ?= build/lobster-global/Dockerfile
TAG_LOBSTER_SYNCER ?= $(REGISTRY)/lobster-syncer:$(VERSION)
DOCKERFILE_LOBSTER_SYNCER ?= build/lobster-syncer/Dockerfile
TAG_LOBSTER_EXPORTER ?= $(REGISTRY)/lobster-exporter:$(VERSION)
DOCKERFILE_LOBSTER_EXPORTER ?= build/lobster-exporter/Dockerfile
TAG_LOBSTER_LOGGEN ?= $(REGISTRY)/loggen:$(VERSION)
DOCKERFILE_LOBSTER_LOGGEN ?= build/loggen/Dockerfile
TAG_LOBSTER_OPERATOR ?= $(REGISTRY)/lobster-operator:$(VERSION)
DOCKERFILE_LOBSTER_OPERATOR ?= build/lobster-operator/Dockerfile
##@ Development
.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
.PHONY: lint
lint: golangci-linter
$(GOLANGCI_LINTER) run --verbose --config .golangci.yml
.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=lobster-operator crd webhook paths="./pkg/operator/..." output:dir=deploy/templates/operator/manifests
.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="./pkg/operator/hack/boilerplate.go.txt" paths="./pkg/operator/..."
.PHONY: postProcessManifests
postProcessManifests:
@echo "Refine manifests file with helm charts condition"
@echo '{{- if .Values.operator }}' > deploy/templates/operator/manifests/crd.yaml
@echo '{{- if .Values.operator }}' > deploy/templates/operator/manifests/clusterRole.yaml
@cat deploy/templates/operator/manifests/*lobstersinks.yaml >> deploy/templates/operator/manifests/crd.yaml
@cat deploy/templates/operator/manifests/role.yaml >> deploy/templates/operator/manifests/clusterRole.yaml
@echo '{{- end }}' >> deploy/templates/operator/manifests/crd.yaml
@echo '{{- end }}' >> deploy/templates/operator/manifests/clusterRole.yaml
@rm deploy/templates/operator/manifests/*lobstersinks.yaml
@rm deploy/templates/operator/manifests/role.yaml
##@ Build Operator Dependencies
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
GOLANGCI_LINTER ?= $(LOCALBIN)/golangci-lint
SWAG ?= $(LOCALBIN)/swag
WIDDERSHINS ?= widdershins
## Tool Versions
CONTROLLER_TOOLS_VERSION ?= v0.14.0
GOLANGCI_LINT_TOOLS_VERSION ?= v1.59.1
SWAG_VERSION := v1.16.3
WIDDERSHINS_TOOLS_VERSION ?= 4.0.1
OS := $(shell uname | tr '[:upper:]' '[:lower:]')
ARCH := $(shell uname -m)
check_command = $(shell which $1 > /dev/null 2>&1 && echo "found" || echo "not found")
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
@GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
.PHONY: golangci-linter
golangci-linter: $(GOLANGCI_LINTER) ## Download golangci-linter locally if necessary.
$(GOLANGCI_LINTER): $(LOCALBIN)
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LOCALBIN) $(GOLANGCI_LINT_TOOLS_VERSION)
.PHONY: swag
swag: $(SWAG) ## Install swag if necessary.
$(SWAG): $(LOCALBIN)
@GOBIN=$(LOCALBIN) go install github.com/swaggo/swag/cmd/swag@$(SWAG_VERSION)
.PHONY: widdershins
widdershins: ## Install widdershins if necessary.
ifeq ($(call check_command,$(WIDDERSHINS)),not found)
@echo "$(WIDDERSHINS) is not found, installing via npm..."
@npm install -g widdershins@$(WIDDERSHINS_TOOLS_VERSION)
endif
##@ Generate docs
.PHONY: gen-swagger-docs-query
gen-swagger-docs-query: fmt vet swag
$(SWAG) fmt -d cmd/lobster-query,pkg/lobster/server/handler/log
$(SWAG) init -d cmd/lobster-query,pkg/lobster/server/handler/log -g main.go -o pkg/docs/query/ --parseDependency true --tags Post
cp pkg/docs/query/swagger.json web/static/docs/query/
.PHONY: gen-swagger-docs-global-query
gen-swagger-docs-global-query: fmt vet swag
$(SWAG) fmt -d cmd/lobster-global,pkg/lobster/server/handler/log
$(SWAG) init -d cmd/lobster-global,pkg/lobster/server/handler/log -g main.go -o pkg/docs/global-query/ --parseDependency true --tags Post
cp pkg/docs/global-query/swagger.json web/static/docs/global-query/
.PHONY: gen-swagger-docs-operator
gen-swagger-docs-operator: manifests postProcessManifests generate fmt vet swag
$(SWAG) fmt -d pkg/operator/server,pkg/operator/server/handler
$(SWAG) init -d pkg/operator/server,pkg/operator/server/handler -g server.go -o pkg/docs/operator/ --parseDependency true --tags Get,Put,Delete
cp pkg/docs/operator/swagger.json web/static/docs/operator/
.PHONY: gen-swagger-docs
gen-swagger-docs: gen-swagger-docs-query gen-swagger-docs-global-query gen-swagger-docs-operator
.PHONY: gen-swagger-docs-query
gen-api-docs-query: gen-swagger-docs-query widdershins
$(WIDDERSHINS) ./pkg/docs/query/swagger.yaml --code=true --shallowSchemas=true --omitHeader=true --summary=true --lang=true -o ./docs/apis/query_apis.md
.PHONY: gen-api-docs-global-query
gen-api-docs-global-query: gen-swagger-docs-global-query widdershins
$(WIDDERSHINS) ./pkg/docs/global-query/swagger.yaml --code=true --shallowSchemas=true --omitHeader=true --summary=true --lang=true -o ./docs/apis/global_query_apis.md
.PHONY: gen-api-docs-operator
gen-api-docs-operator: gen-swagger-docs-operator widdershins
$(WIDDERSHINS) ./pkg/docs/operator/swagger.yaml --code=true --shallowSchemas=true --omitHeader=true --summary=true --lang=true -o ./docs/apis/operator_apis.md
.PHONY: gen-api-docs
gen-api-docs: gen-api-docs-query gen-api-docs-global-query gen-api-docs-operator
##@ Build
.PHONY: image-store image-query image-global-query image-loggen image-exporter
image-store: fmt vet
docker build --build-arg BASE_IMAGE=${BASE_IMAGE} \
-t $(TAG_LOBSTER_STORE) -f $(DOCKERFILE_LOBSTER_STORE) .
image-query: gen-swagger-docs-query
docker build --build-arg BASE_IMAGE=${BASE_IMAGE} \
-t $(TAG_LOBSTER_QUERY) -f $(DOCKERFILE_LOBSTER_QUERY) .
image-global-query: gen-swagger-docs-global-query
docker build --build-arg BASE_IMAGE=${BASE_IMAGE} \
-t $(TAG_LOBSTER_GLOBAL_QUERY) -f $(DOCKERFILE_LOBSTER_GLOBAL_QUERY) .
image-syncer: fmt vet
docker build --build-arg BASE_IMAGE=${BASE_IMAGE} \
-t $(TAG_LOBSTER_SYNCER) -f $(DOCKERFILE_LOBSTER_SYNCER) .
image-loggen: fmt vet
docker build --build-arg BASE_IMAGE=${BASE_IMAGE} \
-t $(TAG_LOBSTER_LOGGEN) -f $(DOCKERFILE_LOBSTER_LOGGEN) .
image-exporter: fmt vet
docker build --build-arg BASE_IMAGE=${BASE_IMAGE} \
-t $(TAG_LOBSTER_EXPORTER) -f $(DOCKERFILE_LOBSTER_EXPORTER) .
image-operator: manifests generate fmt vet gen-swagger-docs-operator
docker build --build-arg BASE_IMAGE=${BASE_IMAGE} \
-t ${TAG_LOBSTER_OPERATOR} -f $(DOCKERFILE_LOBSTER_OPERATOR) .
.PHONY: push-store push-query push-global-query push-loggen push-exporter push-operator
push-store: image-store
docker push $(TAG_LOBSTER_STORE)
push-query: image-query
docker push $(TAG_LOBSTER_QUERY)
push-global-query: image-global-query
docker push $(TAG_LOBSTER_GLOBAL_QUERY)
push-syncer: image-syncer
docker push $(TAG_LOBSTER_SYNCER)
push-loggen: image-loggen
docker push $(TAG_LOBSTER_LOGGEN)
push-exporter: image-exporter
docker push $(TAG_LOBSTER_EXPORTER)
push-operator: image-operator
docker push $(TAG_LOBSTER_OPERATOR)
.PHONY: push-all
push-all: push-store push-query push-global-query push-syncer push-exporter push-loggen push-operator
.PHONY: version
version:
@echo $(VERSION)
.PHONY: tag
tag:
git tag $(VERSION)
git push origin $(VERSION)