-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathMakefile
379 lines (290 loc) · 11.2 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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# ------------------------------------------------------------
# Variables
# ------------------------------------------------------------
# Version detection using shell command
VERSION := $(shell cargo metadata --format-version=1 | jq -r '.packages[] | select(.name == "fuel-streams") | .version')
# Constants
RUST_NIGHTLY_VERSION := nightly-2024-11-06
RUST_VERSION := 1.81.0
# ------------------------------------------------------------
# Phony Targets
# ------------------------------------------------------------
.PHONY: install validate-env check-commands check-network check-versions \
check-dev-env setup create-env version bump-version release dev-watch \
clean clean-build cleanup-artifacts test-watch test helm-test \
fmt fmt-cargo fmt-rust fmt-prettier fmt-markdown lint lint-cargo \
lint-rust lint-clippy lint-prettier lint-markdown lint-machete \
audit audit-fix-test audit-fix load-test run-publisher run-consumer \
run-mainnet-dev run-mainnet-profiling run-testnet-dev run-testnet-profiling \
start-nats stop-nats restart-nats clean-nats minikube-setup minikube-start \
minikube-delete k8s-setup helm-setup cluster-setup pre-cluster \
cluster-up cluster-down cluster-reset
# ------------------------------------------------------------
# Setup & Validation Targets
# ------------------------------------------------------------
install:
cargo fetch
validate-env: check-commands check-versions check-dev-env
@echo "Validating Rust toolchain..."
@rustc --version | grep -q "$(shell cat rust-toolchain 2>/dev/null || echo "$(RUST_VERSION)")" || { echo "Wrong rustc version"; exit 1; }
@echo "Validating cargo installation..."
@cargo --version >/dev/null 2>&1 || { echo "cargo is required but not installed"; exit 1; }
@echo "Environment validation complete"
check-commands:
@for cmd in rustup npm pre-commit docker python3; do \
if ! command -v $$cmd >/dev/null 2>&1; then \
echo "$$cmd is not installed. Please install $$cmd and try again."; \
exit 1; \
fi \
done
check-network:
@if [ "$(NETWORK)" != "mainnet" ] && [ "$(NETWORK)" != "testnet" ]; then \
echo "Error: network must be either 'mainnet' or 'testnet'"; \
exit 1; \
fi
check-versions:
@echo "Checking required tool versions..."
@echo "$$(rustc --version)"
@echo "$$(cargo --version)"
@echo "node: $$(node --version)"
@echo "npm: $$(npm --version)"
check-dev-env:
@if [ ! -f .env ]; then \
echo "Warning: .env file not found. Copying from .env.example..."; \
cp .env.example .env; \
fi
setup: check-commands check-versions check-dev-env
./scripts/setup.sh
create-env:
@./scripts/create_env.sh
# ------------------------------------------------------------
# Version Management
# ------------------------------------------------------------
version:
@echo "Current version: $(VERSION)"
bump-version: VERSION=""
bump-version:
@if [ -z "$(VERSION)" ]; then \
echo "Error: VERSION is required"; \
echo "Usage: make bump-version VERSION=X.Y.Z"; \
exit 1; \
fi
@echo "Bumping version to $(VERSION)..."
@./scripts/bump-version.sh "$(VERSION)"
release: validate-env test lint
@if [ -z "$(VERSION)" ]; then \
echo "Error: VERSION is required"; \
echo "Usage: make release VERSION=X.Y.Z [dry_run=true]"; \
exit 1; \
fi
$(MAKE) bump-version VERSION=$(VERSION)
knope prepare-release $(if $(filter true,$(dry_run)),--dry-run,)
# ------------------------------------------------------------
# Development Targets
# ------------------------------------------------------------
dev-watch:
cargo watch -- cargo run
clean: clean-build
clean-build:
cargo clean
rm -rf target/
rm -rf node_modules/
cleanup-artifacts: REPO_OWNER="fuellabs"
cleanup-artifacts: REPO_NAME="data-systems"
cleanup-artifacts: DAYS_TO_KEEP=10
cleanup-artifacts:
@echo "Running artifact cleanup..."
@./scripts/cleanup_artifacts.sh $(REPO_OWNER) $(REPO_NAME) $(DAYS_TO_KEEP)
# ------------------------------------------------------------
# Testing
# ------------------------------------------------------------
test-watch: PROFILE="all"
test-watch:
cargo watch -x "test --profile $(PROFILE)"
test: PACKAGE="all"
test: PROFILE="dev"
test:
@echo "Running tests for package $(PACKAGE) with profile $(PROFILE)"
@if [ "$(PACKAGE)" = "all" ] || [ -z "$(PACKAGE)" ]; then \
cargo nextest run --cargo-profile $(PROFILE) --workspace --color always --no-tests=pass --all-features && \
cargo test --profile $(PROFILE) --doc --workspace --all-features; \
else \
cargo nextest run --cargo-profile $(PROFILE) -p $(PACKAGE) --color always --no-tests=pass --all-features && \
cargo test --profile $(PROFILE) --doc -p $(PACKAGE) --all-features; \
fi
helm-test:
helm unittest -f "tests/**/*.yaml" -f "tests/*.yaml" cluster/charts/fuel-streams
# ------------------------------------------------------------
# Formatting & Linting
# ------------------------------------------------------------
fmt: fmt-cargo fmt-rust fmt-prettier fmt-markdown
fmt-cargo:
cargo sort -w
fmt-rust:
cargo +$(RUST_NIGHTLY_VERSION) fmt -- --color always
fmt-prettier:
pnpm prettier:fix
fmt-markdown:
pnpm md:fix
lint: lint-cargo lint-rust lint-clippy lint-prettier lint-markdown lint-machete
lint-cargo:
cargo sort --check --workspace
lint-rust:
@cargo check --all-targets --all-features
@cargo +$(RUST_NIGHTLY_VERSION) fmt --all --check -- --color always
lint-clippy:
cargo clippy --workspace --all-targets --all-features -- -D warnings
lint-prettier:
pnpm prettier:validate
lint-markdown:
pnpm md:lint
lint-machete:
cargo machete --skip-target-dir
# ------------------------------------------------------------
# Audit
# ------------------------------------------------------------
audit:
cargo audit
audit-fix-test:
cargo audit fix --dry-run
audit-fix:
cargo audit fix
# ------------------------------------------------------------
# Build & Documentation
# ------------------------------------------------------------
build:
cargo build --release
docs: doc
@echo "Generating additional documentation..."
@cargo doc --no-deps --document-private-items
@cargo doc --workspace --no-deps
docs-serve: docs
@echo "Serving documentation on http://localhost:8000"
@python3 -m http.server 8000 --directory target/doc
# ------------------------------------------------------------
# Load Testing & Benchmarking
# ------------------------------------------------------------
load-test:
cargo run -p load-tester -- --network staging --ws-url "wss://stream-staging.fuel.network" --api-key "your_api_key" --max-subscriptions 10 --step-size 1
bench:
cargo bench -p data-parser
# ------------------------------------------------------------
# Publisher Run Commands
# ------------------------------------------------------------
run-publisher: NETWORK="testnet"
run-publisher: MODE="dev"
run-publisher: PORT="4000"
run-publisher: TELEMETRY_PORT="9001"
run-publisher: NATS_URL="localhost:4222"
run-publisher: EXTRA_ARGS=""
run-publisher: FROM_HEIGHT="0"
run-publisher: check-network
@./scripts/run_publisher.sh
run-publisher-mainnet-dev:
$(MAKE) run-publisher NETWORK=mainnet MODE=dev FROM_HEIGHT=0
run-publisher-mainnet-profiling:
$(MAKE) run-publisher NETWORK=mainnet MODE=profiling FROM_HEIGHT=0
run-publisher-testnet-dev:
$(MAKE) run-publisher NETWORK=testnet MODE=dev FROM_HEIGHT=0
run-publisher-testnet-profiling:
$(MAKE) run-publisher NETWORK=testnet MODE=profiling FROM_HEIGHT=0
# ------------------------------------------------------------
# Consumer Run Commands
# ------------------------------------------------------------
run-consumer: NATS_URL="localhost:4222"
run-consumer: PORT="9002"
run-consumer:
cargo run --package sv-consumer --profile dev -- \
--nats-url $(NATS_URL) \
--port $(PORT)
# ------------------------------------------------------------
# Streamer Run Commands
# ------------------------------------------------------------
run-webserver: NETWORK="testnet"
run-webserver: MODE="dev"
run-webserver: PORT="9003"
run-webserver: NATS_URL="nats://localhost:4222"
run-webserver: EXTRA_ARGS=""
run-webserver: check-network
@./scripts/run_webserver.sh --mode $(MODE) --port $(PORT) --nats-url $(NATS_URL) --extra-args $(EXTRA_ARGS)
run-webserver-mainnet-dev:
$(MAKE) run-webserver NETWORK=mainnet MODE=dev
run-webserver-mainnet-profiling:
$(MAKE) run-webserver NETWORK=mainnet MODE=profiling
run-webserver-testnet-dev:
$(MAKE) run-webserver NETWORK=testnet MODE=dev
run-webserver-testnet-profiling:
$(MAKE) run-webserver NETWORK=testnet MODE=profiling
# ------------------------------------------------------------
# Docker Compose
# ------------------------------------------------------------
# Define service profiles
DOCKER_SERVICES := nats docker cockroach
run-docker-compose: PROFILE="all"
run-docker-compose:
@./scripts/set_env.sh
@docker compose -f cluster/docker/docker-compose.yml --profile $(PROFILE) --env-file .env $(COMMAND)
# Common docker-compose commands
define make-docker-commands
start-$(1):
$(MAKE) run-docker-compose PROFILE="$(if $(filter docker,$(1)),all,$(1))" COMMAND="up -d"
stop-$(1):
$(MAKE) run-docker-compose PROFILE="$(if $(filter docker,$(1)),all,$(1))" COMMAND="down"
restart-$(1):
$(MAKE) run-docker-compose PROFILE="$(if $(filter docker,$(1)),all,$(1))" COMMAND="restart"
clean-$(1):
$(MAKE) run-docker-compose PROFILE="$(if $(filter docker,$(1)),all,$(1))" COMMAND="down -v --remove-orphans"
reset-$(1): clean-$(1) start-$(1)
endef
# Generate targets for each service
$(foreach service,$(DOCKER_SERVICES),$(eval $(call make-docker-commands,$(service))))
reset-nats: clean-nats start-nats
setup-db:
@echo "Setting up database..."
@cargo sqlx migrate run --source crates/fuel-streams-store/migrations
# I removed this for now because it was not working on CI
# @cargo sqlx prepare --workspace -- --all-features
reset-db: clean-docker start-docker setup-db
# ------------------------------------------------------------
# Local cluster (Minikube)
# ------------------------------------------------------------
# Environment variables with defaults
NETWORK ?= testnet
MODE ?= profiling
PORT ?= 4000
minikube-setup:
@./cluster/scripts/setup_minikube.sh "$(DISK_SIZE)" "$(MEMORY)"
minikube-start:
@echo "Starting minikube with disk-size=$(DISK_SIZE), memory=$(MEMORY)..."
minikube start \
--driver=docker \
--disk-size="$(DISK_SIZE)" \
--memory="$(MEMORY)" \
--cpus 8 \
--insecure-registry registry.dev.svc.cluster.local:5000
@echo -e "\n\033[1;33mMinikube Status:\033[0m"
@minikube status
minikube-delete:
@echo "Deleting minikube..."
@minikube delete
helm-setup:
@cd cluster/charts/fuel-streams && helm dependency update
cluster-setup: minikube-setup helm-setup
pre-cluster:
@./scripts/set_env.sh
@./cluster/scripts/gen_env_secret.sh
# Cluster management commands
cluster-up: pre-cluster
CLUSTER_MODE=$(MODE) tilt --file ./Tiltfile up
cluster-down: pre-cluster
CLUSTER_MODE=$(MODE) tilt --file ./Tiltfile down
cluster-reset: cluster-down cluster-up
# ------------------------------------------------------------
# Subjects Schema
# ------------------------------------------------------------
subjects-schema:
@echo "Generating subjects schema..."
@cd scripts/subjects-schema && cargo run
@cat scripts/subjects-schema/schema.json | pbcopy
@echo "Subjects schema copied to clipboard"
@rm -rf scripts/subjects-schema/schema.json