-
Notifications
You must be signed in to change notification settings - Fork 71
/
Makefile
159 lines (139 loc) · 7.43 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
PHONY: .docker-build .build .run .mockgen
PREFIX=/usr/local
PUBLIC_JSON_SCHEMA_DIR=docs/schema/v0/
ALL_GO_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort)
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: test
test: test-core test-flagd test-flagd-proxy
test-core:
go test -race -covermode=atomic -cover -short ./core/pkg/... -coverprofile=core-coverage.out
test-flagd:
go test -race -covermode=atomic -cover -short ./flagd/pkg/... -coverprofile=flagd-coverage.out
test-flagd-proxy:
go test -race -covermode=atomic -cover -short ./flagd-proxy/pkg/... -coverprofile=flagd-proxy-coverage.out
flagd-integration-test: # dependent on ./bin/flagd 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
go test -cover ./test/integration $(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
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:
go install -v github.com/golangci/golangci-lint/cmd/[email protected]
$(foreach module, $(ALL_GO_MOD_DIRS), ${GOPATH}/bin/golangci-lint run --deadline=5m --timeout=5m $(module)/... || exit;)
lint-fix:
go install -v github.com/golangci/golangci-lint/cmd/[email protected]
$(foreach module, $(ALL_GO_MOD_DIRS), ${GOPATH}/bin/golangci-lint run --fix --deadline=5m --timeout=5m $(module)/... || exit;)
install-mockgen:
go install go.uber.org/mock/[email protected]
mockgen: install-mockgen
cd core; mockgen -source=pkg/sync/http/http_sync.go -destination=pkg/sync/http/mock/http.go -package=syncmock
cd core; mockgen -source=pkg/sync/grpc/grpc_sync.go -destination=pkg/sync/grpc/mock/grpc.go -package=grpcmock
cd core; mockgen -source=pkg/sync/grpc/credentials/builder.go -destination=pkg/sync/grpc/credentials/mock/builder.go -package=credendialsmock
cd core; mockgen -source=pkg/evaluator/ievaluator.go -destination=pkg/evaluator/mock/ievaluator.go -package=evalmock
cd core; mockgen -source=pkg/sync/builder/syncbuilder.go -destination=pkg/sync/builder/mock/syncbuilder.go -package=middlewaremocksyncbuildermock
cd flagd; mockgen -source=pkg/service/middleware/interface.go -destination=pkg/service/middleware/mock/interface.go -package=middlewaremock
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-rules:$(MDL_DOCKER_VERSION) "**/*.md"
markdownlint-fix:
$(MDL_CMD) --entrypoint="markdownlint-cli2-fix" davidanson/markdownlint-cli2-rules:$(MDL_DOCKER_VERSION) "**/*.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 squidfunk/mkdocs-material . \
&& docker run --rm -it -p 8000:8000 -v ${PWD}:/docs squidfunk/mkdocs-material
# 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