forked from FuelLabs/data-systems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
294 lines (224 loc) · 8.33 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
# ------------------------------------------------------------
# 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 bench 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-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:
@if [ -z "$(NEW_VERSION)" ]; then \
echo "Error: NEW_VERSION is required"; \
echo "Usage: make bump-version NEW_VERSION=X.Y.Z"; \
exit 1; \
fi
@echo "Bumping version to $(NEW_VERSION)..."
cargo set-version --workspace "$(NEW_VERSION)"
cargo update --workspace
$(MAKE) fmt
release: validate-env test lint
@if [ -z "$(NEW_VERSION)" ]; then \
echo "Error: NEW_VERSION is required"; \
echo "Usage: make release NEW_VERSION=X.Y.Z [dry_run=true]"; \
exit 1; \
fi
$(MAKE) bump-version NEW_VERSION=$(NEW_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:
@echo "Running artifact cleanup..."
@./scripts/cleanup_artifacts.sh $(REPO_OWNER) $(REPO_NAME) $(DAYS_TO_KEEP)
# ------------------------------------------------------------
# Testing
# ------------------------------------------------------------
test-watch:
cargo watch -x "test --profile $(PROFILE)"
test:
@if [ "$(PACKAGE)" = "all" ] || [ -z "$(PACKAGE)" ]; then \
cargo nextest run --cargo-profile $(PROFILE) --workspace --color always --locked --no-tests=pass && \
cargo test --profile $(PROFILE) --doc --workspace; \
else \
cargo nextest run --cargo-profile $(PROFILE) -p $(PACKAGE) --color always --locked --no-tests=pass && \
cargo test --profile $(PROFILE) --doc -p $(PACKAGE); \
fi
bench:
cargo bench -p data-parser -p nats-publisher -p bench-consumers
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
# ------------------------------------------------------------
# Load Testing & Benchmarking
# ------------------------------------------------------------
load-test:
cargo run -p load-tester -- --network testnet --max-subscriptions 10 --step-size 1
# ------------------------------------------------------------
# Publisher Run Commands
# ------------------------------------------------------------
run-publisher: check-network
@./scripts/run_publisher.sh \
--network $(NETWORK) \
--mode $(MODE) \
$(if $(PORT),--port $(PORT),) \
$(if $(TELEMETRY_PORT),--telemetry-port $(TELEMETRY_PORT),) \
$(if $(extra_args),--extra-args "$(extra_args)",)
run-mainnet-dev:
$(MAKE) run-publisher NETWORK=mainnet MODE=dev
run-mainnet-profiling:
$(MAKE) run-publisher NETWORK=mainnet MODE=profiling
run-testnet-dev:
$(MAKE) run-publisher NETWORK=testnet MODE=dev
run-testnet-profiling:
$(MAKE) run-publisher NETWORK=testnet MODE=profiling
# ------------------------------------------------------------
# Docker Compose
# ------------------------------------------------------------
run-docker-compose:
@./scripts/set_env.sh
@docker compose -f cluster/docker/docker-compose.yml --env-file .env $(COMMAND)
start-nats:
$(MAKE) run-docker-compose COMMAND="up -d"
stop-nats:
$(MAKE) run-docker-compose COMMAND="down"
restart-nats:
$(MAKE) run-docker-compose COMMAND="restart"
clean-nats:
$(MAKE) run-docker-compose COMMAND="down -v --rmi all --remove-orphans"
# ------------------------------------------------------------
# Local cluster (Minikube)
# ------------------------------------------------------------
# Environment variables with defaults
NETWORK ?= testnet
MODE ?= profiling
PORT ?= 4000
TELEMETRY_PORT ?= 8080
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
k8s-setup:
@echo "Setting up k8s..."
@./cluster/scripts/setup_k8s.sh $(NAMESPACE)
helm-setup:
@cd cluster/charts/fuel-streams && helm dependency update
@cd cluster/charts/fuel-streams-publisher && helm dependency update
cluster-setup: minikube-setup k8s-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: pre-cluster
CLUSTER_MODE=$(MODE) tilt --file ./Tiltfile reset