-
Notifications
You must be signed in to change notification settings - Fork 10
/
Justfile
294 lines (239 loc) · 7.63 KB
/
Justfile
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
# Justfile
#
# The command 'just' will give usage information.
# See https://github.com/casey/just for more.
export TOPLEVEL := `pwd`
export CARGO_HOME := TOPLEVEL + "/.cargo"
export GIT_COMMIT_HASH := `git rev-parse --short=8 HEAD`
IMAGE := "mina-indexer:" + GIT_COMMIT_HASH
# Show
alias sd := show-dev
alias sp := show-prod
alias st := show-test
# Clean
alias cd := clean-dev
alias cp := clean-prod
alias ct := clean-test
# Dev
alias bt := dev
alias btc := dev-continue
# Test
alias tu := test-unit-dev
alias t1 := tier1
alias t2 := tier2-dev
alias t3 := tier3-dev
# Prod
alias dlp := deploy-local-prod-dev
# Ensure rustfmt works in all environments
# Nix environment has rustfmt nightly and won't work with +nightly
# Non-Nix environment needs nightly toolchain installed and requires +nightly
is_rustfmt_nightly := `cd rust && rustfmt --version | grep stable || echo "true"`
nightly_if_required := if is_rustfmt_nightly == "true" { "" } else { "+nightly" }
DEBUG_MODE := "debug"
PROD_MODE := "nix"
REGRESSION_TEST := "./ops/regression-test.rb"
DEPLOY := "./ops/deploy.rb"
UTILS := "./ops/utils.rb"
default:
@just --list --justfile {{justfile()}}
# Check for presence of tier 1 dependencies.
tier1-prereqs:
@echo "--- Checking for tier-1 prereqs"
ruby --version
cd rust && cargo --version
cd rust && cargo nextest --version
cd rust && cargo audit --version
cd rust && cargo clippy --version
cd rust && cargo machete --help 2>&1 >/dev/null
shellcheck --version
shfmt --version
# Check for presence of tier 2 dependencies.
tier2-prereqs: tier1-prereqs
@echo "--- Checking for tier-2 prereqs"
jq --version
check-jsonschema --version
hurl --version
audit:
@echo "--- Performing Cargo audit"
cd rust && time cargo audit
lint:
@echo "--- Linting ops scripts"
ruby -cw ops/*.rb
standardrb --no-fix ops/*.rb
shellcheck tests/regression.bash
@echo "--- Linting Rust code"
cd rust && time cargo {{nightly_if_required}} fmt --all --check
cd rust && time cargo clippy --all-targets --all-features -- -D warnings
@echo "--- Linting Nix configs"
alejandra --check flake.nix
@echo "--- Linting Cargo dependencies"
cd rust && cargo machete Cargo.toml
format:
cd rust && cargo {{nightly_if_required}} fmt --all
standardrb --fix ops/*.rb
shfmt --write ops/*.sh
alejandra flake.nix
# Perform a fast verification of whether the source compiles.
check:
@echo "--- Invoking 'cargo check'"
cd rust && time cargo check
#
# Build
#
# Perform a nix (release) build
nix-build:
@echo "--- Performing Nix build"
nom build
# Perform a debug build
debug-build:
cd rust && cargo build
# Build OCI images.
build-image:
@echo "--- Building {{IMAGE}}"
docker --version
time nom build .#dockerImage
time docker load < ./result
docker run --rm -it {{IMAGE}} mina-indexer server start --help
docker image rm {{IMAGE}}
rm result
#
# Show
#
# Show mina-indexer PID(s)
show-pids:
@echo "Showing mina-indexer PID(s)"
{{UTILS}} pids show
# Show the mina-indexer-dev directory
show-dev rev=GIT_COMMIT_HASH:
@echo "Showing dev directory"
{{UTILS}} dev show {{rev}}
# Show prod directories
show-prod rev=GIT_COMMIT_HASH:
@echo "Showing prod directory"
{{UTILS}} prod show {{rev}}
# Show test directories
show-test rev=GIT_COMMIT_HASH:
@echo "Showing test directory"
{{UTILS}} test show {{rev}}
#
# Clean
#
# Cargo clean & remove nix build
clean:
cd rust && cargo clean
rm -f result
@echo "Consider also 'git clean -xdfn'"
# Clean the mina-indexer-dev directory
clean-dev which='one' rev=GIT_COMMIT_HASH:
@echo "Cleaning dev directory"
{{UTILS}} dev clean {{which}} {{rev}}
# Clean mina-indexer-prod subdirectory
clean-prod which='one' rev=GIT_COMMIT_HASH:
@echo "Cleaning prod directory"
{{UTILS}} prod clean {{which}} {{rev}}
# Clean mina-indexer-test subdirectory
clean-test rev=GIT_COMMIT_HASH:
@echo "Cleaning test directory"
{{UTILS}} test clean {{rev}}
#
# Dev
#
# Debug build and run regression tests
dev subtest='': debug-build
time {{REGRESSION_TEST}} {{DEBUG_MODE}} {{subtest}}
# Debug build and continue regression tests from given test
dev-continue subtest='': debug-build
time {{REGRESSION_TEST}} {{DEBUG_MODE}} continue {{subtest}}
#
# Unit tests
#
# Run unit debug tests
test-unit:
@echo "--- Invoking 'rspec ops/spec'"
rspec ops/spec/*_spec.rb
@echo "--- Invoking 'cargo nextest'"
cd rust && time cargo nextest run
# Lint & run debug unit test(s)
test-unit-dev test='': lint
@echo "--- Invoking 'cargo nextest'"
cd rust && time cargo nextest run {{test}}
test-unit-mina-rs:
@echo "--- Performing long-running mina-rs unit tests"
cd rust && time cargo nextest run --release --features mina_rs
#
# Tier 1 tests
#
# Run the 1st tier of tests.
tier1: tier1-prereqs check lint test-unit
@echo "--- Performing tier 1 regression tests"
time {{REGRESSION_TEST}} {{DEBUG_MODE}} \
ipc_is_available_immediately \
clean_shutdown \
clean_kill \
block_copy \
account_balance_cli \
best_chain \
rest_accounts_summary \
reuse_databases \
hurl
# Tier 2 tests
# Run tier 2 nix (release) load test
tier2-load-test:
@echo "--- Performing a simple load test with Nix-built binary"
time {{REGRESSION_TEST}} {{PROD_MODE}} load
# Run tier 2 nix (release) best_chain_many_blocks test
tier2-best-chain-many-blocks-test:
@echo "--- Performing best_chain_many_blocks regression test with Nix-built binary"
time {{REGRESSION_TEST}} {{PROD_MODE}} best_chain_many_blocks
# Run tier 2 nix (release) regression tests
tier2-regression-tests:
@echo "--- Performing tier 2 regression tests with Nix-built binary"
time {{REGRESSION_TEST}} {{PROD_MODE}}
# Run tier 2 dev (debug) load test
tier2-load-test-dev:
@echo "--- Performing a simple load test with debug-built binary"
time {{REGRESSION_TEST}} {{DEBUG_MODE}} load
# Run tier 2 dev (debug) best_chain_many_blocks test
tier2-best-chain-many-blocks-test-dev:
@echo "--- Performing best_chain_many_blocks regression test with debug-built binary"
time {{REGRESSION_TEST}} {{DEBUG_MODE}} best_chain_many_blocks
# Run tier 2 dev (debug) regression tests
tier2-regression-tests-dev:
@echo "--- Performing tier 2 regression tests with debug-built binary"
time {{REGRESSION_TEST}} {{DEBUG_MODE}}
# Run tier 2 tests with Nix-built (release) binary & build OCI image.
tier2: tier2-prereqs nix-build \
tier2-load-test \
tier2-best-chain-many-blocks-test \
tier2-regression-tests \
&& build-image
# Run tier 2 tests with debug build.
tier2-dev: tier2-prereqs debug-build \
tier2-load-test-dev \
tier2-best-chain-many-blocks-test-dev \
tier2-regression-tests-dev
# Tier 3 tests
# Run the 3rd tier of tests with Nix-built binary.
tier3 blocks='5000': nix-build test-unit-mina-rs
@echo "--- Performing tier3 regression tests with Nix-built binary"
time {{DEPLOY}} test nix {{blocks}}
# Run the 3rd tier of tests with debug build & no unit tests.
tier3-dev blocks='5000': debug-build
@echo "--- Performing tier3 regression tests with debug-built binary"
time {{DEPLOY}} test debug {{blocks}}
#
# Deploy local prod
#
# Run a server as if in production with the Nix-built binary.
deploy-local-prod blocks='5000' web_port='': nix-build
@echo "--- Deploying prod indexer"
time {{DEPLOY}} prod nix {{blocks}} {{web_port}}
# Run a server as if in production with the debug-built binary.
deploy-local-prod-dev blocks='5000' web_port='': debug-build
@echo "--- Deploying dev prod indexer"
time {{DEPLOY}} prod debug {{blocks}} {{web_port}}
# Shutdown a running local prod indexer.
shutdown rev=GIT_COMMIT_HASH:
@echo "Shutting down prod indexer"
{{UTILS}} prod shutdown {{rev}}
@echo "Successfully shutdown. You may also want to do 'just clean-prod'"