This repository has been archived by the owner on May 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Makefile
354 lines (268 loc) · 12.1 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
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
SHELL=/bin/bash # shell make will use to execute commands
VPATH=.flags # prerequisite search path
$(shell mkdir -p $(VPATH))
########################################
# Run shell commands to fetch info from environment
root=$(shell cd "$(shell dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )
project=$(shell cat $(root)/package.json | grep '"name":' | head -n 1 | cut -d '"' -f 4)
commit=$(shell git rev-parse HEAD | head -c 8)
# version that will be tested against for backwards compatibility checks
backwards_compatible_version=$(shell cat package.json | grep '"backwardsCompatibleWith"' | head -n 1 | cut -d '"' -f 4)
# If Linux, give the container our uid & gid so we know what to reset permissions to. If Mac, the docker-VM takes care of this for us so pass root's id (ie noop)
id=$(shell if [[ "`uname`" == "Darwin" ]]; then echo 0:0; else echo "`id -u`:`id -g`"; fi)
# Pool of images to pull cached layers from during docker build steps
image_cache=$(shell if [[ -n "${GITHUB_WORKFLOW}" ]]; then echo "--cache-from=$(project)_builder:latest,$(project)_database:latest,$(project)_ethprovider:latest,$(project)_node:latest,$(project)_proxy:latest"; else echo ""; fi)
interactive=$(shell if [[ -t 0 && -t 2 ]]; then echo "--interactive"; else echo ""; fi)
########################################
# Setup more vars
find_options=-type f -not -path "*/node_modules/*" -not -name "address-book.json" -not -name "*.swp" -not -path "*/.*" -not -path "*/cache/*" -not -path "*/build/*" -not -path "*/dist/*" -not -name "*.log"
docker_run=docker run --name=$(project)_builder $(interactive) --tty --rm --volume=$(root):/root $(project)_builder $(id)
startTime=.flags/.startTime
totalTime=.flags/.totalTime
log_start=@echo "=============";echo "[Makefile] => Start building $@"; date "+%s" > $(startTime)
log_finish=@echo $$((`date "+%s"` - `cat $(startTime)`)) > $(totalTime); rm $(startTime); echo "[Makefile] => Finished building $@ in `cat $(totalTime)` seconds";echo "=============";echo
########################################
# Build Shortcuts
default: indra
indra: database proxy node
extras: bot ethprovider test-runner
all: indra extras
########################################
# Command & Control Shortcuts
start: indra
bash ops/start-indra.sh
start-prod:
INDRA_ENV=prod bash ops/start-indra.sh
start-daicard: client
bash ops/start-daicard.sh
start-testnet: contracts
INDRA_CHAIN_LOG_LEVEL=1 bash ops/start-testnet.sh
start-bot: bot
bash ops/test/tps.sh 2 1000
stop:
bash ops/stop.sh indra
bash ops/stop.sh daicard
stop-daicard:
bash ops/stop.sh daicard
stop-all:
bash ops/stop.sh indra
bash ops/stop.sh daicard
bash ops/stop.sh testnet
restart: indra stop
bash ops/start-indra.sh
restart-prod: stop
INDRA_ENV=prod bash ops/start-indra.sh
clean: stop-all
docker container prune -f
rm -rf .flags/*
rm -rf node_modules/@connext modules/*/node_modules/@connext
rm -rf node_modules/@walletconnect modules/*/node_modules/@walletconnect
rm -rf modules/*/node_modules/*/.git
rm -rf modules/*/node_modules/.bin
rm -rf modules/contracts/artifacts modules/*/build modules/*/dist docs/build
rm -rf modules/*/.*cache* modules/*/node_modules/.cache modules/contracts/cache/*.json
rm -rf modules/*/package-lock.json
reset: stop-all
docker container prune -f
docker network rm $(project) $(project)_cf_tester $(project)_node_tester $(project)_test_store 2> /dev/null || true
docker secret rm $(project)_database_dev 2> /dev/null || true
docker volume rm $(project)_database_dev 2> /dev/null || true
docker volume rm `docker volume ls -q -f name=$(project)_database_test_*` 2> /dev/null || true
rm -rf .chaindata/*
rm -rf modules/bot/.bot-store
quick-reset:
bash ops/db.sh 'truncate table app_registry cascade;'
bash ops/db.sh 'truncate table channel cascade;'
bash ops/db.sh 'truncate table channel_rebalance_profiles_rebalance_profile cascade;'
bash ops/db.sh 'truncate table node_records cascade;'
bash ops/db.sh 'truncate table onchain_transaction cascade;'
bash ops/db.sh 'truncate table rebalance_profile cascade;'
bash ops/db.sh 'truncate table app_instance cascade;'
bash ops/redis.sh 'flushall'
rm -rf modules/bot/.bot-store
touch modules/node/src/main.ts
reset-images:
rm -f .flags/bot .flags/daicard .flags/database .flags/ethprovider .flags/node .flags/proxy .flags/test-runner
purge: clean reset
push:
bash ops/push-images.sh
pull:
bash ops/pull-images.sh
pull-latest:
bash ops/pull-images.sh latest
build-report:
bash ops/build-report.sh
lint:
bash ops/lint.sh
publish-contracts:
bash ops/npm-publish.sh contracts
publish-packages:
bash ops/npm-publish.sh
dls:
@docker service ls
@echo "====="
@docker container ls -a
########################################
# Test Runner Shortcuts
test-utils: utils
bash ops/test/unit.sh utils
test-store: store
bash ops/test/store.sh
test-contracts: contracts
bash ops/test/unit.sh contracts
test-cf: cf-core
bash ops/test/cf.sh test
test-watcher: watcher
bash ops/test/watcher.sh
test-node: node
bash ops/test/node.sh test
watch-node:
bash ops/test/node.sh watch
test-tps: bot
bash ops/test/tps.sh 5 0 10
test-tps-prod:
INDRA_ENV=prod bash ops/test/tps.sh 3 0 10
test-integration: test-runner
bash ops/test/integration.sh
watch-integration:
bash ops/test/integration.sh latest watch
test-integration-prod:
INDRA_ENV=prod bash ops/test/integration.sh
test-backwards-compatibility:
bash ops/pull-images.sh $(backwards_compatible_version)
INDRA_ENV=prod bash ops/test/integration.sh $(backwards_compatible_version)
test-daicard:
bash ops/test/daicard.sh
watch-daicard:
bash ops/test/daicard.sh --watch
test-docs: docs
$(docker_run) "source .pyEnv/bin/activate && cd docs && sphinx-build -b linkcheck -d build/linkcheck . build/html"
########################################
# Begin Real Build Rules
# All rules from here on should only depend on rules that come before it
# ie first no dependencies, last no dependents
########################################
# Common Prerequisites
builder: $(shell find ops/builder)
$(log_start)
docker build --file ops/builder/Dockerfile $(image_cache) --tag $(project)_builder ops/builder
docker tag ${project}_builder ${project}_builder:$(commit)
$(log_finish) && mv -f $(totalTime) .flags/$@
node-modules: builder package.json $(shell ls modules/*/package.json)
$(log_start)
$(docker_run) "lerna bootstrap --hoist --no-progress"
$(log_finish) && mv -f $(totalTime) .flags/$@
py-requirements: builder docs/requirements.txt
$(log_start)
$(docker_run) "bash ops/py-install.sh"
$(log_finish) && mv -f $(totalTime) .flags/$@
########################################
# Docs
.PHONY: docs
docs: documentation
documentation: py-requirements $(shell find docs $(find_options))
$(log_start)
$(docker_run) "rm -rf docs/build"
$(docker_run) "source .pyEnv/bin/activate && cd docs && sphinx-build -b html -d build/doctrees ./src build/html"
$(log_finish) && mv -f $(totalTime) .flags/$@
########################################
# Build Core JS libs & bundles
# Keep prerequisites synced w the @connext/* dependencies of each module's package.json
types: node-modules $(shell find modules/types $(find_options))
$(log_start)
$(docker_run) "cd modules/types && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
utils: types $(shell find modules/utils $(find_options))
$(log_start)
$(docker_run) "cd modules/utils && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
channel-provider: types $(shell find modules/channel-provider $(find_options))
$(log_start)
$(docker_run) "cd modules/channel-provider && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
messaging: types utils $(shell find modules/messaging $(find_options))
$(log_start)
$(docker_run) "cd modules/messaging && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
contracts: types utils $(shell find modules/contracts $(find_options))
$(log_start)
$(docker_run) "cd modules/contracts && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
store: types utils contracts $(shell find modules/store $(find_options))
$(log_start)
$(docker_run) "cd modules/store && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
cf-core: types utils store contracts $(shell find modules/cf-core $(find_options))
$(log_start)
$(docker_run) "cd modules/cf-core && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
apps: types utils contracts cf-core $(shell find modules/apps $(find_options))
$(log_start)
$(docker_run) "cd modules/apps && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
client: types utils channel-provider messaging store contracts cf-core apps watcher $(shell find modules/client $(find_options))
$(log_start)
$(docker_run) "cd modules/client && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
watcher: types utils contracts store $(shell find modules/watcher $(find_options))
$(log_start)
$(docker_run) "cd modules/watcher && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
daicard-bundle: types utils store client $(shell find modules/daicard $(find_options))
$(log_start)
$(docker_run) "cd modules/daicard && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
bot-bundle: types utils channel-provider messaging store contracts cf-core apps client $(shell find modules/bot $(find_options))
$(log_start)
$(docker_run) "cd modules/bot && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
node-bundle: types utils messaging store contracts cf-core apps watcher client $(shell find modules/node $(find_options))
$(log_start)
$(docker_run) "cd modules/node && npm run build && touch src/main.ts"
$(log_finish) && mv -f $(totalTime) .flags/$@
test-runner-bundle: types utils channel-provider messaging store contracts cf-core apps client $(shell find modules/test-runner $(find_options))
$(log_start)
$(docker_run) "cd modules/test-runner && npm run build"
$(log_finish) && mv -f $(totalTime) .flags/$@
########################################
# Build Docker Images
bot: bot-bundle $(shell find modules/bot/ops $(find_options))
$(log_start)
docker build --file modules/bot/ops/Dockerfile $(image_cache) --tag $(project)_bot modules/bot
docker tag $(project)_bot $(project)_bot:$(commit)
$(log_finish) && mv -f $(totalTime) .flags/$@
daicard: daicard-bundle $(shell find modules/daicard/ops $(find_options))
$(log_start)
docker build --file modules/daicard/ops/Dockerfile $(image_cache) --tag ${project}_daicard modules/daicard
docker tag ${project}_daicard ${project}_daicard:$(commit)
$(log_finish) && mv -f $(totalTime) .flags/$@
database: $(shell find ops/database $(find_options))
$(log_start)
docker build --file ops/database/db.dockerfile $(image_cache) --tag $(project)_database ops/database
docker tag $(project)_database $(project)_database:$(commit)
$(log_finish) && mv -f $(totalTime) .flags/$@
ethprovider: contracts $(shell find modules/contracts/ops $(find_options))
$(log_start)
docker build --file modules/contracts/ops/Dockerfile $(image_cache) --tag $(project)_ethprovider modules/contracts
docker tag $(project)_ethprovider $(project)_ethprovider:$(commit)
$(log_finish) && mv -f $(totalTime) .flags/$@
node: node-bundle $(shell find modules/node/ops $(find_options))
$(log_start)
docker build --file modules/node/ops/Dockerfile $(image_cache) --tag $(project)_node modules/node
docker tag $(project)_node $(project)_node:$(commit)
$(log_finish) && mv -f $(totalTime) .flags/$@
proxy: $(shell find ops/proxy $(find_options))
$(log_start)
docker build $(image_cache) --tag $(project)_proxy ops/proxy
docker tag $(project)_proxy $(project)_proxy:$(commit)
$(log_finish) && mv -f $(totalTime) .flags/$@
ssh-action: $(shell find ops/ssh-action $(find_options))
$(log_start)
docker build --file ops/ssh-action/Dockerfile --tag $(project)_ssh_action ops/ssh-action
docker tag $(project)_ssh_action $(project)_ssh_action:$(commit)
$(log_finish) && mv -f $(totalTime) .flags/$@
test-runner: test-runner-bundle $(shell find modules/test-runner/ops $(find_options))
$(log_start)
docker build --file modules/test-runner/ops/Dockerfile $(image_cache) --tag $(project)_test_runner modules/test-runner
docker tag $(project)_test_runner $(project)_test_runner:$(commit)
$(log_finish) && mv -f $(totalTime) .flags/$@