-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
makefile
296 lines (222 loc) · 7.09 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
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
SHELL:=/bin/bash
INVENTORY_FILE=$(CURDIR)/inventory
SIZE=$(shell wc -l < "$(INVENTORY_FILE)" | awk '{print $$1}')
ifeq (0,$(SIZE))
SIZE = 1
endif
PROJECT_CONF=project.yaml
SECRETS=$(shell yq '.env_var.get[]' $(PROJECT_CONF))
ENV_VARS=$(SECRETS)
REGION=$(shell yq '.infra.terraform.aws.modules.environment.env_var.set.REGION.default' $(PROJECT_CONF))
ENV_FILE_NAME=$(shell yq '.env_var.set.ENV_FILE_NAME.default' $(PROJECT_CONF))
ENV_FILE=$(CURDIR)/$(ENV_FILE_NAME)
TFSTATE_ENV_SUFFIX=$(shell yq '.infra.terraform.env_var.set.TFSTATE_ENV_SUFFIX.default' $(PROJECT_CONF))
TFSTATE_EXT=$(shell yq '.infra.terraform.env_var.set.TFSTATE_EXT.default' $(PROJECT_CONF))
TFSTATE_ENV_FILE=$(TFSTATE_ENV_SUFFIX).$(TFSTATE_EXT)
COMPOSE_DIR=./docker
NOHUP_LOG=$(shell yq '.env_var.set.NOHUP_LOG.default' $(PROJECT_CONF))
REDIS_DB=$(shell yq '.services.event.env_var.set.REDIS_DB.default' $(PROJECT_CONF))
REDIS_USERNAME=$(shell yq '.services.event.env_var.set.REDIS_USERNAME.default' $(PROJECT_CONF))
REDIS_PASSWORD=$(shell yq '.services.event.env_var.set.REDIS_PASSWORD.default' $(PROJECT_CONF))
REDIS_PORT=$(shell yq '.services.event.env_var.set.REDIS_PORT.default' $(PROJECT_CONF))
REDIS_HOST=$(shell yq '.services.event.env_var.set.REDIS_HOST.default' $(PROJECT_CONF))
# approx 10 minutes
all:
@$(MAKE) -s test-inv-file
@$(MAKE) -s test-env-arg
@$(MAKE) -s test-cmd-arg
@$(MAKE) -s test-cmd-val
ifeq (deploy,$(CMD))
bash scripts/deploy-all.sh --env $(ENV)
endif
ifeq (initial-deploy,$(CMD))
bash scripts/deploy-all.sh --env $(ENV) --initial
endif
.PHONY: inventory
inventory:
@bash scripts/create-inventory.sh
@echo "project inventory size: $$(wc -l < "$(INVENTORY_FILE)" | xargs)"
list-env-vars:
@bash scripts/list-env-vars.sh
size:
@$(MAKE) -s test-inv-file
@echo $(SIZE)
print:
cat $(INVENTORY_FILE)
.PHONY: test
test:
$(MAKE) test-local
test-compose-up:
@$(MAKE) -C './tests' test-compose-up
test-docker:
@$(MAKE) -C './tests' test-docker
test-cloud:
@$(MAKE) -C './tests' test-cloud
test-local:
@$(MAKE) -C './tests' test-local
rust-coverage:
ifndef RUST_PKG
@cargo llvm-cov >/dev/null 2>&1
@cargo llvm-cov report 2>/dev/null
else
@cargo llvm-cov -p $(RUST_PKG) >/dev/null 2>&1
@cargo llvm-cov report -p $(RUST_PKG) 2>/dev/null
endif
rust-coverage-percent:
@$(MAKE) rust-coverage | grep TOTAL | awk '{print $$10}' | cut -d '.' -f1
install:
brew install node
brew install awscli
brew install warrensbox/tap/tfswitch
brew install libpq
brew link --force libpq
brew install golang-migrate
brew install yq
npm install -g eslint
# rust
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh -s -- -y
rustup component add llvm-tools-preview --toolchain stable-x86_64-apple-darwin
# https://www.docker.com/products/docker-desktop
cargo install cargo-watch
cargo install cargo-llvm-cov
env-id:
@bash scripts/create-env-id.sh
delete-env-id:
@bash scripts/delete-env-id.sh
print-env-id:
@bash scripts/print-env-id.sh
build-dev:
bash scripts/build-dev-env.sh
delete-dev:
bash scripts/delete-dev-env.sh
delete-dev-state:
(cd infra/terraform/aws/environments/dev; rm -rf .terraform* .tfplan*)
init-dev:
bash scripts/terraform-init-dev.sh \
--key $(TFSTATE_ENV_FILE) \
--dir infra/terraform/aws/environments/dev
set-env-id:
$(MAKE) resume-dev
resume-dev:
$(MAKE) -C infra/terraform/aws/environments/dev resume
new-iam:
bash scripts/manage-gitpod-iam.sh --new
delete-iam:
bash scripts/manage-gitpod-iam.sh --delete
help:
@grep -v '^\t' makefile | grep -v '^#' | grep '^[[:lower:]]' | grep -v '^if' | grep -v '^end' | sed 's/://g'
start:
bash scripts/restart-local.sh
stop:
bash scripts/stop-local.sh
restart:
$(MAKE) stop
$(MAKE) start
list-pids:
@bash scripts/list-pids.sh
list-used-ports:
@source scripts/list-env-vars.sh | grep --color=never -E "PORT$$" | xargs -I{} yq ".. | select(has(\"{}\")) | select(.{}) | .{}.default" $(PROJECT_CONF) | sort
clean:
@APP_DIRS=($$(yq '.. | select(has("local_dev") and .local_dev == true) | path | join("/")' $(PROJECT_CONF))); \
for d in "$${APP_DIRS[@]}"; do \
$(MAKE) --no-print-directory -C "$$d" clean; \
done
@$(MAKE) --no-print-directory -C tests clean
@rm -f ./$(NOHUP_LOG)
redis-uri:
@echo "redis://$(REDIS_USERNAME):$(REDIS_PASSWORD)@$(REDIS_HOST):$(REDIS_PORT)/$(REDIS_DB)"
###################### docker ######################
test-up:
@$(MAKE) test && $(MAKE) compose-up
compose-build:
bash scripts/compose.sh --build
compose-up:
bash scripts/compose.sh --up
compose-up-build:
bash scripts/compose.sh --up --build
compose-down:
bash scripts/compose.sh --down
rebuild-db:
@$(MAKE) -C migrations rebuild
@$(MAKE) -C migrations run
reset-db:
@$(MAKE) -C migrations reset
rebuild-rule:
@bash scripts/rebuild-service.sh --name rule
rebuild-request-create:
@bash scripts/rebuild-service.sh --name request-create
rebuild-request-approve:
@bash scripts/rebuild-service.sh --name request-approve
rebuild-balance-by-account:
@bash scripts/rebuild-service.sh --name balance-by-account
rebuild-request-by-id:
@bash scripts/rebuild-service.sh --name request-by-id
rebuild-requests-by-account:
@bash scripts/rebuild-service.sh --name requests-by-account
rebuild-transaction-by-id:
@bash scripts/rebuild-service.sh --name transaction-by-id
rebuild-transactions-by-account:
@bash scripts/rebuild-service.sh --name transactions-by-account
rebuild-event:
@bash scripts/rebuild-service.sh --name event
rebuild-graphql:
@bash scripts/rebuild-service.sh --name graphql
rebuild-client:
@bash scripts/rebuild-service.sh --name client
###################### demo ######################
bootcamp:
@bash scripts/bootcamp.sh
rule:
@$(MAKE) -C ./services/rule demo
request-create:
@$(MAKE) -C ./services/request-create demo
request-approve:
@$(MAKE) -C ./services/request-approve demo
balance-by-account:
@$(MAKE) -C ./services/balance-by-account demo
request-by-id:
@$(MAKE) -C ./services/request-by-id demo
requests-by-account:
@$(MAKE) -C ./services/requests-by-account demo
transaction-by-id:
@$(MAKE) -C ./services/transaction-by-id demo
transactions-by-account:
@$(MAKE) -C ./services/transactions-by-account demo
###################### postgres ######################
dump-testseed:
@$(MAKE) -C ./migrations/dumps dump-testseed
restore-testseed:
@$(MAKE) -C ./migrations/dumps restore-testseed
insert:
@$(MAKE) -C ./migrations insert
continue-insert:
bash scripts/insert-transactions.sh --continue
###################### secrets ######################
clean-env:
rm -f $(ENV_FILE)
test-env-file:
ifeq (,$(wildcard $(ENV_FILE)))
$(error no .env file, run 'make get-secrets ENV=dev')
endif
get-secrets:
@$(MAKE) -s test-env-arg
@bash scripts/create-env-file.sh \
--app-name root \
--env $(ENV)
### arg tests
test-env-arg:
ifndef ENV
$(error trailing ENV assignment missing, e.g. make all ENV=stg)
endif
test-cmd-arg:
ifndef CMD
$(error trailing CMD assignment missing, e.g. make all CMD=initial-deploy)
endif
test-cmd-val:
ifneq ($(CMD),$(filter $(CMD),deploy initial-deploy))
$(error trailing CMD assignment must be 'deploy' or 'initial-deploy')
endif
test-inv-file:
ifeq (,$(wildcard $(INVENTORY_FILE)))
$(error no inventory file, run 'make inventory')
endif