forked from matter-labs/zksync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
302 lines (204 loc) · 7.26 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
export CI_PIPELINE_ID ?= $(shell date +"%Y-%m-%d-%s")
export SERVER_DOCKER_IMAGE ?= gluk64/franklin:server
export PROVER_DOCKER_IMAGE ?=gluk64/franklin:prover
export GETH_DOCKER_IMAGE ?= gluk64/franklin:geth
export FLATTENER_DOCKER_IMAGE ?= gluk64/franklin:flattener
export NGINX_DOCKER_IMAGE ?= gluk64/franklin-nginx:$(FRANKLIN_ENV)
# Getting started
# Check and change environment (listed here for autocomplete and documentation only)
env:
# Get everything up and running for the first time
init:
@bin/init
yarn:
@cd js/franklin && yarn
@cd js/client && yarn
@cd js/loadtest && yarn
@cd js/explorer && yarn
@cd contracts && yarn
# Helpers
# This will prompt user to confirm an action on production environment
confirm_action:
@bin/.confirm_action
# Database tools
sql = psql "$(DATABASE_URL)" -c
db-test:
@bin/db-test
db-test-reset:
@bin/db-test reset
db-setup:
@bin/db-setup
db-insert-contract:
@bin/db-insert-contract
db-reset: confirm_action db-drop db-setup db-insert-contract
@echo database is ready
db-migrate: confirm_action
@cd core/storage && diesel migration run
db-drop: confirm_action
@# this is used to clear the produciton db; cannot do `diesel database reset` because we don't own the db
@echo DATABASE_URL=$(DATABASE_URL)
@$(sql) 'DROP OWNED BY CURRENT_USER CASCADE' || \
{ $(sql) 'DROP SCHEMA IF EXISTS public CASCADE' && $(sql)'CREATE SCHEMA public'; }
db-wait:
@bin/db-wait
# Frontend clients
dist-config:
bin/.gen_js_config > js/client/src/env-config.js
bin/.gen_js_config > js/explorer/src/env-config.js
client: dist-config
@cd js/client && yarn dev
explorer: dist-config
@cd js/explorer && yarn dev
dist-client: dist-config
@cd js/client && yarn build
dist-explorer: dist-config
@cd js/explorer && yarn build
image-nginx: dist-client dist-explorer
@docker build -t "${NGINX_DOCKER_IMAGE}" -f ./docker/nginx/Dockerfile .
push-image-nginx: image-nginx
docker push "${NGINX_DOCKER_IMAGE}"
explorer-up: #dist-explorer
@docker build -t "${NGINX_DOCKER_IMAGE}" -f ./docker/nginx/Dockerfile .
@docker-compose up -d nginx
# Rust: cross-platform rust builder for linus
docker-options = --rm -v $(shell pwd):/home/rust/src -v cargo-git:/home/rust/.cargo/git -v cargo-registry:/home/rust/.cargo/registry
rust-musl-builder = @docker run $(docker-options) ekidd/rust-musl-builder
# Rust: main stuff
prover:
@bin/.load_keys && cargo run --release --bin prover
server:
@cargo run --bin server
sandbox:
@cargo run --bin sandbox
build-target:
$(rust-musl-builder) sudo chown -R rust:rust /home/rust/.cargo/git /home/rust/.cargo/registry
$(rust-musl-builder) cargo build --release
clean-target:
$(rust-musl-builder) cargo clean
image-server: build-target
docker build -t "${SERVER_DOCKER_IMAGE}" -f ./docker/server/Dockerfile .
image-prover: build-target
docker build -t "${PROVER_DOCKER_IMAGE}" -f ./docker/prover/Dockerfile .
image-rust: image-server image-prover
push-image-rust: image-rust
docker push "${SERVER_DOCKER_IMAGE}"
docker push "${PROVER_DOCKER_IMAGE}"
# Contracts
deploy-contracts: confirm_action
@bin/deploy-contracts
flattener = @docker run --rm -v $(shell pwd)/contracts:/home/contracts -it "${FLATTENER_DOCKER_IMAGE}"
define flatten_file
@echo flattening $(1)
$(flattener) -c 'solidity_flattener --output /home/contracts/flat/$(1) /home/contracts/contracts/$(1)'
endef
# Flatten contract source
flatten:
@mkdir -p contracts/flat
$(call flatten_file,FranklinProxy.sol)
$(call flatten_file,Depositor.sol)
$(call flatten_file,Exitor.sol)
$(call flatten_file,Transactor.sol)
# Publish source to etherscan.io
source: #flatten
@node contracts/scripts/publish-source.js
@echo sources published
# testing
price:
@node contracts/scripts/check-price.js
# Loadtest
run-loadtest: confirm_action
@node js/loadtest/loadtest.js
prepare-loadtest: confirm_action
@node js/loadtest/loadtest.js prepare
rescue: confirm_action
@node js/loadtest/rescue.js
deposit: confirm_action
@node contracts/scripts/deposit.js
# Devops: main
# (Re)deploy contracts and database
redeploy: confirm_action stop deploy-contracts db-reset
dev-ready = docker ps | grep -q "$(GETH_DOCKER_IMAGE)"
start-local:
@docker ps | grep -q "$(GETH_DOCKER_IMAGE)" || { echo "Dev env not ready. Try: 'franklin dev-up'" && exit 1; }
@docker-compose up -d --scale prover=1 server prover nginx
dockerhub-push: image-nginx image-rust
docker push "${NGINX_DOCKER_IMAGE}"
apply-kubeconfig:
@bin/k8s-apply
update-rust: push-image-rust apply-kubeconfig
@kubectl patch deployment $(FRANKLIN_ENV)-server -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"$(shell date +%s)\"}}}}}"
@kubectl patch deployment $(FRANKLIN_ENV)-prover -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"$(shell date +%s)\"}}}}}"
update-nginx: push-image-nginx apply-kubeconfig
@kubectl patch deployment $(FRANKLIN_ENV)-nginx -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"$(shell date +%s)\"}}}}}"
update-all: update-rust update-nginx apply-kubeconfig
start-kube: apply-kubeconfig
ifeq (dev,$(FRANKLIN_ENV))
start: image-nginx image-rust start-local
else
start: apply-kubeconfig start-prover start-server start-nginx
endif
ifeq (dev,$(FRANKLIN_ENV))
stop: confirm_action
@docker-compose stop server prover
else
stop: confirm_action stop-prover stop-server stop-nginx
endif
restart: stop start
start-prover:
@bin/kube scale deployments/$(FRANKLIN_ENV)-prover --replicas=1
start-nginx:
@bin/kube scale deployments/$(FRANKLIN_ENV)-nginx --replicas=1
start-server:
@bin/kube scale deployments/$(FRANKLIN_ENV)-server --replicas=1
stop-prover:
@bin/kube scale deployments/$(FRANKLIN_ENV)-prover --replicas=0
stop-server:
@bin/kube scale deployments/$(FRANKLIN_ENV)-server --replicas=0
stop-nginx:
@bin/kube scale deployments/$(FRANKLIN_ENV)-nginx --replicas=0
# Monitoring
status:
@curl $(API_SERVER)/api/v0.1/status; echo
log-dc:
@docker-compose logs -f server prover
log-server:
kubectl logs -f deployments/$(FRANKLIN_ENV)-server
log-prover:
kubectl logs --tail 300 -f deployments/$(FRANKLIN_ENV)-prover
# Kubernetes: monitoring shortcuts
pods:
kubectl get pods -o wide | grep -v Pending
nodes:
kubectl get nodes -o wide
# Dev environment
dev-up:
@{ docker ps | grep -q "$(GETH_DOCKER_IMAGE)" && echo "Dev env already running" && exit 1; } || echo -n
@docker-compose up -d postgres geth
dev-down:
@docker-compose stop postgres geth
geth-up: geth
@docker-compose up geth
blockscout-migrate:
@docker-compose up -d blockscout_postgres
@docker-compose run blockscout /bin/sh -c "echo $MIX_ENV && mix do ecto.drop --force, ecto.create, ecto.migrate"
blockscout-up:
@docker-compose up -d blockscout_postgres blockscout
blockscout-down:
@docker-compose stop blockscout blockscout_postgres
# Auxillary docker containers for dev environment (usually no need to build, just use images from dockerhub)
dev-build-geth:
@docker build -t "${GETH_DOCKER_IMAGE}" ./docker/geth
dev-build-flattener:
@docker build -t "${FLATTENER_DOCKER_IMAGE}" ./docker/flattener
dev-push-geth:
@docker push "${GETH_DOCKER_IMAGE}"
dev-push-flattener:
@docker push "${FLATTENER_DOCKER_IMAGE}"
# Key generator
make-keys:
@cargo run -p key_generator --release --bin key_generator
# Tesseracts
tesseracts-up:
@docker-compose up -d tesseracts
tesseracts-down:
@docker-compose stop tesseracts