Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
532 lines (487 loc) · 30.9 KB
/
Copy pathMakefile
File metadata and controls
532 lines (487 loc) · 30.9 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
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
522
523
524
525
526
527
528
529
530
531
532
PHONY: .docker-build .build .run .mockgen
PREFIX=/usr/local
PUBLIC_JSON_SCHEMA_DIR=docs/schema/v0/
ALL_GO_MOD_DIRS := $(shell find . \( -path ./test/integration -o -path ./.claude -o -path ./test-harness -o -path ./spec -o -path ./schemas -o -path ./playground-app -o -path "./distributions/*/build" -o -path "./test/distributions/*/build" -o -path ./.flagd-generated -o -path ./.flagd-full-build \) -prune -o -type f -name 'go.mod' -exec dirname {} \; | sort)
# The library modules: what embedders import. Tests, the FIPS tests and the benchmarks run on exactly
# these (plus the binaries), and testdata/go-packages.txt pins the packages they contain.
GO_LIB_MODULE_DIRS := ./core ./sync/file ./sync/flagd-grpc ./sync/http ./sync/openfeature-operator ./sync/gcs ./sync/azblob ./sync/s3 ./sync/sse ./sync/builder ./telemetry/otel ./eventsink/webhook ./evaluator/flagd ./configformat/flagd
# The modules flagd-full is made of besides the library ones: its main module, the runtime and the service endpoints
# (UC-001 Q7). They are tested, benchmarked and pinned like the library modules.
FLAGD_MODULE_DIRS := ./flagd ./runtime ./service/transport ./service/flag-evaluation ./service/flag-evaluation-legacy ./service/ofrep ./service/flag-sync ./service/event-collector
# The contrib component modules (vendor integrations). They are tested and pinned like the library modules, but stay
# out of GO_LIB_MODULE_DIRS: they are not what embedders import, and an engine that hashes with MD5 cannot run under
# test-fips.
CONTRIB_MODULE_DIRS := ./contrib/flagsmith/engine ./contrib/flagsmith/middleware ./contrib/flagsmith/sync
# The testbed modules (UC-022): libraries for the test suites of providers, which no distribution links. They are tested
# and pinned like the library modules.
TESTBED_MODULE_DIRS := ./testbed/control ./testbed/source ./testbed/cmd
# The FIPS variant builds against the CMVP-certified Go Cryptographic Module
# v1.0.0 (certificate #5247). The literal version is required; the
# "certified"/"inprocess" aliases vary by toolchain. The fips140 tag makes the
# binary require that module at startup rather than merely report on it.
FIPS_ENV := GOFIPS140=v1.0.0 CGO_ENABLED=0
FIPS_TAGS := fips140
FLAGD_DEV_NAMESPACE ?= flagd-dev
ZD_TEST_NAMESPACE_FLAGD_PROXY ?= flagd-proxy-zd-test
ZD_TEST_NAMESPACE ?= flagd-zd-test
ZD_CLIENT_IMG ?= zd-client:latest
FLAGD_PROXY_IMG ?= flagd-proxy:latest
FLAGD_PROXY_IMG_ZD ?= flagd-proxy:zd
DOCS_DIR ?= docs
workspace-init: workspace-clean
go work init
$(foreach module, $(ALL_GO_MOD_DIRS), go work use $(module);)
workspace-update:
$(foreach module, $(ALL_GO_MOD_DIRS), go work use $(module);)
workspace-clean:
rm -rf go.work
guard-%:
@ if [ "${${*}}" = "" ]; then \
echo "Environment variable $* not set"; \
exit 1; \
fi
docker-build: # default to flagd
make docker-build-flagd
docker-push: # default to flagd
make docker-push-flagd
docker-build-flagd:
docker buildx build --build-arg=VERSION="$$(git describe --tags --abbrev=0)" --build-arg=COMMIT="$$(git rev-parse --short HEAD)" --build-arg DATE="$$(date +%FT%TZ)" --platform="linux/arm64" -t ${IMG} -f flagd/build.Dockerfile .
docker-push-flagd:
docker buildx build --push --build-arg=VERSION="$$(git describe --tags --abbrev=0)" --build-arg=COMMIT="$$(git rev-parse --short HEAD)" --build-arg DATE="$$(date +%FT%TZ)" --platform="linux/ppc64le,linux/s390x,linux/amd64,linux/arm64" -t ${IMG} -f flagd/build.Dockerfile .
build: workspace-init # default to flagd
make build-flagd
build-flagd:
go build -ldflags "-X main.version=dev -X main.commit=$$(git rev-parse --short HEAD) -X main.date=$$(date +%FT%TZ)" -o ./bin/flagd ./flagd
.PHONY: build-flagd-fips
build-flagd-fips:
$(FIPS_ENV) go build -tags $(FIPS_TAGS) -ldflags "-X main.version=dev -X main.commit=$$(git rev-parse --short HEAD) -X main.date=$$(date +%FT%TZ)" -o ./bin/flagd-fips ./flagd
go version -m ./bin/flagd-fips | grep -E 'GOFIPS140=|-tags='
# UC-010 Q17: each standard distribution compiles as a FIPS variant too. The Builder generates the source of each
# manifest, and the FIPS build of that source carries the certified module and the fips140 tag.
STANDARD_DISTRIBUTIONS := flagd-minimal flagd-minimal-otel flagd-cloud flagd-kubernetes flagd-sync
.PHONY: build-standard-fips
build-standard-fips:
cd builder && go build -o ../bin/relay-builder ./cmd/relay-builder
@set -e; for d in $(STANDARD_DISTRIBUTIONS); do \
echo "== $$d"; \
GOWORK=off ./bin/relay-builder --manifest distributions/$$d/manifest.yaml --skip-compile; \
(cd distributions/$$d/build && GOWORK=off $(FIPS_ENV) go build -tags $(FIPS_TAGS) -o ../../../bin/$$d-fips . ); \
info=$$(go version -m ./bin/$$d-fips); \
echo "$$info" | grep -q 'GOFIPS140=v1\.0\.0' || { echo "$$d does not carry the certified module"; exit 1; }; \
echo "$$info" | grep -q -- '-tags=fips140' || { echo "$$d is not built with the fips140 tag"; exit 1; }; \
done
.PHONY: test
# One target per line, so parallel pull requests that add a test target merge cleanly.
TEST_TARGETS += test-core
TEST_TARGETS += test-flagd
TEST_TARGETS += test-flagd-proxy
TEST_TARGETS += test-contrib
TEST_TARGETS += test-builder
TEST_TARGETS += test-distributions
TEST_TARGETS += test-upgrade-accepted
TEST_TARGETS += test-image-pins
TEST_TARGETS += test-configformat-example
TEST_TARGETS += test-service-example
TEST_TARGETS += test-evaluator-testkit
TEST_TARGETS += test-inprocess-example
TEST_TARGETS += test-sync-example
TEST_TARGETS += test-telemetry-example
TEST_TARGETS += test-eventsink-example
TEST_TARGETS += test-contract-external
TEST_TARGETS += test-middleware-example
TEST_TARGETS += test-release
TEST_TARGETS += test-concurrency
TEST_TARGETS += test-porttest
TEST_TARGETS += test-tools-ci
test: $(TEST_TARGETS)
test-core: test-modules
# The loops below and CI's matrix (.github/scripts/ci-modules.json) run the same recipe, test-module.
test-modules:
@rc=0; $(foreach m,$(GO_LIB_MODULE_DIRS),$(MAKE) --no-print-directory test-module MODULE=$(m) || rc=1;) exit $$rc
test-contrib:
@rc=0; $(foreach m,$(CONTRIB_MODULE_DIRS) $(TESTBED_MODULE_DIRS),$(MAKE) --no-print-directory test-module MODULE=$(m) || rc=1;) exit $$rc
test-flagd:
@rc=0; $(foreach m,$(FLAGD_MODULE_DIRS),$(MAKE) --no-print-directory test-module MODULE=$(m) || rc=1;) exit $$rc
# The tests of one module (MODULE=core, with or without the leading ./), with the flags that `make test` has always
# used for it. The recipes of the single-module targets below are the same ones; test_ci_modules.py pins that.
TEST_MODULE := $(patsubst ./%,%,$(MODULE))
COVERED_MODULES := $(patsubst ./%,%,$(GO_LIB_MODULE_DIRS) $(FLAGD_MODULE_DIRS) $(CONTRIB_MODULE_DIRS) $(TESTBED_MODULE_DIRS))
# Modules whose tests run as `go test -race -covermode=atomic -cover -short -count=1 ./<module>/...`, with a profile.
PLAIN_TEST_MODULES := builder test/release test/service-example test/sync-example test/evaluator-testkit \
test/configformat-example test/configformat-example/distribution test/eventsink-example test/eventsink-example/distribution \
test/middleware-example test/middleware-example/distribution test/telemetry-example test/telemetry-example/distribution \
test/inprocess-example/file test/inprocess-example/filegrpc test/inprocess-example/engine test/porttest tools/ci
# Every module that leaves a <module>-coverage.out profile, uploaded by CI as the coverage-profiles artifact.
COVERAGE_MODULES := $(COVERED_MODULES) flagd-proxy $(PLAIN_TEST_MODULES)
.PHONY: test-module
test-module:
ifneq ($(filter $(TEST_MODULE),$(COVERED_MODULES)),)
go test -race -covermode=atomic -cover -short ./$(TEST_MODULE)/... -coverprofile=$(subst /,-,$(TEST_MODULE))-coverage.out
else ifeq ($(TEST_MODULE),flagd-proxy)
go test -race -covermode=atomic -cover -short ./flagd-proxy/... -coverprofile=flagd-proxy-coverage.out
else ifneq ($(filter $(TEST_MODULE),$(PLAIN_TEST_MODULES)),)
go test -race -covermode=atomic -cover -short -count=1 ./$(TEST_MODULE)/... -coverprofile=$(subst /,-,$(TEST_MODULE))-coverage.out
else ifeq ($(TEST_MODULE),test/concurrency)
go test -race -count=1 ./test/concurrency/...
else ifeq ($(TEST_MODULE),test/distributions)
cd test/distributions && go test -count=1 -timeout 30m ./...
else ifeq ($(TEST_MODULE),test/upgrade)
cd test/upgrade && go test -count=1 -run 'TestAcceptedMatchesIssue|TestSurfaces|TestGuideCoversAcceptedItems' ./...
else ifeq ($(TEST_MODULE),test/image)
cd test/image && go test -count=1 -run 'TestReferenceDockerfilePins|TestTestbedDockerfilePins' ./...
else
@echo "test-module: no test recipe for MODULE=$(MODULE); ci-modules.json lists the modules that have one"; exit 1
endif
test-sync-example:
@$(MAKE) --no-print-directory test-module MODULE=test/sync-example
test-telemetry-example:
@rc=0; for m in test/telemetry-example test/telemetry-example/distribution; do $(MAKE) --no-print-directory test-module MODULE=$$m || rc=1; done; exit $$rc
test-contract-external:
./test/contract-external.sh
test-middleware-example:
@rc=0; for m in test/middleware-example test/middleware-example/distribution; do $(MAKE) --no-print-directory test-module MODULE=$$m || rc=1; done; exit $$rc
# The release tests read the module paths of the repository and build a distribution from a file:// module proxy of it.
test-release:
@$(MAKE) --no-print-directory test-module MODULE=test/release
test-eventsink-example:
@rc=0; for m in test/eventsink-example test/eventsink-example/distribution; do $(MAKE) --no-print-directory test-module MODULE=$$m || rc=1; done; exit $$rc
test-configformat-example:
@rc=0; for m in test/configformat-example test/configformat-example/distribution; do $(MAKE) --no-print-directory test-module MODULE=$$m || rc=1; done; exit $$rc
# Opt-in, not part of `make test`: the shared engine test data of Flagsmith has no licence, so it is read from a clone
# outside this repository, at the commit that flagsmith-go-client v5.3.0 records for it.
FLAGSMITH_ENGINE_DATA_COMMIT := 2e710ea7c6994110d17d1adb40b2ec2e90e7cf44
FLAGSMITH_ENGINE_DATA_DIR ?= $(or $(XDG_CACHE_HOME),$(HOME)/.cache)/flagsmith-engine-test-data
.PHONY: flagsmith-engine-data-check
flagsmith-engine-data-check:
[ -d $(FLAGSMITH_ENGINE_DATA_DIR)/.git ] || git clone --quiet https://github.com/Flagsmith/engine-test-data.git $(FLAGSMITH_ENGINE_DATA_DIR)
git -C $(FLAGSMITH_ENGINE_DATA_DIR) fetch --quiet origin $(FLAGSMITH_ENGINE_DATA_COMMIT)
git -C $(FLAGSMITH_ENGINE_DATA_DIR) checkout --quiet $(FLAGSMITH_ENGINE_DATA_COMMIT)
FLAGSMITH_ENGINE_TEST_DATA=$(FLAGSMITH_ENGINE_DATA_DIR)/test_cases go test -count=1 -v -run TestSharedEngineTestData ./contrib/flagsmith/engine/...
test-service-example:
@$(MAKE) --no-print-directory test-module MODULE=test/service-example
# The testbed's evaluator suite lives in the test-harness submodule (git submodule update --init test-harness).
test-evaluator-testkit:
@$(MAKE) --no-print-directory test-module MODULE=test/evaluator-testkit
# The in-process examples assert on their own module graphs, which they read with the go command outside the workspace.
test-inprocess-example:
@rc=0; for m in test/inprocess-example/file test/inprocess-example/filegrpc test/inprocess-example/engine; do $(MAKE) --no-print-directory test-module MODULE=$$m || rc=1; done; exit $$rc
# The Builder is a tool of its own: it imports no relay module (UC-001 Q1).
test-builder:
@$(MAKE) --no-print-directory test-module MODULE=builder
# The concurrency module's Docker-free tests; its load tests run only when RELAY_LOAD is set (NFR-017).
test-concurrency:
go test -race -count=1 ./test/concurrency/...
# The k6 image of the concurrency load, pinned by digest. A k6 upgrade re-records the digest and re-checks the stream
# behaviour of TestStreamCloseEvents. Images are pulled, never pushed.
K6_IMAGE ?= grafana/k6:2.3.0@sha256:9c2dee7f8ed74d317e4027c06a10f169b625638189de8d4555d0b3486a5aeb34
# The load against the race build of flagd-minimal (NFR-017): the smoke runs about 60 seconds of load, the full run 10 minutes.
.PHONY: print-k6-image
print-k6-image:
@echo $(K6_IMAGE)
test-load-smoke:
K6_IMAGE=$(K6_IMAGE) RELAY_LOAD=smoke go test -count=1 -timeout 30m -run 'TestCheckerSelfTest|TestConcurrency' ./test/concurrency/...
test-load:
K6_IMAGE=$(K6_IMAGE) RELAY_LOAD=full go test -count=1 -timeout 60m ./test/concurrency/...
# The shared port helpers of the test modules.
test-porttest:
@$(MAKE) --no-print-directory test-module MODULE=test/porttest
test-tools-ci:
@$(MAKE) --no-print-directory test-module MODULE=tools/ci
# The CI helpers as one binary (tools/ci). ci-tool builds it into .relay-ci/; ci-tool-path builds it if needed and
# prints the path, for the scripts that run it (RELAY_CI overrides).
.PHONY: ci-tool ci-tool-path
ci-tool:
@CGO_ENABLED=0 GOWORK=off go build -C tools/ci -trimpath -o $(CURDIR)/.relay-ci/relay-ci .
ci-tool-path:
@$(MAKE) --no-print-directory ci-tool >&2
@echo $(CURDIR)/.relay-ci/relay-ci
test-distributions:
cd test/distributions && go test -count=1 -timeout 30m ./...
test-flagd-proxy:
@$(MAKE) --no-print-directory test-module MODULE=flagd-proxy
# fips140=only makes non-approved algorithms error or panic, so this fails if a
# tested path reaches MD5, SHA-1, RC4, 3DES or ChaCha20-Poly1305. Test mode only;
# released binaries run with fips140=on.
#
# -exec applies the GODEBUG to the test binaries only. Setting it in the
# environment would also apply it to the go command, whose module fetches over
# TLS negotiate X25519 and fail under fips140=only.
.PHONY: test-fips
test-fips:
$(FIPS_ENV) go test -tags $(FIPS_TAGS) -short -count=1 -exec 'env GODEBUG=fips140=only' $(addsuffix /...,$(GO_LIB_MODULE_DIRS)) $(addsuffix /...,$(FLAGD_MODULE_DIRS)) ./flagd-proxy/...
# Regenerate the crypto dependency closure recorded in the FIPS docs. Pinned to
# linux/amd64: the closure is platform-dependent, so an unpinned run would
# differ between a developer machine and CI.
.PHONY: fips-closure
fips-closure:
@$(FIPS_ENV) GOOS=linux GOARCH=amd64 go list -tags $(FIPS_TAGS) -deps ./flagd ./flagd-proxy \
| grep -E '^(crypto|golang\.org/x/crypto)($$|/)|/crypto($$|/)' \
| sort -u > docs/reference/fips-crypto-closure.txt
@echo "wrote docs/reference/fips-crypto-closure.txt"
# UC-013 A3: the FIPS crypto closure of each standard distribution is a subset of the recorded one (flagd-full's), so
# a distribution never reaches a cryptographic package that docs/reference/fips-140-3.md has not reviewed.
.PHONY: fips-closure-standard
fips-closure-standard:
cd builder && go build -o ../bin/relay-builder ./cmd/relay-builder
@set -e; tr -d '\r' < docs/reference/fips-crypto-closure.txt | LC_ALL=C sort -u > bin/recorded-fips-closure.txt; \
for d in $(STANDARD_DISTRIBUTIONS); do \
GOWORK=off ./bin/relay-builder --manifest distributions/$$d/manifest.yaml --skip-compile; \
(cd distributions/$$d/build && GOWORK=off $(FIPS_ENV) GOOS=linux GOARCH=amd64 go list -tags $(FIPS_TAGS) -deps .) > bin/$$d-deps.txt; \
grep -E '^(crypto|golang\.org/x/crypto)($$|/)|/crypto($$|/)' bin/$$d-deps.txt | LC_ALL=C sort -u > bin/$$d-fips-closure.txt; \
grep -qx 'crypto/fips140' bin/$$d-fips-closure.txt || { echo "$$d: the closure lacks crypto/fips140, so the package list is wrong"; exit 1; }; \
extra=$$(LC_ALL=C comm -23 bin/$$d-fips-closure.txt bin/recorded-fips-closure.txt); \
if [ -n "$$extra" ]; then echo "$$d reaches crypto packages outside the recorded closure:"; echo "$$extra"; exit 1; fi; \
echo "$$d: FIPS crypto closure is within the recorded one"; \
done
flagd-benchmark-test:
go test -bench=Bench -short -benchtime=5s -benchmem $(addsuffix /...,$(GO_LIB_MODULE_DIRS) $(FLAGD_MODULE_DIRS)) | tee benchmark.txt
flagd-integration-test-harness:
# target used to start a locally built flagd with the e2e flags
cd flagd; go run main.go start -f file:../test-harness/flags/testing-flags.json -f file:../test-harness/flags/custom-ops.json -f file:../test-harness/flags/evaluator-refs.json -f file:../test-harness/flags/zero-flags.json -f file:../test-harness/flags/edge-case-flags.json
flagd-integration-test: workspace-clean
# this is a intentionally an "orphaned" module so that it effectively does e2e testing independently of the rest of the code
cd test/integration && go test -count=1 -cover $(ARGS)
run: # default to flagd
make run-flagd
run-flagd:
cd flagd; go run main.go start -f file:../config/samples/example_flags.flagd.json
run-flagd-selector-demo:
cd flagd; go run main.go start -f file:../config/samples/example_flags.flagd.json -f file:../config/samples/example_flags.flagd.2.json
install:
cp systemd/flagd.service /etc/systemd/system/flagd.service
mkdir -p /etc/flagd
cp systemd/flags.json /etc/flagd/flags.json
mkdir -p $(DESTDIR)$(PREFIX)/bin
cp bin/flagd $(DESTDIR)$(PREFIX)/bin/flagd
systemctl start flagd
uninstall:
systemctl disable flagd
systemctl stop flagd
rm /etc/systemd/system/flagd.service
rm -f $(DESTDIR)$(PREFIX)/bin/flagd
lint:
$(MAKE) check-flagd-full-generated
go install -v github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.14.0
$(MAKE) lint-modules
# golangci-lint over every module; the binary is ${GOPATH}/bin/golangci-lint.
.PHONY: lint-modules
lint-modules:
rc=0; $(foreach module, $(ALL_GO_MOD_DIRS), ${GOPATH}/bin/golangci-lint run $(module)/... || rc=1;) exit $$rc
lint-fix:
go install -v github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.14.0
rc=0; $(foreach module, $(ALL_GO_MOD_DIRS), ${GOPATH}/bin/golangci-lint run --fix $(module)/... || rc=1;) exit $$rc
# The packages of the library modules and of flagd-full's modules must not change unnoticed, so that a move cannot drop a package from the test run.
.PHONY: check-package-coverage
check-package-coverage:
@for m in $(GO_LIB_MODULE_DIRS) $(FLAGD_MODULE_DIRS) $(CONTRIB_MODULE_DIRS) $(TESTBED_MODULE_DIRS); do (cd $$m && go list ./...) || exit 1; done | LC_ALL=C sort > .go-packages.tmp; \
tr -d '\r' < testdata/go-packages.txt > .go-packages.want; \
if ! diff -u .go-packages.want .go-packages.tmp; then rm -f .go-packages.tmp .go-packages.want; \
echo "the packages of the library modules differ from testdata/go-packages.txt"; exit 1; fi; \
rm -f .go-packages.tmp .go-packages.want
# The modules flagd-full links must not change unnoticed (UC-001 pin 1c). A module that moves to another path is the
# only accepted change: update testdata/flagd-full-modules.txt in the same commit and say so in the commit message.
.PHONY: check-flagd-full-modules flagd-full-modules
flagd-full-modules:
@go list -deps -f '{{with .Module}}{{.Path}}{{end}}' ./flagd | grep -v '^$$' | LC_ALL=C sort -u
check-flagd-full-modules:
@$(MAKE) --no-print-directory flagd-full-modules > .flagd-full-modules.tmp; tr -d '' < testdata/flagd-full-modules.txt > .flagd-full-modules.want; if ! diff -u .flagd-full-modules.want .flagd-full-modules.tmp; then rm -f .flagd-full-modules.tmp .flagd-full-modules.want; echo "the modules flagd-full links differ from testdata/flagd-full-modules.txt"; exit 1; fi; rm -f .flagd-full-modules.tmp .flagd-full-modules.want
# testdata/module-boundaries.txt lists <module dir>:<packages>:<forbidden import path regexp>; no package of
# <packages>, nor anything it imports, may match.
.PHONY: check-module-boundary check-evaluator-boundary
# testdata/module-graph-boundaries.txt lists <module dir>:<forbidden module path regexp>; none of the modules in the
# module graph of <module dir> (built outside the workspace, as an embedder would) may match.
check-module-boundary:
@while IFS=: read -r dir pkgs forbidden; do \
forbidden=$$(printf '%s' "$$forbidden" | tr -d '\r'); \
case "$$dir" in ''|'#'*) continue;; esac; \
deps=$$(cd $$dir && go list -deps $$pkgs) || exit 1; \
if echo "$$deps" | grep -E "$$forbidden"; then \
echo "$$dir $$pkgs must not depend on the packages listed above"; exit 1; \
fi; \
done < testdata/module-boundaries.txt
@while IFS=: read -r dir forbidden; do \
forbidden=$$(printf '%s' "$$forbidden" | tr -d '\r'); \
case "$$dir" in ''|'#'*) continue;; esac; \
mods=$$(cd $$dir && GOWORK=off go list -m all) || exit 1; \
if echo "$$mods" | grep -E "$$forbidden"; then \
echo "$$dir must not have the modules listed above in its module graph"; exit 1; \
fi; \
done < testdata/module-graph-boundaries.txt
check-evaluator-boundary: check-module-boundary
install-mockgen:
go install go.uber.org/mock/mockgen@v0.4.0
mockgen: install-mockgen
cd sync/http; mockgen -source=http_sync.go -destination=mock/http.go -package=syncmock
cd sync/flagd-grpc; mockgen -source=grpc_sync.go -destination=mock/grpc.go -package=grpcmock
cd sync/flagd-grpc; mockgen -source=credentials/builder.go -destination=credentials/mock/builder.go -package=credendialsmock
cd core; mockgen -source=pkg/evaluator/ievaluator.go -destination=pkg/evaluator/mock/ievaluator.go -package=evalmock
cd sync/builder; mockgen -source=syncbuilder.go -destination=mock/syncbuilder.go -package=middlewaremocksyncbuildermock
cd service/transport; mockgen -source=middleware/interface.go -destination=middleware/mock/interface.go -package=middlewaremock
cd service/flag-evaluation; mockgen -source=flag_evaluator_v2.go -destination=mock/eventstream.go -package=flagevalmock
generate-docs:
cd flagd; go run ./cmd/doc/main.go
.PHONY: deploy-dev-env
export IMG?= ghcr.io/open-feature/flagd:latest
deploy-dev-env: undeploy-dev-env
kubectl create ns "$(FLAGD_DEV_NAMESPACE)"
envsubst '$${IMG}' < config/deployments/flagd/deployment.yaml | kubectl apply -f - -n "$(FLAGD_DEV_NAMESPACE)"
kubectl apply -f config/deployments/flagd/service.yaml -n "$(FLAGD_DEV_NAMESPACE)"
kubectl wait --for=condition=available deployment/flagd -n "$(FLAGD_DEV_NAMESPACE)" --timeout=300s
undeploy-dev-env:
kubectl delete ns "$(FLAGD_DEV_NAMESPACE)" --ignore-not-found=true
run-zd-test:
kubectl delete ns "$(ZD_TEST_NAMESPACE)" --ignore-not-found=true
kubectl create ns "$(ZD_TEST_NAMESPACE)"
ZD_TEST_NAMESPACE="$(ZD_TEST_NAMESPACE)" FLAGD_DEV_NAMESPACE=$(FLAGD_DEV_NAMESPACE) IMG="$(IMG)" IMG_ZD="$(IMG_ZD)" ./test/zero-downtime/zd_test.sh
run-flagd-proxy-zd-test:
ZD_TEST_NAMESPACE_FLAGD_PROXY="$(ZD_TEST_NAMESPACE_FLAGD_PROXY)" FLAGD_PROXY_IMG="$(FLAGD_PROXY_IMG)" FLAGD_PROXY_IMG_ZD="$(FLAGD_PROXY_IMG_ZD)" ZD_CLIENT_IMG="$(ZD_CLIENT_IMG)" ./test/zero-downtime-flagd-proxy/zd_test.sh
# Markdown lint configuration
#
# - .markdownlintignore holds the configuration for files to be ignored
# - .markdownlint.yaml contains the rules for markdownfiles
MDL_DOCKER_VERSION := next
ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
MDL_CMD := docker run -v $(ROOT_DIR):/workdir --rm
.PHONY: markdownlint markdownlint-fix
markdownlint:
$(MDL_CMD) davidanson/markdownlint-cli2:$(MDL_DOCKER_VERSION) "**/*.md"
markdownlint-fix:
$(MDL_CMD) davidanson/markdownlint-cli2:$(MDL_DOCKER_VERSION) --fix "**/*.md"
.PHONY: pull-schemas-submodule
pull-schemas-submodule:
git submodule update schemas
.PHONY: generate-proto-docs
generate-proto-docs: pull-schemas-submodule
docker run --rm -v ${PWD}/$(DOCS_DIR)/reference/specifications:/out -v ${PWD}/schemas/protobuf:/protos pseudomuto/protoc-gen-doc --doc_opt=markdown,protos-with-toc.md flagd/evaluation/v1/evaluation.proto flagd/sync/v1/sync.proto \
&& echo '<!-- WARNING: THIS DOC IS AUTO-GENERATED. DO NOT EDIT! -->' > ${PWD}/$(DOCS_DIR)/reference/specifications/protos.md \
&& sed '/^## Table of Contents/,/#top/d' ${PWD}/$(DOCS_DIR)/reference/specifications/protos-with-toc.md >> ${PWD}/$(DOCS_DIR)/reference/specifications/protos.md \
&& rm -f ${PWD}/$(DOCS_DIR)/reference/specifications/protos-with-toc.md
# Update the schema at flagd.dev
# PUBLIC_JSON_SCHEMA_DIR above controls the dir (and therefore major version)
.PHONY: update-public-schema
update-public-schema: pull-schemas-submodule
rm -f $(PUBLIC_JSON_SCHEMA_DIR)*.json
cp schemas/json/*.json $(PUBLIC_JSON_SCHEMA_DIR)
.PHONY: run-web-docs
run-web-docs: generate-docs generate-proto-docs
docker build -t flag-docs:latest . --load \
&& docker run --rm -it -p 8000:8000 -v ${PWD}:/docs flag-docs:latest
# Run the playground app in dev mode
# See the readme in the playground-app folder for more details
.PHONY: playground-dev
playground-dev:
cd playground-app && npm ci && npm run dev
# Build the playground app
# See the readme in the playground-app folder for more details
.PHONY: playground-build
playground-build:
cd playground-app && npm ci && npm run build
# Publish the playground app to the docs folder
# See the readme in the playground-app folder for more details
.PHONY: playground-publish
playground-publish: playground-build
cp playground-app/dist/assets/index-*.js docs/playground/playground.js
# UC-009: the flagd module is the Builder's output for distributions/flagd-full/manifest.yaml. The Builder generates its
# go.mod, main.go and components/components.go; this target regenerates them into a directory beside flagd/, so that
# the replaces come out the same, and fails when what is committed differs. A hand edit of a generated file, or a
# manifest edit without the regenerated files, fails here.
FLAGD_FULL_CHECK_DIR := .flagd-generated
.PHONY: check-flagd-full-generated
check-flagd-full-generated:
cd builder && go build -o ../bin/relay-builder ./cmd/relay-builder
rm -rf $(FLAGD_FULL_CHECK_DIR)
cp -r flagd $(FLAGD_FULL_CHECK_DIR)
GOWORK=off ./bin/relay-builder --manifest distributions/flagd-full/manifest.yaml --skip-compile --output $(FLAGD_FULL_CHECK_DIR) \
|| { rm -rf $(FLAGD_FULL_CHECK_DIR); exit 1; }
rc=0; for f in go.mod main.go components/components.go; do \
diff -u flagd/$$f $(FLAGD_FULL_CHECK_DIR)/$$f || rc=1; done; \
rm -rf $(FLAGD_FULL_CHECK_DIR); \
if [ $$rc -ne 0 ]; then echo "flagd/ differs from the Builder's output for distributions/flagd-full/manifest.yaml; run: make generate-flagd-full"; fi; \
exit $$rc
# Regenerates the flagd module from the manifest of flagd-full.
.PHONY: generate-flagd-full
generate-flagd-full:
cd builder && go build -o ../bin/relay-builder ./cmd/relay-builder
GOWORK=off ./bin/relay-builder --manifest distributions/flagd-full/manifest.yaml --skip-compile
# UC-001 7a: the Builder builds flagd-full from its manifest, the binary is named flagd, and the duration is printed
# (NFR-008 asks for under three minutes). Run it with a warm module cache. The binary and the pins that run against it
# stay out of flagd/.
FLAGD_FULL_BUILD_DIR := .flagd-full-build
# NFR-008: a warm build of flagd-full finishes within three minutes.
FLAGD_FULL_BUILD_LIMIT ?= 180
.PHONY: build-flagd-full
build-flagd-full:
cd builder && go build -o ../bin/relay-builder ./cmd/relay-builder
rm -rf $(FLAGD_FULL_BUILD_DIR)
start=$$(date +%s); \
GOWORK=off ./bin/relay-builder --manifest distributions/flagd-full/manifest.yaml --output $(FLAGD_FULL_BUILD_DIR) || exit 1; \
took=$$(( $$(date +%s) - start )); echo "flagd-full built in $${took}s"; \
if [ "$${took}" -gt "$(FLAGD_FULL_BUILD_LIMIT)" ]; then echo "NFR-008: flagd-full took $${took}s, over $(FLAGD_FULL_BUILD_LIMIT)s"; exit 1; fi
test -x $(FLAGD_FULL_BUILD_DIR)/flagd
cd flagd && FLAGD_BINARY=$$(cd ../$(FLAGD_FULL_BUILD_DIR) && pwd)/flagd go test -count=1 -run "TestCLICharacterization|TestStartupLogCharacterization" ./
# UC-019: the Builder builds the flagsmith vendor distribution from its manifest. Flagsmith's flagengine resolves from
# the module proxy, so the build needs network access or a warm module cache. There is no FIPS variant of it: the engine
# hashes with MD5.
FLAGSMITH_BUILD_DIR := .flagsmith-build
.PHONY: build-flagsmith
build-flagsmith:
cd builder && go build -o ../bin/relay-builder ./cmd/relay-builder
rm -rf $(FLAGSMITH_BUILD_DIR)
GOWORK=off ./bin/relay-builder --manifest distributions/flagsmith/manifest.yaml --output $(FLAGSMITH_BUILD_DIR)
test -x $(FLAGSMITH_BUILD_DIR)/flagsmith
$(FLAGSMITH_BUILD_DIR)/flagsmith components --output json | grep -q 'contrib/flagsmith/engine"'
# UC-001, UC-009, UC-019: the flagd module is what the Builder generates, and the Builder's binary passes the pins; the
# vendor distribution builds too.
.PHONY: builder-e2e
builder-e2e: check-flagd-full-generated build-flagd-full build-flagsmith
# UC-009: the differential of today's flagd against the flagd-full the Builder made. It builds two images, so it needs
# Docker and stays out of `make test`; TestAcceptedMatchesIssue does not need Docker and runs there.
.PHONY: upgrade-test test-upgrade-accepted refresh-issue-78 image-test test-image-pins
upgrade-test:
cd test/upgrade && UPGRADE_TEST=1 go test -count=1 -timeout 60m -v ./...
# The reference image's tests build images with buildx (UC-002).
image-test:
cd test/image && IMAGE_TEST=1 go test -count=1 -timeout 60m -v ./...
test-image-pins:
cd test/image && go test -count=1 -run 'TestReferenceDockerfilePins|TestTestbedDockerfilePins' ./...
test-upgrade-accepted:
cd test/upgrade && go test -count=1 -run 'TestAcceptedMatchesIssue|TestSurfaces|TestGuideCoversAcceptedItems' ./...
# Refreshes the list of behaviour changes that accepted.yaml has to cover.
refresh-issue-78:
gh issue view 78 --repo open-feature-forking/openfeature-relay --json body --jq .body > test/upgrade/testdata/issue-78.txt
# UC-022: the launchpad contract of a flagd testbed image. testbed-launchpad-image builds today's upstream image from the
# test-harness submodule (git submodule update --init test-harness); KIND is launchpad or relay.
.PHONY: testbed-launchpad-image testbed-contract
testbed-launchpad-image:
docker build -f test-harness/flagd/Dockerfile -t testbed-launchpad:local test-harness
testbed-contract:
@test -n "$(IMAGE)" || { echo "usage: make testbed-contract IMAGE=<image> [KIND=launchpad|relay]"; exit 1; }
cd test/testbed && TESTBED_IMAGE=$(IMAGE) TESTBED_KIND=$(or $(KIND),launchpad) go test -count=1 -timeout 30m -v ./...
# The relay testbed image: the testbed distribution, which the Builder generates from its manifest (UC-022). With
# TESTBED_RELAY_IMAGE set, the image is already there (CI loads it from the layout it publishes) and is not built.
TESTBED_RELAY_IMAGE ?= flagd-testbed:local
.PHONY: testbed-relay-image testbed-contract-both testbed-suites testbed-rpc-outages
testbed-relay-image:
ifeq ($(origin TESTBED_RELAY_IMAGE),file)
docker build -f distributions/flagd-testbed/Dockerfile -t $(TESTBED_RELAY_IMAGE) .
else
@echo "using $(TESTBED_RELAY_IMAGE), not building the relay testbed image"
endif
# The contract against both images: the launchpad as it is, the relay testbed with its quirks fixed.
testbed-contract-both: testbed-launchpad-image testbed-relay-image
$(MAKE) testbed-contract IMAGE=testbed-launchpad:local KIND=launchpad
$(MAKE) testbed-contract IMAGE=$(TESTBED_RELAY_IMAGE) KIND=relay
# TestRPC and TestInProcess against both images, which must pass the same scenarios (UC-022 Q14). The outage scenarios
# (@reconnect, @events, @grace) are included by testbed-rpc-outages (Q16).
testbed-suites: testbed-launchpad-image testbed-relay-image
.github/scripts/testbed-suites.sh
testbed-rpc-outages: testbed-launchpad-image testbed-relay-image
.github/scripts/testbed-suites.sh outages
# UC-023 (Q14): flagd-full with a grpc source against the relay testbed. It builds both images, so it needs Docker and
# stays out of `make test`; the test skips without TESTBED_FLAGD_IMAGE.
.PHONY: testbed-grpc-sync
testbed-grpc-sync:
docker build -f distributions/flagd-testbed/Dockerfile -t testbed-relay:grpc-sync .
docker build -f flagd/build.Dockerfile -t flagd-full:grpc-sync .
cd test/testbed && TESTBED_IMAGE=testbed-relay:grpc-sync TESTBED_KIND=relay TESTBED_FLAGD_IMAGE=flagd-full:grpc-sync \
go test -count=1 -timeout 30m -v -run 'TestGRPCSource' ./...