forked from connext/indra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
270 lines (212 loc) · 9.02 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
registry=docker.io/connextproject
project=$(shell cat package.json | grep '"name":' | awk -F '"' '{print $$4}')
# Get absolute paths to important dirs
cwd=$(shell pwd)
contracts=$(cwd)/modules/contracts
client=$(cwd)/modules/client
db=$(cwd)/modules/database
hub=$(cwd)/modules/hub
proxy=$(cwd)/modules/proxy
dashboard=$(cwd)/modules/dashboard
# Specify make-specific variables (VPATH = prerequisite search path)
VPATH=build
SHELL=/bin/bash
# Fetch Prerequisites
find_options=-type f -not -path "*/node_modules/*" -not -name "*.swp" -not -path "*/.*" -not -name "*.log"
# 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 care of this for us so pass root's id (noop)
my_id=$(shell id -u):$(shell id -g)
id=$(shell if [[ "`uname`" == "Darwin" ]]; then echo 0:0; else echo $(my_id); fi)
docker_run=docker run --name=$(project)_builder --tty --rm
docker_run_in_client=$(docker_run) --volume=$(client):/root $(project)_builder $(id)
docker_run_in_contracts=$(docker_run) --volume=$(client):/client --volume=$(contracts):/root $(project)_builder $(id)
docker_run_in_hub=$(docker_run) --volume=$(client):/client --volume=$(hub):/root $(project)_builder $(id)
docker_run_in_db=$(docker_run) --volume=$(db):/root $(project)_builder $(id)
docker_run_in_dashboard=$(docker_run) --volume=$(dashboard):/root $(project)_builder $(id)
# Env setup
$(shell mkdir -p build $(contracts)/build $(db)/build $(hub)/dist)
version=$(shell cat package.json | grep "\"version\":" | egrep -o "[.0-9]+")
install=npm install --prefer-offline --unsafe-perm
log_start=@echo "=============";echo "[Makefile] => Start building $@"; date "+%s" > build/.timestamp
log_finish=@echo "[Makefile] => Finished building $@ in $$((`date "+%s"` - `cat build/.timestamp`)) seconds";echo "=============";echo
########################################
# Begin Phony Rules
.PHONY: default all dev prod stop clean reset purge push push-live backup
default: dev
all: dev prod
dev: hooks database hub proxy client dashboard
prod: hooks database-prod hub-prod proxy-prod dashboard-server-prod
start: dev
bash ops/deploy.dev.sh
start-prod: prod
bash ops/deploy.prod.sh
stop:
bash ops/stop.sh
clean: stop
docker container prune -f
rm -rf build/*
rm -rf modules/**/build
rm -rf modules/**/dist
reset-base: stop
docker container prune -f
docker volume rm $(project)_database_dev 2> /dev/null || true
reset-client: reset-base
rm -rf build/client* $(client)/dist $(client)/node_modules $(client)/package-lock.json
reset-contracts: reset-base
rm -rf build/contract* $(contracts)/build/* $(contracts)/node_modules $(contracts)/package-lock.json
docker volume rm $(project)_chain_dev 2> /dev/null || true
reset-dashboard: reset-base
rm -rf build/dashboard* $(dashboard)/build/* $(dashboard)/node_modules $(dashboard)/package-lock.json
docker volume rm $(project)_chain_dev 2> /dev/null || true
reset-database: reset-base
rm -rf build/database* $(db)/build/* $(db)/node_modules $(db)/package-lock.json
docker volume rm $(project)_database_dev 2> /dev/null || true
reset-hub: reset-base
rm -rf build/hub* $(hub)/dist/* $(hub)/node_modules $(hub)/package-lock.json
reset: reset-base
docker volume rm $(project)_chain_dev 2> /dev/null || true
docker volume rm $(project)_database_dev 2> /dev/null || true
rm -rf $(db)/snapshots/ganache-*
purge: reset clean
rm -rf modules/**/node_modules
push: prod
docker tag $(project)_database:latest $(registry)/$(project)_database:latest
docker tag $(project)_hub:latest $(registry)/$(project)_hub:latest
docker tag $(project)_proxy:latest $(registry)/$(project)_proxy:latest
docker tag $(project)_dashboard:latest $(registry)/$(project)_dashboard:latest
docker push $(registry)/$(project)_database:latest
docker push $(registry)/$(project)_hub:latest
docker push $(registry)/$(project)_proxy:latest
docker push $(registry)/$(project)_dashboard:latest
push-live: prod
docker tag $(project)_database:latest $(registry)/$(project)_database:$(version)
docker tag $(project)_hub:latest $(registry)/$(project)_hub:$(version)
docker tag $(project)_proxy:latest $(registry)/$(project)_proxy:$(version)
docker tag $(project)_dashboard:latest $(registry)/$(project)_dashboard:$(version)
docker push $(registry)/$(project)_database:$(version)
docker push $(registry)/$(project)_hub:$(version)
docker push $(registry)/$(project)_proxy:$(version)
docker push $(registry)/$(project)_dashboard:$(version)
backup:
bash $(db)/ops/run-backup.sh
########################################
# Begin Tests
# set a default test command for developer convenience
test: test-default
test-default: test-client
test-all: test-client test-contracts test-hub
test-client: client
bash ops/test-client.sh
watch-client:
bash ops/watch-client.sh
test-contracts: client contract-artifacts
bash ops/test-contracts.sh
test-hub: hub database
bash ops/test-hub.sh
########################################
# Begin Real Rules
# Proxy
proxy-prod: dashboard-prod $(shell find $(proxy) $(find_options))
$(log_start)
docker build --file $(proxy)/prod.dockerfile --tag $(project)_proxy:latest .
$(log_finish) && touch build/$@
proxy: $(shell find $(proxy) $(find_options))
$(log_start)
docker build --file $(proxy)/dev.dockerfile --tag $(project)_proxy:dev .
$(log_finish) && touch build/$@
# Dashboard Server
dashboard-server-prod: dashboard-prod
$(log_start)
docker build --file $(dashboard)/ops/prod.dockerfile --tag $(project)_dashboard:latest $(dashboard)
$(log_finish) && touch build/$@
# Dashboard Client
dashboard-prod: dashboard-node-modules $(shell find $(dashboard)/src $(dashboard)/ops $(find_options))
$(log_start)
$(docker_run_in_dashboard) "cp -f ops/prod.env .env"
$(docker_run_in_dashboard) "npm run build"
$(docker_run_in_dashboard) "cp -f ops/dev.env .env"
$(log_finish) && touch build/$@
dashboard: dashboard-node-modules $(dashboard)/ops/dev.env
$(log_start)
$(docker_run_in_dashboard) "cp -f ops/dev.env .env"
$(log_finish) && touch build/$@
dashboard-node-modules: builder $(dashboard)/package.json
$(log_start)
$(docker_run_in_dashboard) "$(install)"
$(log_finish) && touch build/$@
# Hub
hub-prod: hub
$(log_start)
docker build --file $(hub)/ops/prod.dockerfile --tag $(project)_hub:latest .
$(log_finish) && touch build/$@
hub: hub-node-modules client contract-artifacts $(shell find $(hub)/src $(find_options))
$(log_start)
$(docker_run_in_hub) "./node_modules/.bin/tsc -p tsconfig.json"
$(log_finish) && touch build/$@
hub-node-modules: builder $(hub)/package.json $(client)/package.json
$(log_start)
$(docker_run_in_hub) "rm -rf node_modules/connext"
$(docker_run_in_hub) "$(install)"
$(docker_run_in_hub) "rm -rf node_modules/connext/dist"
$(docker_run_in_hub) "ln -s ../../../client/dist node_modules/connext/dist"
$(docker_run_in_hub) "rm -rf node_modules/connext/src"
$(docker_run_in_hub) "ln -s ../../../client/src node_modules/connext/src"
@touch build/hub-node-modules
$(log_finish) && touch build/$@
# Contracts
contract-artifacts: contract-node-modules $(shell find $(contracts)/contracts $(find_options))
$(log_start)
$(docker_run_in_contracts) "npm run build"
$(log_finish) && touch build/$@
contract-node-modules: builder $(contracts)/package.json
$(log_start)
$(docker_run_in_contracts) "rm -rf node_modules/connext"
$(docker_run_in_contracts) "$(install)"
$(docker_run_in_contracts) "rm -rf node_modules/connext/dist"
$(docker_run_in_contracts) "ln -s ../../../client/dist node_modules/connext/dist"
$(docker_run_in_contracts) "rm -rf node_modules/connext/src"
$(docker_run_in_contracts) "ln -s ../../../client/src node_modules/connext/src"
@touch build/client-node-modules
$(log_finish) && touch build/$@
# Client
client: client-node-modules $(shell find $(client)/src $(find_options))
$(log_start)
$(docker_run_in_client) "npm run build"
$(log_finish) && touch build/$@
client-node-modules: builder $(client)/package.json
$(log_start)
$(docker_run_in_client) "$(install)"
$(log_finish) && touch build/$@ && touch build/client
# Database
database-prod: database
$(log_start)
docker tag $(project)_database:dev $(project)_database:latest
$(log_finish) && touch build/$@
database: database-node-modules database-migrations $(shell find $(db)/ops $(find_options))
$(log_start)
docker build --file $(db)/ops/db.dockerfile --tag $(project)_database:dev $(db)
$(log_finish) && touch build/$@
database-migrations: $(db)/ops/ejs-render.js $(shell find $(db)/migrations $(db)/templates $(find_options))
$(log_start)
$(docker_run_in_db) "make"
$(log_finish) && touch build/$@
database-node-modules: builder $(db)/package.json
$(log_start)
$(docker_run_in_db) "$(install)"
$(log_finish) && touch build/$@
# Builder, etc
builder: ops/builder.dockerfile
$(log_start)
docker build --file ops/builder.dockerfile --tag $(project)_builder:latest .
$(log_finish) && touch build/$@
root-node-modules: package.json
$(log_start)
$(install)
$(log_finish) && touch build/$@
hooks: ops/pre-push.sh
$(log_start)
rm -f .git/hooks/*
cp ops/pre-push.sh .git/hooks/pre-push
chmod +x .git/hooks/pre-push
$(log_finish) && touch build/$@