forked from interuss/dss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
224 lines (181 loc) · 8.82 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
GOPATH := $(shell go env GOPATH 2> /dev/null)
GOBIN := $(GOPATH)/bin
UPSTREAM_OWNER := $(shell scripts/git/upstream_owner.sh)
COMMIT := $(shell scripts/git/commit.sh)
# DSS_VERSION_TAG determines the version of the DSS and is baked into
# the executable using linker flags. If the commit is not a tag,
# the version_tag will contain information about the closest tag
# (ie v0.0.1-g6a64c20, see RELEASE.md for more details).
DSS_VERSION_TAG := $(shell scripts/git/version.sh dss)
GENERATOR_TAG := generator:${DSS_VERSION_TAG}
# Build and version information is baked into the executable itself.
BUILD_LDFLAGS := -X github.com/interuss/dss/pkg/build.time=$(shell date -u '+%Y-%m-%d.%H:%M:%S') -X github.com/interuss/dss/pkg/build.commit=$(COMMIT) -X github.com/interuss/dss/pkg/build.host=$(shell hostname)
VERSION_LDFLAGS := -X github.com/interuss/dss/pkg/version.tag=$(DSS_VERSION_TAG) -X github.com/interuss/dss/pkg/version.commit=$(COMMIT)
LDFLAGS := $(BUILD_LDFLAGS) $(VERSION_LDFLAGS)
ifeq ($(OS),Windows_NT)
detected_OS := Windows
else
detected_OS := $(shell uname -s)
endif
.PHONY: interuss
interuss:
go install -ldflags "$(LDFLAGS)" ./cmds/...
go-mod-download: go.mod
go mod download
go.mod:
go mod tidy
.PHONY: format
format:
clang-format -style=file -i pkg/api/v1/ridpbv1/rid.proto
clang-format -style=file -i pkg/api/v2/ridpbv2/rid.proto
clang-format -style=file -i pkg/api/v1/scdpb/scd.proto
clang-format -style=file -i pkg/api/v1/auxpb/aux_service.proto
cd monitoring/uss_qualifier && make format
cd monitoring/mock_uss && make format
cd monitoring/monitorlib && make format
gofmt -s -w .
.PHONY: lint
lint: go_lint shell_lint
cd monitoring/uss_qualifier && make lint
.PHONY: go_lint
go_lint:
docker run --rm -v $(CURDIR):/dss -w /dss golangci/golangci-lint:v1.26.0 golangci-lint run --timeout 5m --skip-dirs /dss/build/workspace -v -E gofmt,bodyclose,rowserrcheck,misspell,golint -D staticcheck,vet
docker run --rm -v $(CURDIR):/dss -w /dss golangci/golangci-lint:v1.26.0 golangci-lint run --timeout 5m -v --disable-all --skip-dirs /dss/build/workspace -E staticcheck --skip-dirs '^cmds/http-gateway,^pkg/logging'
.PHONY: shell_lint
shell_lint:
find . -name '*.sh' | grep -v '^./interfaces/astm-utm' | grep -v '^./build/workspace' | xargs docker run --rm -v $(CURDIR):/dss -w /dss koalaman/shellcheck
pkg/api/v1/ridpbv1/rid.pb.go: pkg/api/v1/ridpbv1/rid.proto generator
docker run -v$(CURDIR):/src:delegated -w /src $(GENERATOR_TAG) protoc \
-I/usr/include \
-I/src \
-I/go/src \
-I/go/pkg/mod/github.com/grpc-ecosystem/[email protected]/third_party/googleapis \
--go_out=plugins=grpc:. $<
pkg/api/v1/ridpbv1/rid.pb.gw.go: pkg/api/v1/ridpbv1/rid.proto pkg/api/v1/ridpbv1/rid.pb.go generator
docker run -v$(CURDIR):/src:delegated -w /src $(GENERATOR_TAG) protoc \
-I/usr/include \
-I. \
-I/go/src \
-I/go/pkg/mod/github.com/grpc-ecosystem/[email protected]/third_party/googleapis \
--grpc-gateway_out=logtostderr=true,allow_delete_body=true:. $<
pkg/api/v1/ridpbv1/rid.proto: generator
[ -d $@ ] || mkdir -p pkg/api/v1/ridpbv1
docker run -v$(CURDIR):/src:delegated -w /src $(GENERATOR_TAG) openapi2proto \
-spec interfaces/rid/v1/remoteid/augmented.yaml -annotate \
-tag dss \
-indent 2 \
-package ridpbv1 > $@
pkg/api/v2/ridpbv2/rid.pb.go: pkg/api/v2/ridpbv2/rid.proto generator
docker run -v$(CURDIR):/src:delegated -w /src $(GENERATOR_TAG) protoc \
-I/usr/include \
-I/src \
-I/go/src \
-I/go/pkg/mod/github.com/grpc-ecosystem/[email protected]/third_party/googleapis \
--go_out=plugins=grpc:. $<
pkg/api/v2/ridpbv2/rid.pb.gw.go: pkg/api/v2/ridpbv2/rid.proto pkg/api/v2/ridpbv2/rid.pb.go generator
docker run -v$(CURDIR):/src:delegated -w /src $(GENERATOR_TAG) protoc \
-I/usr/include \
-I. \
-I/go/src \
-I/go/pkg/mod/github.com/grpc-ecosystem/[email protected]/third_party/googleapis \
--grpc-gateway_out=logtostderr=true,allow_delete_body=true:. $<
pkg/api/v2/ridpbv2/rid.proto: interfaces/rid_v2_adjusted.yaml generator
[ -d $@ ] || mkdir -p pkg/api/v2/ridpbv2
docker run -v$(CURDIR):/src:delegated -w /src $(GENERATOR_TAG) openapi2proto \
-spec interfaces/rid_v2_adjusted.yaml -annotate \
-tag dss \
-indent 2 \
-package ridpbv2 > $@
interfaces/rid_v2_adjusted.yaml: interfaces/rid/v2/remoteid/canonical.yaml
./interfaces/adjuster/adjust_openapi_yaml.sh ./interfaces/rid/v2/remoteid/canonical.yaml ./interfaces/rid_v2_adjusted.yaml --adjustment_profile rid --path_prefix /rid/v2
pkg/api/v1/auxpb/aux_service.pb.go: pkg/api/v1/auxpb/aux_service.proto generator
docker run -v$(CURDIR):/src:delegated -w /src $(GENERATOR_TAG) protoc \
-I/usr/include \
-I. \
-I/go/src \
-I/go/pkg/mod/github.com/grpc-ecosystem/[email protected]/third_party/googleapis \
--go_out=plugins=grpc:. $<
pkg/api/v1/auxpb/aux_service.pb.gw.go: pkg/api/v1/auxpb/aux_service.proto pkg/api/v1/auxpb/aux_service.pb.go generator
docker run -v$(CURDIR):/src:delegated -w /src $(GENERATOR_TAG) protoc \
-I/usr/include \
-I. \
-I/go/src \
-I/go/pkg/mod/github.com/grpc-ecosystem/[email protected]/third_party/googleapis \
--grpc-gateway_out=logtostderr=true,allow_delete_body=true:. $<
pkg/api/v1/scdpb/scd.pb.go: pkg/api/v1/scdpb/scd.proto generator
docker run -v$(CURDIR):/src:delegated -w /src $(GENERATOR_TAG) protoc \
-I/usr/include \
-I. \
-I/go/src \
-I/go/pkg/mod/github.com/grpc-ecosystem/[email protected]/third_party/googleapis \
--go_out=plugins=grpc:. $<
pkg/api/v1/scdpb/scd.pb.gw.go: pkg/api/v1/scdpb/scd.proto pkg/api/v1/scdpb/scd.pb.go generator
docker run -v$(CURDIR):/src:delegated -w /src $(GENERATOR_TAG) protoc \
-I/usr/include \
-I. \
-I/go/src \
-I/go/pkg/mod/github.com/grpc-ecosystem/[email protected]/third_party/googleapis \
--grpc-gateway_out=logtostderr=true,allow_delete_body=true:. $<
interfaces/scd_adjusted.yaml: interfaces/astm-utm/Protocol/utm.yaml
./interfaces/adjuster/adjust_openapi_yaml.sh ./interfaces/astm-utm/Protocol/utm.yaml ./interfaces/scd_adjusted.yaml --adjustment_profile scd
pkg/api/v1/scdpb/scd.proto: interfaces/scd_adjusted.yaml generator
docker run -v$(CURDIR):/src:delegated -w /src $(GENERATOR_TAG) openapi2proto \
-spec interfaces/scd_adjusted.yaml -annotate \
-tag dss \
-indent 2 \
-package scdpb > $@
generator:
docker build --rm -t $(GENERATOR_TAG) build/generator
.PHONY: protos
protos: pkg/api/v1/auxpb/aux_service.pb.gw.go pkg/api/v1/ridpbv1/rid.pb.gw.go pkg/api/v1/scdpb/scd.pb.gw.go pkg/api/v2/ridpbv2/rid.pb.gw.go format
# --- Targets to autogenerate Go code for OpenAPI-defined interfaces ---
.PHONY: apis
apis: example_apis dummy_oauth_api
openapi-to-go-server:
docker image build -t interuss/openapi-to-go-server ./interfaces/openapi-to-go-server
example_apis: openapi-to-go-server
$(CURDIR)/interfaces/openapi-to-go-server/generate_example.sh
dummy_oauth_api: openapi-to-go-server
docker container run -it \
-v $(CURDIR)/interfaces/dummy-oauth/dummy-oauth.yaml:/resources/dummy-oauth.yaml \
-v $(CURDIR)/cmds/dummy-oauth:/resources/output \
interuss/openapi-to-go-server \
--api_import github.com/interuss/dss/cmds/dummy-oauth/api \
--api /resources/dummy-oauth.yaml \
--api_folder /resources/output/api
# ---
.PHONY: install-staticcheck
install-staticcheck:
go install honnef.co/go/tools/cmd/staticcheck
.PHONY: staticcheck
staticcheck: install-staticcheck
staticcheck -go 1.12 ./...
.PHONY: test
test:
go test -ldflags "$(LDFLAGS)" -count=1 -v ./pkg/... ./cmds/...
.PHONY: test-cockroach
test-cockroach: cleanup-test-cockroach
@docker run -d --name dss-crdb-for-testing -p 26257:26257 -p 8080:8080 cockroachdb/cockroach:v21.2.7 start-single-node --insecure > /dev/null
go run ./cmds/db-manager/main.go --schemas_dir ./build/deploy/db_schemas/rid --db_version latest --cockroach_host localhost
go test -count=1 -v ./pkg/rid/store/cockroach --cockroach_host localhost --cockroach_port 26257 cockroach_ssl_mode disable --cockroach_user root --cockroach_db_name rid --schemas_dir db-schemas/rid
go test -count=1 -v ./pkg/scd/store/cockroach --cockroach_host localhost --cockroach_port 26257 cockroach_ssl_mode disable --cockroach_user root --cockroach_db_name scd --schemas_dir db-schemas/scd
go test -count=1 -v ./pkg/rid/application --cockroach_host localhost --cockroach_port 26257 cockroach_ssl_mode disable --cockroach_user root --cockroach_db_name rid --schemas_dir db-schemas/rid
@docker stop dss-crdb-for-testing > /dev/null
@docker rm dss-crdb-for-testing > /dev/null
.PHONY: cleanup-test-cockroach
cleanup-test-cockroach:
@docker stop dss-crdb-for-testing > /dev/null 2>&1 || true
@docker rm dss-crdb-for-testing > /dev/null 2>&1 || true
.PHONY: test-e2e
test-e2e:
test/docker_e2e.sh
.PHONY: hygiene
hygiene:
test/repo_hygiene/repo_hygiene.sh
tag: VERSION = v$(MAJOR).$(MINOR).$(PATCH)
tag:
scripts/tag.sh $(UPSTREAM_OWNER)/dss/$(VERSION)
start-locally:
build/dev/run_locally.sh
stop-locally:
build/dev/run_locally.sh stop