-
Notifications
You must be signed in to change notification settings - Fork 119
/
Makefile
203 lines (151 loc) · 6.6 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
SHELL:=/usr/bin/env bash
.DEFAULT_GOAL:=all
MAKEFLAGS += --no-print-directory
DOCS_DEPLOY_USE_SSH ?= true
DOCS_DEPLOY_GIT_USER ?= git
VERSION := 0.0.0
YARN:=./build/bin/yarn.sh
PROJECT_ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
.PHONY: help # Print this help message.
help:
@grep -E '^\.PHONY: [a-zA-Z_-]+ .*?# .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = "(: |#)"}; {printf "%-30s %s\n", $$2, $$3}'
.PHONY: all # Generate API, Frontend, and backend assets.
all: preflight-checks api frontend backend-with-assets
.PHONY: api # Generate API assets.
api: yarn-ensure
tools/compile-protos.sh -c "$(PROJECT_ROOT_DIR)/api"
.PHONY: api-lint # Lint the generated API assets.
api-lint:
tools/compile-protos.sh -c "$(PROJECT_ROOT_DIR)/api" -l
.PHONY: api-lint-fix # Lint and fix the generated API assets.
api-lint-fix:
tools/compile-protos.sh -c "$(PROJECT_ROOT_DIR)/api" -lf
.PHONY: api-verify # Verify API proto changes include generate frontend and backend assets.
api-verify: yarn-ensure
find backend/api -mindepth 1 -maxdepth 1 -type d -exec rm -rf {} \;
find frontend/api/src -mindepth 1 -maxdepth 1 -type d -exec rm -rf {} \;
rm backend/internal/test/pb/*.go
$(MAKE) api
tools/ensure-no-diff.sh backend/api backend/internal/test/pb frontend/api/src
.PHONY: backend # Build the standalone backend.
backend: preflight-checks-backend
cd backend && go build -o ../build/clutch -ldflags="-X main.version=$(VERSION)"
.PHONY: backend-with-assets # Build the backend with frontend assets.
backend-with-assets: preflight-checks-backend
cd backend && go run cmd/assets/generate.go ../frontend/packages/app/build && go build -tags withAssets -o ../build/clutch -ldflags="-X main.version=$(VERSION)"
.PHONY: backend-dev # Start the backend in development mode.
backend-dev: preflight-checks-backend
tools/air.sh
.PHONY: backend-dev-mock # Start the backend in development mode with mock responses.
backend-dev-mock:
cd backend && go run mock/gateway.go
.PHONY: backend-lint # Lint the backend code.
backend-lint: preflight-checks-backend
tools/golangci-lint.sh run
.PHONY: backend-lint-fix # Lint and fix the backend code.
backend-lint-fix: preflight-checks-backend
tools/golangci-lint.sh run --fix
cd backend && go mod tidy
.PHONY: backend-test # Run unit tests for the backend code.
backend-test: preflight-checks-backend
cd backend && go test -race -covermode=atomic ./...
.PHONY: backend-verify # Verify go modules' requirements files are clean.
backend-verify:
cd backend && go mod tidy
tools/ensure-no-diff.sh backend
.PHONY: backend-config-validation
backend-config-validation:
cd backend && go run main.go -validate -c clutch-config.yaml
.PHONY: backend-integration-test
backend-integration-test:
cd backend/internal/test/integration/chaos && ./do_integration_test.sh
.PHONY: frontend-install # Install frontend dependencies.
frontend-install: yarn-ensure
$(YARN) --cwd frontend install --immutable
.PHONY: frontend # Build production frontend assets.
frontend: yarn-ensure preflight-checks-frontend frontend-install
$(YARN) --cwd frontend build
.PHONY: frontend-compile # Build development frontend assets.
frontend-compile: frontend-install
$(YARN) --cwd frontend build:dev
.PHONY: frontend-dev # Start the frontend in development mode.
frontend-dev: setup-git-hooks frontend-install
$(YARN) --cwd frontend start
.PHONY: frontend-lint # Lint the frontend code.
frontend-lint: yarn-ensure
$(YARN) --cwd frontend lint
.PHONY: frontend-lint-fix # Lint and fix the frontend code.
frontend-lint-fix: yarn-ensure
$(YARN) --cwd frontend lint:fix
.PHONY: frontend-test # Run unit tests for the frontend code.
frontend-test: yarn-ensure
$(YARN) --cwd frontend test
.PHONY: frontend-e2e # Run end-to-end tests for the frontend code.
frontend-e2e: yarn-ensure
./tools/frontend-e2e.sh
.PHONY: frontend-verify # Verify frontend packages are sorted.
frontend-verify: yarn-ensure
$(YARN) --cwd frontend lint:packages
.PHONY: docs # Build all doc assets.
docs: docs-generate yarn-ensure
$(YARN) --cwd docs/_website install --immutable && $(YARN) --cwd docs/_website build
.PHONY: docs-dev # Start the docs server in development mode.
docs-dev: docs-generate yarn-ensure
$(YARN) --cwd docs/_website install --immutable && BROWSER=none $(YARN) --cwd docs/_website start
.PHONY: docs-generate # Generate the documentation content.
docs-generate:
cd docs/_website/generator && go run .
.PHONY: dev # Run the Clutch application in development mode.
dev:
$(MAKE) -j2 backend-dev frontend-dev
.PHONY: dev-mock # Run the Clutch application in development mode with mock responses.
dev-mock:
$(MAKE) -j2 backend-dev-mock frontend-dev
.PHONY: lint # Lint all of the code.
lint: api-lint backend-lint frontend-lint
.PHONY: lint-fix # Lint and fix all of the code.
lint-fix: api-lint-fix backend-lint-fix frontend-lint-fix
.PHONY: scaffold-gateway # Generate a new gateway.
scaffold-gateway:
cd tools/scaffolding && go run scaffolder.go -m gateway -p $(shell git rev-parse --short HEAD)
.PHONY: scaffold-workflow # Generate a new Workflow package.
scaffold-workflow:
cd tools/scaffolding && go run scaffolder.go -m frontend-plugin
.PHONY: storybook # Start storybook locally.
storybook: frontend-install
$(YARN) --cwd frontend storybook
.PHONY: storybook-build # Build storybook assets for deploy.
storybook-build: frontend-install
$(YARN) --cwd frontend storybook:build
.PHONY: test # Unit test all of the code.
test: backend-test frontend-test
.PHONY: verify # Verify all of the code.
verify: api-verify backend-verify frontend-verify
.PHONY: yarn-ensure # Install the pinned version of yarn.
yarn-ensure:
@./tools/install-yarn.sh
.PHONY: dev-k8s-up # Start a local k8s cluster
dev-k8s-up:
@tools/kind.sh create cluster --kubeconfig $(PROJECT_ROOT_DIR)/build/kubeconfig-clutch --name clutch-local || true
@tools/kind.sh seed
@echo
@echo "Export these environment variables before starting development:"
@echo ' export KUBECONFIG=$(PROJECT_ROOT_DIR)/build/kubeconfig-clutch'
.PHONY: dev-k8s-down
dev-k8s-down:
@tools/kind.sh delete cluster --name clutch-local
.PHONY: preflight-checks-frontend
preflight-checks-frontend:
@tools/preflight-checks.sh frontend
.PHONY: preflight-checks-backend
preflight-checks-backend:
@tools/preflight-checks.sh backend
.PHONY: setup-git-hooks
setup-git-hooks:
@tools/setup-git-hooks.sh
.PHONY: preflight-checks
preflight-checks:
@tools/preflight-checks.sh
.PHONY: util-bump-aws # renovate does not bump all AWS packages together, this makes it easy to upgrade all of them at once
util-bump-aws:
cd backend && go list -m -f '{{if not .Indirect}}{{.Path}}{{end}}' all | grep aws-sdk-go | tr '\n' ' ' | xargs go get -u