-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
291 lines (227 loc) · 8.42 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
# ============================================================================ #
# STARKNET NODE BENCHMAR RUNNER #
# ============================================================================ #
NODES := madara juno pathfinder
IMGS := $(addsuffix /image.tar.gz,$(NODES))
VOLUMES := $(addsuffix _runner_db,$(NODES)) fgw_runner_db
SECRETS := secrets/rpc_api.secret \
secrets/rpc_api_ws.secret \
secrets/gateway_key.secret \
secrets/db_password.secret
DEPS := poetry install
RUNNER := poetry run fastapi run app
define HELP
Starknet Node Benchmark Runner
Starts mulitple starknet RPC nodes in individual, isolated and resource-
constrained containers for benchmarking. An endpoint will be exposed at
0.0.0.0:8000/docs where you can visually query RPC methods and run benchmarks
on each node. You can also query this endpoint more traditionally via JSON RPC
in cases where automation is necessary.
Usage:
make <target>
Targets:
[ RUNNING NODES ]
Runs nodes, automatically building the required images if they have not
already been generated (this will take some time). Note that it is also
required for you to have added the necessary secrets to `./secrets/`, or the
nodes will fail to start.
- start-madara Start the Madara node
- start-juno Start the Juno node
- start-pathfinder Start the Pathfinder node
- start-fgw Start feeder gateway node
- start-db Start postgresql local db at ./db/data
- start-service Start api service at 0.0.0.0:8000/docs
- start Start all nodes and api service
[ STOPPING NODES ]
Note that this will only pause container execution and not delete them, any
volume or image.
- stop-madara Stop the Madara node
- stop-juno Stop the Juno node
- stop-pathfinder Stop the Pathfinder node
- stop-fgw Stop feeder gateway node
- stop-db Stop postgresql local db at ./db/data
- stop Stop all nodes
[ RESTARTING NODES ]
Restarts nodes, possibly cleaning build artefacts, containers, images and
volumes in the process. Note that it is also required for you to have added
the necessary secrets to `./secrets/`, or the nodes will fail to restart.
- restart-madara Restart the Madara node
- restart-juno Restart the Juno node
- restart-pathfinder Restart the Pathfinder node
- restart-fgw Restart feeder gateway node
- restart-db Restart postgresql local db at ./db/data
- restart Restart all nodes
- frestart Perform full clean and restart all nodes
[ LOGGING NODES ]
This will show logging outputs for a node's container. Defaults to following
the output, <Ctrl-C> to quit.
- logs-madara View logs for the Madara node
- logs-juno View logs for the Juno node
- logs-pathfinder View logs for the Pathfinder node
- logs-fgw View logs for feeder gateway node
[ BUILDING DEPENDENCIES ]
Images are built using local dockerfiles running a version of each node
pinned to a specif release or commit. Note that to avoid continuousy
rebuilding images those are export to a `tar.gz` as build artefacts.
- images Build Docker images for all nodes
[ CLEANING DEPENDECIES ]
Will remove running containers, images and even volumes. Use the latter with
care as reseting node volumes will force a resync from genesys.
- clean Stop containers and prune images
- clean-db Perform clean and remove local volumes and database
- fclean Perform clean-db and remove local images
[ OTHER COMMANDS ]
- help Show this help message
endef
export HELP
# dim white italic
DIM := \033[2;3;37m
# bold cyan
INFO := \033[1;36m
# bold green
PASS := \033[1;32m
# bold red
WARN := \033[1;31m
RESET := \033[0m
.PHONY: all
all: help
.PHONY: help
help:
@echo "$$HELP"
.PHONY: start-fgw
start-fgw: images
@echo -e "$(DIM)starting$(RESET) $(PASS)fgw$(RESET)"
@docker compose -f fgw/compose.yaml up -d
.PHONY: start-db
start-db:
@echo -e "$(DIM)starting$(RESET) $(PASS)database$(RESET)"
@docker compose -f db/compose.yaml up -d
.PHONY: start-madara
start-madara: start-fgw $(SECRETS)
@echo -e "$(DIM)running$(RESET) $(PASS)madara$(RESET)"
@docker compose -f madara/compose.yaml up -d
.PHONY: start-juno
start-juno: start-fgw $(SECRETS)
@echo -e "$(DIM)running$(RESET) $(PASS)juno$(RESET)"
@docker compose -f juno/compose.yaml up -d
.PHONY: start-pathfinder
start-pathfinder: start-fgw $(SECRETS)
@echo -e "$(DIM)running$(RESET) $(PASS)pathfinder$(RESET)"
@docker compose -f pathfinder/compose.yaml up -d
.PHONY: start-service
start-service: start-db
@$(DEPS)
@$(RUNNER)
.PHONY: start
start: start-db start-fgw
@make --silent start-madara start-juno start-pathfinder
@echo -e "$(PASS)all services are up$(RESET)"
@$(DEPS)
@$(RUNNER)
.PHONY: stop-fgw
stop-fgw:
@echo -e "$(DIM)stopping$(RESET) $(WARN)fgw$(RESET)"
@docker compose -f fgw/compose.yaml stop
.PHONY: stop-db
stop-db:
@echo -e "$(DIM)stopping$(RESET) $(WARN)database$(RESET)"
@docker compose -f db/compose.yaml stop
.PHONY: stop-madara
stop-madara:
@echo -e "$(DIM)stopping$(RESET) $(WARN)madara$(RESET)"
@docker compose -f madara/compose.yaml stop
.PHONY: stop-juno
stop-juno:
@echo -e "$(DIM)stopping$(RESET) $(WARN)juno$(RESET)"
@docker compose -f juno/compose.yaml stop
.PHONY: stop-pathfinder
stop-pathfinder:
@echo -e "$(DIM)stopping$(RESET) $(WARN)pathfinder$(RESET)"
@docker compose -f pathfinder/compose.yaml stop
.PHONY: stop
stop: stop-madara stop-juno stop-pathfinder
@make --silent stop-db stop-fgw
@echo -e "$(WARN)all services stopped$(RESET)"
.PHONY: logs-fgw
logs-fgw:
@echo -e "$(DIM)logs for$(RESET) $(INFO)fgw$(RESET)";
@docker compose -f fgw/compose.yaml logs -f -n 100;
.PHONY: logs-madara
logs-madara:
@echo -e "$(DIM)logs for$(RESET) $(INFO)madara$(RESET)";
@docker compose -f madara/compose.yaml logs -f -n 100;
.PHONY: logs-juno
logs-juno:
@echo -e "$(DIM)logs for$(RESET) $(INFO)juno$(RESET)";
@docker compose -f juno/compose.yaml logs -f -n 100;
.PHONY: logs-pathfinder
logs-pathfinder:
@echo -e "$(DIM)logs for$(RESET) $(INFO)pathfinder$(RESET)";
@docker compose -f pathfinder/compose.yaml logs -f -n 100;
.PHONY: images
images: $(IMGS)
.PHONY: clean
clean: stop
@echo -e "$(DIM)pruning containers$(RESET)"
@docker container prune -f
@echo -e "$(DIM)pruning images$(RESET)"
@docker image prune -f
@echo -e "$(WARN)images cleaned$(RESET)"
.PHONY: clean-db
clean-db:
@echo -e "$(WARN)This action will result in irrecoverable loss of data!$(RESET)"
@echo -e "$(DIM)Are you sure you want to proceed?$(RESET) $(PASS)[y/N] $(RESET)" && \
read ans && \
case "$$ans" in \
[yY]*) true;; \
*) false;; \
esac
@make --silent clean
@echo -e "$(DIM)removing node database volumes$(RESET)"
@for volume in $(VOLUMES); do \
docker volume rm -f $$volume; \
done
@echo -e "$(DIM)removing benchmark database$(RESET)"
@sudo rm -rf ./db/data
.PHONY: fclean
fclean: clean-db
@echo -e "$(DIM)removing local images tar.gz$(RESET)"
@rm -rf $(IMGS)
@echo -e "$(WARN)artefacts cleaned$(RESET)"
.PHONY: restart-fgw
restart-fgw: clean
@make --silent start-fgw
.PHONY: restart-madara
restart-madara: clean
@make --silent start-madara
.PHONY: restart-juno
restart-juno: clean
@make --silent start-juno
.PHONY: restart-pathfinder
restart-pathfinder: clean
@make --silent start-pathfinder
.PHONY: restart-db
restart-db: clean
@make --silent start-db
.PHONY: restart
restart: clean
@make --silent start
.PHONY: frestart
frestart: fclean
@make --silent start
%image.tar.gz: node = $(@D)
%image.tar.gz: %Dockerfile
@echo -e "$(DIM)building$(RESET) $(PASS)$(node)$(RESET)"
@docker image rm -f $(node):latest || true
@docker build -t $(node):latest $(node)
@docker image save -o $(node)/image.tar.gz $(node):latest
# Nix Image build has had to been remove following the introduction of scarb
# into the build process. This is because scarb needs to download depencies
# during the madara build process, which results in an impure derivation.
# This does not play well with nix. The only solution to this would be to
# propose an upstream pr to the scarb repo which allows scarb to re-use
# locally available dependencies, even if they were not downloaded by it.
#
# @nix-build $(node) -o $(node)/result
# @$(node)/result/bin/copyto $(node)/image.tar.gz
# @docker load -i $(node)/image.tar.gz