-
Notifications
You must be signed in to change notification settings - Fork 131
/
Makefile.include
165 lines (134 loc) · 7.33 KB
/
Makefile.include
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
# vim: ts=8:sw=8:ft=make:noai:noet
SWAGGER_UI_VERSION?=latest
.PHONY: default init release gen test clean all
default: help
help: ## Display this help message
@echo "Please use \`make <target>\` where <target> is one of:"
@grep -h '^[a-zA-Z]' $(MAKEFILE_LIST) | \
awk -F ':.*?## ' 'NF==2 {printf " %-26s%s\n", $$1, $$2}'
@echo
@echo "To test DBaaS components with minikube:"
@echo "Start minikube: minikube start --cpus=2 --nodes=3 --kubernetes-version=v1.20.0"
@echo "ENABLE_DBAAS=1 NETWORK=minikube make env-up"
@echo "DBAAS_ALLOW_UNSUPPORTED_OPERATORS=1 DBAAS_PXC_OP_CHANNEL=fast-v1 ENABLE_DBAAS=1 NETWORK=minikube make env-up"
@echo Check the docker-compose.yml file to see which environment variables are available.
init: ## Install tools
rm -rf bin/*
cd tools && go generate -x -tags=tools
# Install golangci-lint
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ./bin v1.51.2 # Version should match specified in CI
release: ## Build release versions of all components
make -C agent release
make -C admin release
make -C managed release
make -C qan-api2 release
gen: clean ## Generate files
make gen-api
make gen-alertmanager
make clean_swagger
make -C agent gen
make -C admin gen
make -C managed gen
make format
make format ## TODO: One formatting run is not enough, figure out why.
go install -v ./...
gen-api: ## Generate PMM API
# generated by descriptors target
bin/buf breaking --against descriptor.bin api
bin/buf generate -v api
for API in api/agentlocalpb api/serverpb api/inventorypb api/managementpb api/managementpb/dbaas api/managementpb/ia api/managementpb/alerting api/managementpb/backup api/managementpb/azure api/managementpb/role api/qanpb api/managementpb/agent api/managementpb/node api/managementpb/service api/platformpb api/userpb; do \
set -x ; \
bin/swagger mixin $$API/json/header.json $$API/*.swagger.json --output=$$API/json/$$(basename $$API).json --keep-spec-order; \
bin/swagger flatten --with-flatten=expand --with-flatten=remove-unused $$API/json/$$(basename $$API).json --output=$$API/json/$$(basename $$API).json ; \
bin/swagger validate $$API/json/$$(basename $$API).json ; \
bin/swagger generate client --with-flatten=expand --with-flatten=remove-unused --spec=$$API/json/$$(basename $$API).json --target=$$API/json \
--additional-initialism=aws \
--additional-initialism=db \
--additional-initialism=ok \
--additional-initialism=pmm \
--additional-initialism=psmdb \
--additional-initialism=pxc \
--additional-initialism=pt \
--additional-initialism=qan \
--additional-initialism=rds \
--additional-initialism=sql \
--additional-initialism=ha ; \
done
# generate public API spec, omit agentlocalpb (always private),
# as well as a number of protos that are in beta (not v1 yet, they all go to a similar call below)
bin/swagger mixin --output=api/swagger/swagger.json \
api/swagger/header.json \
api/serverpb/json/serverpb.json \
api/userpb/json/userpb.json \
api/inventorypb/json/inventorypb.json \
api/managementpb/json/managementpb.json \
api/managementpb/backup/json/backup.json \
api/managementpb/alerting/json/alerting.json
bin/swagger validate api/swagger/swagger.json
bin/swagger-order --output=api/swagger/swagger.json api/swagger/swagger.json
# generate API spec with all PMM Server APIs (omit agentlocalpb)
bin/swagger mixin --output=api/swagger/swagger-dev.json \
api/swagger/header-dev.json \
api/serverpb/json/serverpb.json \
api/userpb/json/userpb.json \
api/inventorypb/json/inventorypb.json \
api/managementpb/json/managementpb.json \
api/managementpb/dbaas/json/dbaas.json \
api/managementpb/ia/json/ia.json \
api/managementpb/alerting/json/alerting.json \
api/managementpb/backup/json/backup.json \
api/managementpb/azure/json/azure.json \
api/managementpb/role/json/role.json \
api/managementpb/agent/json/agent.json \
api/managementpb/node/json/node.json \
api/managementpb/service/json/service.json \
api/qanpb/json/qanpb.json \
api/platformpb/json/platformpb.json
bin/swagger validate api/swagger/swagger-dev.json
bin/swagger-order --output=api/swagger/swagger-dev.json api/swagger/swagger-dev.json
gen-alertmanager: ## Generate Alertmanager client
bin/swagger generate client --model-package=ammodels --client-package=amclient --spec=api/alertmanager/openapi.yaml --target=api/alertmanager
clean_swagger:
find api -name '*.swagger.json' -print -delete
ifeq ($(shell test "${SWAGGER_UI_VERSION}" = "latest" && echo 1 || echo 0), 1)
get_swagger_version:
override SWAGGER_UI_VERSION = $(shell curl --silent --head https://github.com/swagger-api/swagger-ui/releases/latest | grep -E '^[lL]ocation' | sed 's;^.*/;;')
else
get_swagger_version:
endif
update-swagger: get_swagger_version ## Update Swagger UI in api/swagger, use `SWAGGER_UI_VERSION=xxx make update-swagger` to choose a version other than latest
curl --output /tmp/swagger.tar.gz -sSfL "https://github.com/swagger-api/swagger-ui/archive/refs/tags/${SWAGGER_UI_VERSION}.tar.gz"
tar xf /tmp/swagger.tar.gz --transform 's;swagger-ui-.*/dist/;api/swagger/;g'
rm -f api/swagger/.npmrc
sed -i 's/url: ".*"/url: "\/swagger.json",\n validatorUrl: "none"/' api/swagger/swagger-initializer.js
clean: clean_swagger ## Remove generated files
find api -name '*.pb.go' -print -delete
find api -name '*.pb.gw.go' -print -delete
find api -name '*.validate.go' -print -delete
for API in api/agentlocalpb api/serverpb api/inventorypb api/managementpb api/managementpb/dbaas api/managementpb/ia api/managementpb/alerting api/managementpb/backup api/managementpb/role api/managementpb/agent api/managementpb/node api/managementpb/service api/qanpb api/platformpb ; do \
rm -fr $$API/json/client $$API/json/models $$API/json/$$(basename $$API).json ; \
done
rm -f api/swagger/swagger.json api/swagger/swagger-dev.json
test-common: ## Run tests from API (and other shared) packages only (i.e it ignores directories that are explicitly listed)
go test $(shell go list ./... | grep -v -e admin -e agent -e managed -e api-tests -e qan-api2 -e update)
api-test: ## Run API tests on dev env. Use `PMM_KUBECONFIG=/path/to/kubeconfig.yaml make api-test` to run tests for DBaaS
go test -count=1 -race -p 1 -v ./api-tests/... -pmm.server-insecure-tls
check: ## Run required checkers and linters
LOG_LEVEL=error bin/golangci-lint run ; \
bin/go-sumtype ./... ; \
bin/go-consistent -pedantic ./...
check-license: ## Run license header checks against source files
bin/license-eye -c .licenserc.yaml header check
check-all: check-license check ## Run golangci linter to check for changes against main
bin/golangci-lint run -c=.golangci.yml --new-from-rev=main
FILES = $(shell find . -type f -name '*.go')
format: ## Format source code
bin/gofumpt -l -w $(FILES)
bin/goimports -local github.com/percona/pmm -l -w $(FILES)
bin/gci write --section Standard --section Default --section "Prefix(github.com/percona/pmm)" $(FILES)
bin/buf format api -w
serve: ## Serve API documentation with nginx
nginx -p . -c api/nginx/nginx.conf
descriptors: ## Update API compatibility descriptors
#./prototool break descriptor-set . -o api/api.descriptor
bin/buf build -o descriptor.bin --as-file-descriptor-set api