-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathMakefile
More file actions
280 lines (227 loc) · 10.8 KB
/
Makefile
File metadata and controls
280 lines (227 loc) · 10.8 KB
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
USER_GROUP := $(shell id -u):$(shell id -g)
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)
# 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)
# Where test coverage data will be written to
COVERDATA_DIR := $(shell pwd)/build/dev/startup/coverdata
ifeq ($(OS),Windows_NT)
detected_OS := Windows
else
detected_OS := $(shell uname -s)
endif
.PHONY: interuss
interuss:
go install $(EXTRA_GO_INSTALL_FLAGS) -ldflags "$(LDFLAGS)" ./cmds/...
go-mod-download: go.mod
go mod download
go.mod:
go mod tidy
.PHONY: format
format: go-format python-format
.PHONY: go-format
go-format:
gofmt -s -w .
.PHONY: lint
lint: python-lint shell-lint go-lint terraform-lint
.PHONY: check-hygiene
check-hygiene: python-lint hygiene shell-lint go-lint terraform-lint
.PHONY: python-lint
python-lint: openapi-to-go-server
docker run --rm -u "$(USER_GROUP)" --entrypoint uv \
-v "$(CURDIR)/interfaces/openapi-to-go-server:/app/" \
interuss/openapi-to-go-server \
run ruff check
docker run --rm -u "$(USER_GROUP)" --entrypoint uv \
-v "$(CURDIR)/interfaces/openapi-to-go-server:/app/" \
interuss/openapi-to-go-server \
run ruff format --check
docker run --rm -u "$(USER_GROUP)" \
-v "$(CURDIR)/deploy/operations/certificates-management:/app/" \
ghcr.io/astral-sh/ruff:0.15.10 \
check /app/ --no-cache
docker run --rm -u "$(USER_GROUP)" \
-v "$(CURDIR)/deploy/operations/certificates-management:/app/" \
ghcr.io/astral-sh/ruff:0.15.10 \
format --check /app/ --no-cache
.PHONY: python-format
python-format: openapi-to-go-server
docker run --rm -u "$(USER_GROUP)" --entrypoint uv \
-v "$(CURDIR)/interfaces/openapi-to-go-server:/app/" \
interuss/openapi-to-go-server \
run ruff check --fix
docker run --rm -u "$(USER_GROUP)" --entrypoint uv \
-v "$(CURDIR)/interfaces/openapi-to-go-server:/app/" \
interuss/openapi-to-go-server \
run ruff format
docker run --rm -u "$(USER_GROUP)" \
-v "$(CURDIR)/deploy/operations/certificates-management:/app/" \
ghcr.io/astral-sh/ruff:0.15.10 \
check /app/ --fix --no-cache
docker run --rm -u "$(USER_GROUP)" \
-v "$(CURDIR)/deploy/operations/certificates-management:/app/" \
ghcr.io/astral-sh/ruff:0.15.10 \
format /app/ --no-cache
.PHONY: hygiene
hygiene:
test/repo_hygiene/repo_hygiene.sh
.PHONY: shell-lint
shell-lint:
echo "===== Checking DSS shell lint =====" && find . -name '*.sh' | grep -v '^./interfaces/astm-utm' | git check-ignore --stdin --no-index -n -v --non-matching | grep '^::' | cut -f2 | xargs docker run --rm -v $(CURDIR):/dss -w /dss koalaman/shellcheck
.PHONY: go-lint
go-lint:
echo "===== Checking Go lint (except for *.gen.go files) =====" && docker run --rm -v $(CURDIR):/dss -w /dss golangci/golangci-lint:v2.7.2 golangci-lint run -v
.PHONY: terraform-lint
terraform-lint:
docker run --rm -w /opt/dss -v ./deploy:/opt/dss/deploy -e TF_LOG=TRACE hashicorp/terraform fmt -recursive -check
./deploy/infrastructure/utils/generate_terraform_variables.sh --lint
# This mirrors the hygiene-tests continuous integration workflow job (.github/workflows/ci.yml)
.PHONY: hygiene-tests
hygiene-tests: check-hygiene
# --- Targets to autogenerate Go code for OpenAPI-defined interfaces ---
.PHONY: apis
apis: example_apis dummy_oauth_api dss_apis
openapi-to-go-server:
docker image build -t interuss/openapi-to-go-server ./interfaces/openapi-to-go-server
dss_apis: openapi-to-go-server
docker container run -u "$(USER_GROUP)" -it \
-v "$(CURDIR)/interfaces/aux_/aux_.yaml:/resources/auxv1.yaml" \
-v "$(CURDIR)/interfaces/astm-utm/Protocol/utm.yaml:/resources/scdv1.yaml" \
-v "$(CURDIR)/interfaces/rid/v1/remoteid/augmented.yaml:/resources/ridv1.yaml" \
-v "$(CURDIR)/interfaces/rid/v2/remoteid/updated.yaml:/resources/ridv2.yaml" \
-v "$(CURDIR)/:/resources/src" \
interuss/openapi-to-go-server \
--api_import github.com/interuss/dss/pkg/api \
--api /resources/auxv1.yaml#dss \
--api /resources/scdv1.yaml#dss \
--api /resources/ridv1.yaml#dss \
--api /resources/ridv2.yaml#dss@ridv2/rid/v2 \
--api_folder /resources/src/pkg/api
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: check-dss
check-dss: evaluate-tanka test-go-units test-go-units-crdb test-e2e
.PHONY: test-go-units
test-go-units:
go test -cover -ldflags "$(LDFLAGS)" -count=1 -v ./pkg/... ./cmds/... -coverpkg=./... -test.gocoverdir=$(COVERDATA_DIR)
.PHONY: test-go-units-crdb
test-go-units-crdb: cleanup-test-go-units-crdb
@docker run -d --name dss-crdb-for-testing -p 26257:26257 -p 8080:8080 cockroachdb/cockroach:v24.1.3 start-single-node --insecure > /dev/null
@until [ -n "`docker logs dss-crdb-for-testing | grep 'nodeID'`" ]; do echo "Waiting for CRDB to be ready"; sleep 3; done;
go run ./cmds/db-manager/main.go migrate --schemas_dir ./build/db_schemas/rid --db_version latest --datastore_host localhost
go run ./cmds/db-manager/main.go migrate --schemas_dir ./build/db_schemas/scd --db_version latest --datastore_host localhost
go run ./cmds/db-manager/main.go migrate --schemas_dir ./build/db_schemas/aux_ --db_version latest --datastore_host localhost
go test -cover -count=1 -v ./pkg/rid/store/datastore --datastore_host localhost --datastore_port 26257 --datastore_ssl_mode disable --datastore_user root -test.gocoverdir=$(COVERDATA_DIR)
go test -cover -count=1 -v ./pkg/rid/application --datastore_host localhost --datastore_port 26257 --datastore_ssl_mode disable --datastore_user root -test.gocoverdir=$(COVERDATA_DIR)
go test -cover -count=1 -v ./pkg/scd/store/datastore --datastore_host localhost --datastore_port 26257 --datastore_ssl_mode disable --datastore_user root -test.gocoverdir=$(COVERDATA_DIR)
go test -cover -count=1 -v ./pkg/aux_/store/datastore --datastore_host localhost --datastore_port 26257 --datastore_ssl_mode disable --datastore_user root -test.gocoverdir=$(COVERDATA_DIR)
@docker stop dss-crdb-for-testing > /dev/null
@docker rm dss-crdb-for-testing > /dev/null
.PHONY: cleanup-test-go-units-crdb
cleanup-test-go-units-crdb:
@docker stop dss-crdb-for-testing > /dev/null 2>&1 || true
@docker rm dss-crdb-for-testing > /dev/null 2>&1 || true
.PHONY: build-dss
build-dss:
build/dev/run_locally.sh build
test-e2e: down-locally build-dss start-locally probe-locally evict-locally security-locally collect-local-logs down-locally
tag:
scripts/tag.sh $(UPSTREAM_OWNER)/dss/v$(VERSION)
.PHONY: restart-all
restart-all: build-dss down-locally start-locally
.PHONY: start-locally
start-locally:
@test ${COMPOSE_PROFILES} || echo "\033[0;96mTo start Yugabyte datastore, set the docker compose profile to with-yugabyte. Example using env variable: export COMPOSE_PROFILES=with-yugabyte\033[0m"
build/dev/run_locally.sh up -d
.PHONY: probe-locally
probe-locally:
build/dev/probe_locally.sh
.PHONY: evict-locally
evict-locally:
build/dev/evict_locally.sh
.PHONY: security-locally
security-locally:
build/dev/security_locally.sh
.PHONY: qualify-locally
qualify-locally:
build/dev/qualify_locally.sh
.PHONY: collect-local-logs
collect-local-logs:
docker logs dss_sandbox-local-dss-core-service-1 2> core-service-for-testing.log
.PHONY: clean-coverage-data
clean-coverage-data:
rm -f $(COVERDATA_DIR)/*
rm -f coverage.out
rm -f go-coverage.html
rm -f coverage.lcov
rm -rf lcov-coverage
.PHONY: coverage-report-go
coverage-report-go:
go tool covdata textfmt -i=$(COVERDATA_DIR) -o=coverage.out
go tool cover -html coverage.out -o go-coverage.html
.PHONY: coverage-report-lcov
coverage-report-lcov: coverage-report-go
gcov2lcov -infile coverage.out -outfile coverage.lcov
genhtml coverage.lcov -o lcov-coverage/
.PHONY: collect-coverage
collect-coverage:
# Issuing make commands explicitly, as we need to repeat 'down-locally'
make clean-coverage-data down-locally
make test-go-units test-go-units-crdb
make start-locally
make probe-locally qualify-locally
make down-locally
make coverage-report-go
.PHONY: stop-locally
stop-locally:
build/dev/run_locally.sh stop
.PHONY: down-locally
down-locally:
build/dev/run_locally.sh down
# This mirrors the dss-tests continuous integration workflow job (.github/workflows/ci.yml)
.PHONY: dss-tests
dss-tests: evaluate-tanka test-go-units test-go-units-crdb build-dss down-locally start-locally probe-locally collect-local-logs down-locally
.PHONY: evaluate-tanka
evaluate-tanka:
docker container run -v $(CURDIR)/deploy/services/tanka:/deploy/services/tanka grafana/tanka show --dangerous-allow-redirect /deploy/services/tanka/examples/minimum
docker container run -v $(CURDIR)/deploy/services/tanka:/deploy/services/tanka grafana/tanka show --dangerous-allow-redirect /deploy/services/tanka/examples/schema_manager
# This reproduces the entire continuous integration workflow (.github/workflows/ci.yml)
.PHONY: presubmit
presubmit: hygiene-tests dss-tests
# Serve documentation locally
.PHONY: local-doc
local-doc:
docker build -f Dockerfile.docs . -t dss-docs
docker run --rm -it -p 8888:8000 -v $(CURDIR):/app/:ro dss-docs
# Generation of documentation's assets
SOURCES_GV = $(wildcard docs/assets/*.gv)
OBJECTS_GV = $(patsubst docs/assets/%.gv, docs/assets/generated/%.png, $(SOURCES_GV))
SOURCES_PUML = $(wildcard docs/assets/*.puml)
OBJECTS_PUML = $(patsubst docs/assets/%.puml, docs/assets/generated/%.png, $(SOURCES_PUML))
docs/assets/generated/%.png: docs/assets/%.gv
dot -Tpng $< -o $@
docs/assets/generated/%.png: docs/assets/%.puml
plantuml -o generated $<
doc-assets: $(OBJECTS_GV) $(OBJECTS_PUML)
# Automatic rebuilding of assets
.PHONY: doc-assets-watch
doc-assets-watch:
while inotifywait -e modify docs/assets/*; do make doc-assets; done