forked from matter-labs/zksync
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
264 lines (178 loc) · 6.17 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
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: dev-up env yarn db-setup redeploy
yarn:
@cd contracts && yarn
@cd js/franklin && yarn
@cd js/client && yarn
@cd js/loadtest && yarn
@cd js/explorer && 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:
@$(sql) "INSERT INTO server_config (contract_addr) VALUES ('$(CONTRACT_ADDR)')"
@echo "successfully inserted contract address into the database"
db-reset: confirm_action db-drop db-setup db-insert-contract
@echo database is ready
db-migrate: confirm_action
@cd src/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'; }
# 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) -it ekidd/rust-musl-builder
# Rust: main stuff
prover:
@bin/.load_keys && cargo run --release --bin prover
server:
@cargo run --bin server
sandbox:
@cd src/sandbox && cargo run
build-target:
$(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
loadtest: confirm_action
@node js/loadtest/loadtest.js
prepare-loadtest: confirm_action
@node js/loadtest/loadtest.js prepare
# 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
restart-kube-rust:
restart-kube-nginx:
#echo kubectl patch deployment nginx -p "{\"spec\":{\"template\":{\"metadata\":{\"labels\":{\"date\":\"$(date +%s)\"}}}}}"
start-kube: push-image-nginx push-image-rust apply-kubeconfig restart-kube-rust restart-kube-nginx
ifeq (,$(KUBECONFIG))
start: image-nginx image-rust start-local
else
start: start-kube
endif
stop: confirm_action
ifeq (,$(KUBECONFIG))
@docker-compose stop server prover
else
@bin/kube scale deployments/server --replicas=0
@bin/kube scale deployments/prover --replicas=0
@bin/kube scale deployments/nginx --replicas=0
endif
restart: stop start
# Monitoring
status:
@curl $(API_SERVER)/api/v0.1/status; echo
log:
ifeq (,$(KUBECONFIG))
@docker-compose logs -f server prover
else
kubectl logs -f deployments/server
endif
# Kubernetes: monitoring shortcuts
pods:
kubectl get pods -o wide
nodes:
kubectl get nodes -o wide
proverlogs:
kubectl logs -f deployments/prover
# 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}"