forked from FerretDB/FerretDB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.yml
521 lines (460 loc) · 16.3 KB
/
Taskfile.yml
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
---
version: 3
env:
GORACE: halt_on_error=1,history_size=2
vars:
BENCHTIME: 5s
FUZZTIME: 15s
FUZZCORPUS: ../fuzz-corpus
RACEFLAG: -race={{and (ne OS "windows") (ne ARCH "arm")}}
BUILDTAGS: ferretdb_debug,ferretdb_tigris,ferretdb_hana
SERVICES: postgres postgres_secured tigris mongodb mongodb_secured
tasks:
# invoked when `task` is run without arguments
default:
deps: [all]
all:
desc: "Generate, format, build, test and lint code and documentation"
cmds:
- task: gen
- task: build-testcover
- task: test
- task: lint
- task: security
- task: docs
gen-version:
run: once
cmds:
- go generate -x ./build/version
# do not change that target much; see "Building and packaging" in README.md
build-release:
desc: "Build bin/ferretdb{{exeExt}} (release build)"
deps: [gen-version]
cmds:
# TODO add ferretdb_hana
- go build -o=bin/ferretdb{{exeExt}} -trimpath -tags=ferretdb_tigris ./cmd/ferretdb
env:
CGO_ENABLED: 0
build-testcover:
desc: "Build bin/ferretdb-testcover{{exeExt}}"
run: once
deps: [gen-version]
cmds:
- go test -c -o=bin/ferretdb-testcover{{exeExt}} -trimpath {{.RACEFLAG}} -tags=ferretdb_testcover,{{.BUILDTAGS}} -coverpkg=./... ./cmd/ferretdb
init-tools:
dir: tools
cmds:
- go mod tidy
- go mod verify
- go generate -x
init-integration:
dir: integration
cmds:
- go mod tidy
- go mod verify
init:
desc: "Install development tools"
deps: [gen-version, init-tools, init-integration]
cmds:
- go mod tidy
- go mod verify
env-reset:
desc: "Clean ALL Go and Docker data (caches, images, volumes), and reset environment"
cmds:
- task: env-down
- cmd: docker buildx prune --all
ignore_error: true # build container may not exist
- docker system prune --all --volumes
- bin/golangci-lint{{exeExt}} cache clean
- go clean -cache -testcache -modcache -fuzzcache
- rm -fr .cache .task tools/.task integration/.task records tmp
- task: env-pull
- task: init
env-up-detach:
cmds:
- >
docker compose up --always-recreate-deps --force-recreate --remove-orphans --renew-anon-volumes --timeout=0 --detach
--build --pull=always
{{.SERVICES}}
env-up-detach-offline:
cmds:
- >
docker compose up --always-recreate-deps --force-recreate --remove-orphans --renew-anon-volumes --timeout=0 --detach
{{.SERVICES}}
env-setup:
deps: [gen-version]
cmds:
- go run {{.RACEFLAG}} ./cmd/envtool
env-logs:
cmds:
- docker compose ps --all
- docker compose logs --follow
env-up:
desc: "Start development environment"
deps: [env-up-detach, env-setup]
cmds:
- task: env-logs
env-up-offline:
deps: [env-up-detach-offline, env-setup]
cmds:
- task: env-logs
env-pull:
desc: "Pull development environment's Docker images"
cmds:
- docker compose build --pull
env-down:
desc: "Stop development environment"
cmds:
- docker compose down --remove-orphans --timeout=0 --volumes
env-data:
desc: "Fill `test` database with data for experiments"
cmds:
- bin/task{{exeExt}} -d integration env-data
gen:
desc: "Generate (and format) code"
cmds:
- go generate -x ./...
- bin/task{{exeExt}} -d integration integration-gen
- task: fmt
fmt:
desc: "Format code"
cmds:
- bin/goimports{{exeExt}} -format-only -local=github.com/FerretDB/FerretDB -w .
- bin/gofumpt{{exeExt}} -w .
test:
desc: "Run all unit and integration tests in parallel"
deps: [test-unit, test-integration]
test-unit-short:
desc: "Run short unit tests (with caching)"
cmds:
- go test -short {{.RACEFLAG}} -tags={{.BUILDTAGS}} -shuffle=on -coverprofile=cover.txt -coverpkg=./... ./...
- bin/task{{exeExt}} -d tools tools-test
test-unit:
desc: "Run all unit tests"
cmds:
- go test -count=1 {{.RACEFLAG}} -tags={{.BUILDTAGS}} -shuffle=on -coverprofile=cover.txt -coverpkg=./... ./...
- go test -count=1 {{.RACEFLAG}} -tags={{.BUILDTAGS}} -shuffle=on -bench=. -benchtime=1x ./...
- bin/task{{exeExt}} -d tools tools-test
test-integration:
desc: "Run integration tests for PostgreSQL and Tigris in parallel"
deps:
- test-integration-pg
- test-integration-tigris
- test-integration-mongodb
test-integration-pg:
desc: "Run integration tests for PostgreSQL handler"
dir: integration
cmds:
- >
go test -count=1 {{.RACEFLAG}} -tags={{.BUILDTAGS}} -shuffle=on -coverpkg=../...
-timeout=15m
-coverprofile=integration-pg.txt .
-handler=pg
-postgresql-url=postgres://[email protected]:5432/ferretdb?pool_min_conns=1
-records-dir=../records
-target-unix-socket
test-integration-tigris:
desc: "Run integration tests for Tigris handler"
dir: integration
cmds:
- >
go test -count=1 {{.RACEFLAG}} -tags={{.BUILDTAGS}} -shuffle=on -coverpkg=../...
-timeout=30m
-coverprofile=integration-tigris.txt .
-handler=tigris
-records-dir=../records
-target-tls
-compat-port=37018
-compat-tls
test-integration-cockroach:
desc: "Run integration tests for CockroachDB with pg handler"
dir: integration
cmds:
- >
go test -count=1 {{.RACEFLAG}} -tags={{.BUILDTAGS}} -shuffle=on -coverpkg=../...
-coverprofile=integration-cockroach.txt .
-handler=pg
-postgresql-url=postgres://username:[email protected]:26257/ferretdb?pool_min_conns=1
-records-dir=../records
test-integration-mongodb:
desc: "Run integration tests for MongoDB"
dir: integration
cmds:
- >
go test -count=1 {{.RACEFLAG}} -tags={{.BUILDTAGS}} -shuffle=on -coverpkg=../...
-coverprofile=integration-mongodb.txt .
-compat-port=0
-records-dir=../records
-target-port=37017
bench-short:
desc: "Benchmark for about 25 seconds (with default BENCHTIME)"
cmds:
- go test -list='Benchmark.*' ./...
- echo 'Running five functions for {{.BENCHTIME}} each...'
- go test -bench=BenchmarkArray -benchtime={{.BENCHTIME}} ./internal/bson/ | tee -a new.txt
- go test -bench=BenchmarkDocument -benchtime={{.BENCHTIME}} ./internal/bson/ | tee -a new.txt
- go test -bench=BenchmarkArray -benchtime={{.BENCHTIME}} ./internal/handlers/pg/pjson/ | tee -a new.txt
- go test -bench=BenchmarkDocument -benchtime={{.BENCHTIME}} ./internal/handlers/pg/pjson/ | tee -a new.txt
- go test -bench=BenchmarkDocument -benchtime={{.BENCHTIME}} ./internal/handlers/tigris/tjson/ | tee -a new.txt
- bin/benchstat{{exeExt}} old.txt new.txt
# That's not quite correct: https://github.com/golang/go/issues/15513
# But good enough for us.
fuzz-init:
deps: [gen-version]
cmds:
- go test -count=0 ./...
# Those commands should still run tests (i.e., should not have -run=XXX flags)
# to fill seed corpus for fuzz tests that use WriteSeedCorpusFile (e.g., FuzzHandler).
fuzz:
desc: "Fuzz for about 2 minutes (with default FUZZTIME)"
cmds:
- go test -list='Fuzz.*' ./...
- echo 'Running eight functions for {{.FUZZTIME}} each...'
- go test -fuzz=FuzzArray -fuzztime={{.FUZZTIME}} ./internal/bson/
- go test -fuzz=FuzzDocument -fuzztime={{.FUZZTIME}} ./internal/bson/
- go test -fuzz=FuzzArray -fuzztime={{.FUZZTIME}} ./internal/handlers/pg/pjson/
- go test -fuzz=FuzzDocument -fuzztime={{.FUZZTIME}} ./internal/handlers/pg/pjson/
- go test -fuzz=FuzzDocument -fuzztime={{.FUZZTIME}} ./internal/handlers/tigris/tjson/
- go test -fuzz=FuzzMsg -fuzztime={{.FUZZTIME}} ./internal/wire/
- go test -fuzz=FuzzQuery -fuzztime={{.FUZZTIME}} ./internal/wire/
- go test -fuzz=FuzzReply -fuzztime={{.FUZZTIME}} ./internal/wire/
fuzz-corpus:
desc: "Sync seed and generated fuzz corpora with FUZZCORPUS"
cmds:
- go run {{.RACEFLAG}} ./cmd/fuzztool corpus generated {{.FUZZCORPUS}}
- go run {{.RACEFLAG}} ./cmd/fuzztool corpus seed {{.FUZZCORPUS}}
- go run {{.RACEFLAG}} ./cmd/fuzztool corpus {{.FUZZCORPUS}} generated
run:
desc: "Run FerretDB"
deps: [build-testcover]
cmds:
- >
bin/ferretdb-testcover{{exeExt}} -test.coverprofile=cover.txt --
--listen-addr=:27017
--mode=diff-normal
--postgresql-url="postgres://[email protected]:5432/ferretdb"
--proxy-addr=127.0.0.1:37017
--test-records-dir=records
run-secured:
desc: "Run secured FerretDB with TLS and authentication"
deps: [build-testcover]
cmds:
- >
bin/ferretdb-testcover{{exeExt}} -test.coverprofile=cover.txt --
--listen-addr=''
--listen-tls-cert-file=./build/certs/server-cert.pem
--listen-tls-key-file=./build/certs/server-key.pem
--listen-tls-ca-file=./build/certs/rootCA.pem
--listen-tls=:27018
--mode=normal
--postgresql-url="postgres://127.0.0.1:5433/ferretdb"
--test-records-dir=records
run-tigris:
deps: [build-testcover]
cmds:
- >
bin/ferretdb-testcover{{exeExt}} -test.coverprofile=cover.txt --
--handler=tigris
--listen-addr=:27017
--listen-tls-cert-file=./build/certs/server-cert.pem
--listen-tls-key-file=./build/certs/server-key.pem
--listen-tls=:27018
--mode=diff-normal
--proxy-addr=127.0.0.1:37017
--test-records-dir=records
run-cockroach:
deps: [build-testcover]
cmds:
- >
bin/ferretdb-testcover{{exeExt}} -test.coverprofile=cover.txt --
--listen-addr=:27017
--listen-tls-cert-file=./build/certs/server-cert.pem
--listen-tls-key-file=./build/certs/server-key.pem
--listen-tls=:27018
--mode=diff-normal
--postgresql-url=postgres://username:[email protected]:26257/ferretdb
--proxy-addr=127.0.0.1:37017
--test-records-dir=records
run-proxy:
desc: "Run FerretDB in diff-proxy mode"
deps: [build-testcover]
cmds:
- >
bin/ferretdb-testcover{{exeExt}} -test.coverprofile=cover.txt --
--listen-addr=:27017
--listen-tls-cert-file=./build/certs/server-cert.pem
--listen-tls-key-file=./build/certs/server-key.pem
--listen-tls=:27018
--mode=diff-proxy
--postgresql-url="postgres://[email protected]:5432/ferretdb"
--proxy-addr=127.0.0.1:37017
--test-records-dir=records
lint:
desc: "Run linters"
cmds:
- bin/golangci-lint{{exeExt}} run --config=.golangci.yml
- bin/golangci-lint{{exeExt}} run --config=.golangci-new.yml
- bin/go-consistent{{exeExt}} -pedantic ./cmd/... ./internal/... ./build/... ./ferretdb/...
- bin/go-sumtype{{exeExt}} ./...
- go vet -vettool=./bin/checkswitch{{exeExt}} ./...
- bin/task{{exeExt}} -d integration integration-lint
- bin/task{{exeExt}} -d tools tools-lint
sources:
- "**/*.go"
- "**/go.mod"
- "**/*.yml"
security:
desc: "Run security scanners"
deps: [security-trivy, security-govulncheck]
security-trivy:
cmds:
- >
docker compose run --rm trivy filesystem .
--secret-config=./build/trivy-secret.yaml
--ignorefile=./build/.trivyignore
--cache-dir=./.cache/trivy
--exit-code=1
security-govulncheck:
cmds:
- bin/govulncheck{{exeExt}} -v -test ./...
- bin/task{{exeExt}} -d integration integration-security
godocs:
desc: "Serve godoc documentation at http://127.0.0.1:6060/pkg/github.com/FerretDB/FerretDB/?m=all"
cmds:
- bin/godoc{{exeExt}} -http=127.0.0.1:6060
psql:
desc: "Run psql"
cmds:
- docker compose exec -e PGPASSWORD=password postgres psql -U username -d ferretdb
mongosh:
desc: "Run MongoDB shell (`mongosh`)"
cmds:
- >
docker compose exec mongodb mongosh
'mongodb://host.docker.internal:27017/?heartbeatFrequencyMS=300000'
--verbose --eval 'disableTelemetry()' --shell
mongosh-secured:
desc: "Run MongoDB shell (`mongosh`) for secured FerretDB"
cmds:
- >
docker compose exec mongodb mongosh
--tlsCertificateKeyFile=/etc/certs/client.pem --tlsCAFile=/etc/certs/rootCA.pem
'mongodb://username:[email protected]:27018/?authMechanism=PLAIN&tls=true&heartbeatFrequencyMS=300000'
--verbose --eval 'disableTelemetry()' --shell
mongo-test:
desc: "Run legacy MongoDB shell (`mongo`) with test script"
cmds:
- >
docker compose run --rm legacy-mongo-shell
--tlsCertificateKeyFile /etc/certs/server.pem
--tlsCAFile /etc/certs/rootCA.pem
--tls
'mongodb://username:[email protected]:27017/?authMechanism=PLAIN'
/legacy-mongo-shell/test.js
docker-init:
cmds:
- docker buildx create --driver=docker-container --name=ferretdb --use=false
docker-local:
desc: "Build `ferretdb-local` Docker image"
deps: [gen-version]
cmds:
- >
docker buildx build --builder=ferretdb
--build-arg VERSION={{.VERSION}}
--build-arg COMMIT={{.COMMIT}}
--build-arg RACEFLAG={{.RACEFLAG}}
--tag=ferretdb-local
--load .
vars:
VERSION:
sh: cat build/version/version.txt
COMMIT:
sh: cat build/version/commit.txt
docker-push:
deps: [gen-version]
cmds:
- >
docker buildx build --builder=ferretdb
--build-arg VERSION={{.VERSION}}
--build-arg COMMIT={{.COMMIT}}
--build-arg RACEFLAG={{.RACEFLAG}}
--platform=linux/arm/v7,linux/arm64,linux/amd64
{{range splitList "," .DOCKER_IMAGES}}--tag={{trim .}} {{end -}}
--push .
vars:
VERSION:
sh: cat build/version/version.txt
COMMIT:
sh: cat build/version/commit.txt
docker-push-release:
cmds:
- task: docker-push
vars:
DOCKER_IMAGES: >
ferretdb/ferretdb:latest,
ferretdb/ferretdb:{{trimPrefix "v" .VERSION}},
ghcr.io/ferretdb/ferretdb:latest,
ghcr.io/ferretdb/ferretdb:{{trimPrefix "v" .VERSION}}
vars:
VERSION:
sh: cat build/version/version.txt
packages:
cmds:
- task: packages-deb
- task: packages-rpm
packages-deb:
dir: build
cmds:
- ../bin/nfpm{{exeExt}} package --packager=deb --target=deb/ferretdb.deb
- >
docker compose run --rm ubuntu /bin/sh -c
'dpkg -i /deb/ferretdb.deb && ferretdb --version'
env:
VERSION:
sh: cat ../build/version/version.txt
GOARCH:
sh: go env GOARCH
packages-rpm:
dir: build
cmds:
- ../bin/nfpm{{exeExt}} package --packager=rpm --target=rpm/ferretdb.rpm
- >
docker compose run --rm ubi /bin/sh -c
'rpm -i /rpm/ferretdb.rpm && ferretdb --version'
env:
VERSION:
sh: cat ../build/version/version.txt
GOARCH:
sh: go env GOARCH
docs:
desc: "Format, lint and build documentation"
deps: [docs-fmt]
cmds:
- docker compose run --rm docusaurus-docs build
blog:
desc: "Format, lint and build blog"
deps: [docs-fmt]
cmds:
- docker compose run --rm docusaurus-blog build
# see https://github.com/DavidAnson/markdownlint-cli2#command-line for the reason we use double-quotes
docs-fmt:
desc: "Format and lint documentation"
cmds:
- docker compose run --rm textlint --fix --config build/.textlintrc "**/*.md" ".github/**/*.md"
- docker compose run --rm markdownlint "**/*.md" "#CHANGELOG.md"
docs-dev:
desc: "Start documentation development server"
cmds:
- docker compose run --rm --service-ports docusaurus-docs start --host=0.0.0.0
docs-cloudflare-preview:
cmds:
# for debugging
- >
docker compose run --rm
--entrypoint='/bin/sh -c "git config --global --add safe.directory /workdir && git status"'
wrangler
- docker compose run --rm wrangler pages deployment create --project-name=docs website/build
blog-dev:
desc: "Start blog development server"
cmds:
- docker compose run --rm --service-ports docusaurus-blog start --host=0.0.0.0 --port=3001