-
Notifications
You must be signed in to change notification settings - Fork 135
/
Makefile
107 lines (89 loc) · 4.8 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
SWAGGER_UI_VERSION?=latest
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
gen: clean ## Generate PMM API
# generated by descriptors target
../bin/buf breaking --against descriptor.bin
../bin/buf generate -v .
for API in agentlocalpb serverpb inventorypb managementpb managementpb/dbaas managementpb/ia managementpb/alerting managementpb/backup managementpb/dump managementpb/azure managementpb/role qanpb managementpb/agent managementpb/node managementpb/service platformpb 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=swagger/swagger.json \
swagger/header.json \
serverpb/json/serverpb.json \
userpb/json/userpb.json \
inventorypb/json/inventorypb.json \
managementpb/json/managementpb.json \
managementpb/backup/json/backup.json \
managementpb/alerting/json/alerting.json
../bin/swagger validate swagger/swagger.json
../bin/swagger-order --output=swagger/swagger.json swagger/swagger.json
# generate API spec with all PMM Server APIs (omit agentlocalpb)
../bin/swagger mixin --output=swagger/swagger-dev.json \
swagger/header-dev.json \
serverpb/json/serverpb.json \
userpb/json/userpb.json \
inventorypb/json/inventorypb.json \
managementpb/json/managementpb.json \
managementpb/dbaas/json/dbaas.json \
managementpb/ia/json/ia.json \
managementpb/alerting/json/alerting.json \
managementpb/backup/json/backup.json \
managementpb/dump/json/dump.json \
managementpb/azure/json/azure.json \
managementpb/role/json/role.json \
managementpb/agent/json/agent.json \
managementpb/node/json/node.json \
managementpb/service/json/service.json \
qanpb/json/qanpb.json \
platformpb/json/platformpb.json
../bin/swagger validate swagger/swagger-dev.json
../bin/swagger-order --output=swagger/swagger-dev.json swagger/swagger-dev.json
gen-alertmanager: ## Generate Alertmanager client
../bin/swagger generate client --model-package=ammodels --client-package=amclient --spec=alertmanager/openapi.yaml --target=alertmanager
format: ## Format API definitions
../bin/buf format . -w
clean-swagger:
find . -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-swagger-ui/releases/latest | grep -E '^[lL]ocation' | sed 's;^.*/;;')
else
get_swagger_version:
endif
update-swagger: get_swagger_version ## Update Swagger UI in 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-swagger-ui/archive/refs/tags/${SWAGGER_UI_VERSION}.tar.gz"
tar xf /tmp/swagger.tar.gz --transform 's;swagger-ui-.*/dist/;swagger/;g'
rm -f swagger/.npmrc
sed -i 's/url: ".*"/url: "\/swagger.json",\n validatorUrl: "none"/' swagger/swagger-initializer.js
clean: clean-swagger ## Remove generated files
find . -name '*.pb.go' -print -delete
find . -name '*.pb.gw.go' -print -delete
find . -name '*.validate.go' -print -delete
for API in agentlocalpb serverpb inventorypb managementpb userpb managementpb/azure managementpb/dbaas managementpb/dump managementpb/ia managementpb/alerting managementpb/backup management/dump managementpb/role managementpb/agent managementpb/node managementpb/service qanpb platformpb ; do \
rm -fr $$API/json/client $$API/json/models $$API/json/$$(basename $$API).json ; \
done
rm -f swagger/swagger.json swagger/swagger-dev.json
descriptors: ## Update API compatibility descriptors
../bin/buf build -o descriptor.bin --as-file-descriptor-set .