forked from glamperd/indrav2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
213 lines (166 loc) · 6.56 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
project=indra
registry=docker.io/connextproject
# Specify make-specific variables (VPATH = prerequisite search path)
flags=.makeflags
VPATH=$(flags)
SHELL=/bin/bash
find_options=-type f -not -path "*/node_modules/*" -not -name "*.swp" -not -path "*/.*" -not -name "*.log"
version=$(shell cat package.json | grep '"version":' | awk -F '"' '{print $$4}')
# Get absolute paths to important dirs
cwd=$(shell pwd)
wincwd="C:\dev\workspace\indra"
bot=$(cwd)/modules/payment-bot
client=$(cwd)/modules/client
contracts=$(cwd)/modules/contracts
daicard=$(cwd)/modules/daicard
database=$(cwd)/modules/database
messaging=$(cwd)/modules/messaging
node=$(cwd)/modules/node
proxy-lock=$(cwd)/modules/proxy-lock
proxy=$(cwd)/modules/proxy
redis-lock=$(cwd)/modules/redis-lock
types=$(cwd)/modules/types
# Setup docker run time
# If on Linux, give the container our uid & gid so we know what to reset permissions to
# On Mac, the docker-VM takes care of this for us so pass root's id (ie noop)
my_id=$(shell id -u):$(shell id -g)
id=$(shell if [[ "`uname`" == "Darwin" ]]; then echo 0:0; else echo $(my_id); fi)
is_win=$(shell if [[ "`uname -a`" =~ .*Microsoft.* ]]; then echo true; else echo false; fi)
volcwd=$(shell if [ $is_win == true ]; then echo ${wincwd}; else echo ${cwd}; fi)
docker_run=docker run --name=$(project)_builder --tty --rm --volume=$(volcwd):/root $(project)_builder $(id)
log_start=@echo "=============";echo "[Makefile] => Start building $@"; date "+%s" > $(flags)/.timestamp
log_finish=@echo "[Makefile] => Finished building $@ in $$((`date "+%s"` - `cat $(flags)/.timestamp`)) seconds";echo "=============";echo
# Env setup
$(shell mkdir -p .makeflags $(node)/dist)
########################################
# Begin Phony Rules
.PHONY: default all dev prod start start-prod stop restart restart-prod clean reset push-latest backup
default: dev
all: dev prod
dev: database node types client payment-bot proxy ws-tcp-relay
prod: database node-prod proxy-prod ws-tcp-relay
start: dev
bash ops/start-dev.sh ganache
stop:
bash ops/stop.sh
restart: dev
bash ops/stop.sh
bash ops/start-dev.sh ganache
start-prod: prod
bash ops/start-prod.sh
restart-prod:
bash ops/stop.sh
bash ops/start-prod.sh
clean: stop
docker container prune -f
rm -rf $(flags)/*
rm -rf node_modules/@counterfactual/*
rm -rf modules/**/node_modules/@counterfactual/*
rm -rf modules/**/build
rm -rf modules/**/dist
rm -rf modules/**/node_modules/**/.git
reset: stop
docker container prune -f
docker volume rm `docker volume ls -q -f name=$(project)_database_test_*` 2> /dev/null || true
docker volume rm $(project)_database_dev 2> /dev/null || true
docker secret rm $(project)_database_dev 2> /dev/null || true
docker volume rm $(project)_chain_dev 2> /dev/null || true
rm -rf $(bot)/.payment-bot-db/*
rm -rf $(flags)/deployed-contracts
push-latest: prod
bash ops/push-images.sh latest database node proxy relay
push-prod: prod
bash ops/push-images.sh $(version) database node proxy relay
deployed-contracts: contracts
bash ops/deploy-contracts.sh ganache
touch $(flags)/$@
dls:
@docker service ls
@echo "====="
@docker container ls -a
########################################
# Begin Test Rules
test: test-node
watch: watch-node
start-test: prod deployed-contracts
INDRA_ETH_PROVIDER=http://localhost:8545 INDRA_MODE=test bash ops/start-prod.sh
test-ui: payment-bot
bash ops/test-ui.sh
watch-ui: node-modules
bash ops/test-ui.sh watch
test-bot: payment-bot
bash ops/test-bot.sh
test-bot-farm:
bash ops/test-bot-farm.sh
test-contracts: contracts
bash ops/test-contracts.sh
test-node: node
bash ops/test-node.sh --runInBand --forceExit
watch-node: node-modules
bash ops/test-node.sh --watch
########################################
# Begin Real Rules
builder: ops/builder.dockerfile
$(log_start)
docker build --file ops/builder.dockerfile --tag $(project)_builder:latest .
$(log_finish) && touch $(flags)/$@
client: contracts types messaging proxy-lock $(shell find $(client)/src $(find_options))
$(log_start)
$(docker_run) "cd modules/client && npm run build"
$(log_finish) && touch $(flags)/$@
contracts: node-modules $(shell find $(contracts)/contracts $(find_options))
$(log_start)
$(docker_run) "cd modules/contracts && npm run build"
$(log_finish) && touch $(flags)/$@
daicard-prod: node-modules client $(shell find $(daicard)/src $(find_options))
$(log_start)
$(docker_run) "cd modules/daicard && npm run build"
$(log_finish) && touch $(flags)/$@
database: node-modules $(shell find $(database) $(find_options))
$(log_start)
docker build --file $(database)/db.dockerfile --tag $(project)_database:latest $(database)
$(log_finish) && touch $(flags)/$@
messaging: node-modules $(shell find $(messaging)/src $(find_options))
$(log_start)
$(docker_run) "cd modules/messaging && npm run build"
$(log_finish) && touch $(flags)/$@
node: contracts types messaging redis-lock $(shell find $(node)/src $(node)/migrations $(find_options))
$(log_start)
$(docker_run) "cd modules/node && npm run build"
$(log_finish) && touch $(flags)/$@
node-modules: builder package.json $(shell ls modules/**/package.json)
$(log_start)
$(docker_run) "lerna bootstrap --hoist"
$(log_finish) && touch $(flags)/$@
node-prod: node $(node)/ops/prod.dockerfile $(node)/ops/entry.sh
$(log_start)
docker build --file $(node)/ops/prod.dockerfile --tag $(project)_node:latest .
$(log_finish) && touch $(flags)/$@
payment-bot: node-modules client types $(shell find $(bot)/src $(find_options))
$(log_start)
$(docker_run) "cd modules/payment-bot && npm run build"
$(log_finish) && touch $(flags)/$@
proxy: $(shell find $(proxy) $(find_options))
$(log_start)
docker build --file $(proxy)/dev.dockerfile --tag $(project)_proxy:dev .
$(log_finish) && touch $(flags)/$@
proxy-prod: daicard-prod $(shell find $(proxy) $(find_options))
$(log_start)
docker build --file $(proxy)/prod.dockerfile --tag $(project)_proxy:latest .
$(log_finish) && touch $(flags)/$@
redis-lock: node-modules $(shell find $(redis-lock)/src $(find_options))
$(log_start)
$(docker_run) "cd modules/redis-lock && npm run build"
$(log_finish) && touch $(flags)/$@
proxy-lock: node-modules $(shell find $(proxy-lock)/src $(find_options))
$(log_start)
$(docker_run) "cd modules/proxy-lock && npm run build"
$(log_finish) && touch $(flags)/$@
types: node-modules messaging $(shell find $(types)/src $(find_options))
$(log_start)
$(docker_run) "cd modules/types && npm run build"
$(log_finish) && touch $(flags)/$@
ws-tcp-relay: ops/ws-tcp-relay.dockerfile
$(log_start)
docker build --file ops/ws-tcp-relay.dockerfile --tag $(project)_relay:latest .
$(log_finish) && touch $(flags)/$@