-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
251 lines (211 loc) · 10.8 KB
/
Copy pathMakefile
File metadata and controls
251 lines (211 loc) · 10.8 KB
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
.PHONY: build check test test-unit test-integration fmt lint clean \
docker-up docker-down db-setup db-reset \
guest-agent guest-agent-arm64 \
image image-arm64 image-gpu \
firecracker-bins firecracker-bins-arm64 \
help
# ── Default ───────────────────────────────────────────────────────────────────
help:
@echo "Arbor — build and development tasks"
@echo ""
@echo " make build Build all services (release)"
@echo " make check cargo check --workspace (no DB needed)"
@echo " make test-unit Run unit + pure logic tests (no DB)"
@echo " make test-integration Run DB integration tests (needs DB)"
@echo " make fmt Format all Rust code"
@echo " make lint clippy --workspace"
@echo " make docker-up Start postgres + minio + services via compose"
@echo " make docker-down Stop compose stack"
@echo " make db-setup Create DB + run migrations"
@echo " make db-reset Drop and recreate DB"
@echo " make guest-agent Build static musl guest-agent (x86_64)"
@echo " make guest-agent-arm64 Build static musl guest-agent (aarch64)"
@echo " make image Build Ubuntu 24.04 guest rootfs x86_64 (requires root)"
@echo " make image-arm64 Build Ubuntu 24.04 guest rootfs aarch64 (requires root)"
@echo " make image-gpu Build Ubuntu 24.04 GPU guest rootfs x86_64 (requires root)"
@echo " make firecracker-bins Download Firecracker + Jailer (x86_64)"
@echo " make firecracker-bins-arm64 Download Firecracker + Jailer (aarch64)"
# ── Rust ──────────────────────────────────────────────────────────────────────
check:
SQLX_OFFLINE=true cargo check --workspace
build:
SQLX_OFFLINE=true cargo build --release --workspace
fmt:
cargo fmt --all
lint:
SQLX_OFFLINE=true cargo clippy --workspace -- -D warnings
# ── Tests ─────────────────────────────────────────────────────────────────────
test-unit:
@echo "Running unit tests (no DB required)..."
SQLX_OFFLINE=true cargo test -p arbor-tests \
--test safety \
--test reseal \
-- --nocapture 2>&1
test-api-smoke:
@echo "Running API smoke tests..."
SQLX_OFFLINE=true cargo test -p arbor-tests \
--test api_smoke \
-- --nocapture 2>&1
test-m6:
@echo "Running M6 runner pool tests (no DB)..."
SQLX_OFFLINE=true cargo test -p arbor-tests --test m6_smoke -- --nocapture 2>&1
SQLX_OFFLINE=true cargo test -p arbor-runner-agent -- --nocapture 2>&1
test-m8:
@echo "Running M8 ARM64 runner class tests (no DB)..."
SQLX_OFFLINE=true cargo test -p arbor-tests --test m8_arm64_tests -- --nocapture 2>&1
SQLX_OFFLINE=true cargo test -p arbor-runner-agent -- --nocapture 2>&1
test-integration: db-setup
@echo "Running integration tests (requires PostgreSQL)..."
DATABASE_URL=$(DATABASE_URL) \
TEST_DATABASE_URL=$(DATABASE_URL) \
cargo test -p arbor-tests --test db_tests -- --nocapture 2>&1
DATABASE_URL=$(DATABASE_URL) \
TEST_DATABASE_URL=$(DATABASE_URL) \
cargo test -p arbor-controller --test integration_test -- --nocapture 2>&1
test-all: test-unit test-api-smoke test-m6 test-m8 test-integration
# ── Database ──────────────────────────────────────────────────────────────────
DATABASE_URL ?= postgresql://arbor:arbor_dev_only@localhost/arbor
db-setup:
@echo "Setting up database..."
psql $(DATABASE_URL) -c "SELECT 1" 2>/dev/null || \
(createdb arbor 2>/dev/null || true)
DATABASE_URL=$(DATABASE_URL) cargo sqlx prepare --workspace
DATABASE_URL=$(DATABASE_URL) sqlx migrate run --source migrations/
db-reset:
@echo "Dropping and recreating database..."
dropdb --if-exists arbor
createdb arbor
DATABASE_URL=$(DATABASE_URL) sqlx migrate run --source migrations/
db-prepare:
DATABASE_URL=$(DATABASE_URL) cargo sqlx prepare --workspace
# ── Guest agent (musl static binaries) ───────────────────────────────────────
guest-agent:
@echo "Building static guest-agent for x86_64..."
rustup target add x86_64-unknown-linux-musl
cargo build --release \
--target x86_64-unknown-linux-musl \
-p arbor-guest-agent
@echo "Binary: target/x86_64-unknown-linux-musl/release/arbor-guest-agent"
@ls -lh target/x86_64-unknown-linux-musl/release/arbor-guest-agent
guest-agent-arm64:
@echo "Building static guest-agent for aarch64..."
rustup target add aarch64-unknown-linux-musl
@# Cross-linker required on x86_64 hosts: apt install gcc-aarch64-linux-gnu
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-gnu-gcc \
cargo build --release \
--target aarch64-unknown-linux-musl \
-p arbor-guest-agent
@echo "Binary: target/aarch64-unknown-linux-musl/release/arbor-guest-agent"
@ls -lh target/aarch64-unknown-linux-musl/release/arbor-guest-agent
# ── Guest rootfs images ───────────────────────────────────────────────────────
image: guest-agent
@echo "Building Ubuntu 24.04 guest rootfs (x86_64, requires root)..."
cp target/x86_64-unknown-linux-musl/release/arbor-guest-agent \
images/ubuntu-24.04-dev/arbor-guest-agent
sudo bash images/ubuntu-24.04-dev/build.sh
image-arm64: guest-agent-arm64
@echo "Building Ubuntu 24.04 guest rootfs (aarch64, requires root)..."
cp target/aarch64-unknown-linux-musl/release/arbor-guest-agent \
images/ubuntu-24.04-dev/arbor-guest-agent
sudo ARCH=aarch64 bash images/ubuntu-24.04-dev/build.sh
image-gpu: guest-agent
@echo "Building Ubuntu 24.04 GPU guest rootfs (x86_64, requires root)..."
cp target/x86_64-unknown-linux-musl/release/arbor-guest-agent \
images/ubuntu-24.04-dev/arbor-guest-agent
sudo GPU=1 bash images/ubuntu-24.04-dev/build.sh
# ── Firecracker binaries ──────────────────────────────────────────────────────
FC_VERSION ?= v1.9.0
FC_DIR ?= /var/lib/arbor/firecracker/bin
firecracker-bins:
@echo "Downloading Firecracker $(FC_VERSION) for x86_64..."
mkdir -p $(FC_DIR)
curl -L \
"https://github.com/firecracker-microvm/firecracker/releases/download/$(FC_VERSION)/firecracker-$(FC_VERSION)-x86_64.tgz" \
| tar -xz -C /tmp/
install -m 755 /tmp/release-$(FC_VERSION)-x86_64/firecracker-$(FC_VERSION)-x86_64 \
$(FC_DIR)/firecracker
install -m 755 /tmp/release-$(FC_VERSION)-x86_64/jailer-$(FC_VERSION)-x86_64 \
$(FC_DIR)/jailer
@echo "Binaries installed to $(FC_DIR)"
firecracker-bins-arm64:
@echo "Downloading Firecracker $(FC_VERSION) for aarch64..."
mkdir -p $(FC_DIR)
curl -L \
"https://github.com/firecracker-microvm/firecracker/releases/download/$(FC_VERSION)/firecracker-$(FC_VERSION)-aarch64.tgz" \
| tar -xz -C /tmp/
install -m 755 /tmp/release-$(FC_VERSION)-aarch64/firecracker-$(FC_VERSION)-aarch64 \
$(FC_DIR)/firecracker
install -m 755 /tmp/release-$(FC_VERSION)-aarch64/jailer-$(FC_VERSION)-aarch64 \
$(FC_DIR)/jailer
@echo "Binaries installed to $(FC_DIR)"
# ── Docker Compose ────────────────────────────────────────────────────────────
docker-up:
@[ -f deploy/.env ] || (echo "Copy deploy/.env.example to deploy/.env and fill in values"; exit 1)
docker-compose -f deploy/docker-compose.yml up -d
@echo ""
@echo "Services:"
@echo " API: http://localhost:8080"
@echo " Metrics: http://localhost:8080/metrics"
@echo " MinIO: http://localhost:9001 (admin UI)"
@echo ""
@echo "Quick test:"
@echo " curl -s http://localhost:8080/health | jq ."
docker-down:
docker-compose -f deploy/docker-compose.yml down
docker-logs:
docker-compose -f deploy/docker-compose.yml logs -f
# ── Register dev runner ───────────────────────────────────────────────────────
register-dev-runner:
@echo "Registering localhost as an x86_64 runner node..."
curl -s -X POST http://localhost:8080/internal/runners/register \
-H 'Content-Type: application/json' \
-d '{ \
"runner_class": "fc-x86_64-v1", \
"address": "http://localhost:9090", \
"arch": "x86_64", \
"firecracker_version": "1.9.0", \
"cpu_template": "T2", \
"capacity_slots": 10 \
}' | jq .
register-dev-runner-arm64:
@echo "Registering localhost as an aarch64 runner node..."
curl -s -X POST http://localhost:8080/internal/runners/register \
-H 'Content-Type: application/json' \
-d '{ \
"runner_class": "fc-arm64-v1", \
"address": "http://localhost:9090", \
"arch": "aarch64", \
"firecracker_version": "1.9.0", \
"cpu_template": "T2A", \
"capacity_slots": 10 \
}' | jq .
# ── Demo workflow ─────────────────────────────────────────────────────────────
demo-fork:
@echo "=== Arbor fork demo ==="
@echo ""
@echo "1. Create workspace..."
@WS=$$(curl -s -X POST http://localhost:8080/v1/workspaces \
-H 'Content-Type: application/json' \
-d '{"name":"demo","repo":{"provider":"github","url":"git@github.com:x/y.git","ref":"refs/heads/main"},"runtime":{"runner_class":"fc-x86_64-v1","vcpu_count":2,"memory_mib":2048,"disk_gb":20},"image":{"base_image_id":"ubuntu-24.04-dev-v1"},"network":{"egress_policy":"default-deny"}}' \
| jq -r '.workspace_id'); \
echo " workspace_id=$$WS"; \
echo ""; \
echo "2. Take checkpoint..."; \
CKPT=$$(curl -s -X POST http://localhost:8080/v1/workspaces/$$WS/checkpoints \
-H 'Content-Type: application/json' \
-d '{"name":"before-experiment","mode":"full_vm"}' \
| jq -r '.checkpoint_id'); \
echo " checkpoint_id=$$CKPT"; \
echo ""; \
echo "3. Fork 3 parallel attempts..."; \
for branch in attempt-a attempt-b attempt-c; do \
FORK=$$(curl -s -X POST http://localhost:8080/v1/checkpoints/$$CKPT/fork \
-H 'Content-Type: application/json' \
-d "{\"branch_name\":\"$$branch\",\"post_restore\":{\"quarantine\":true,\"identity_reseal\":true}}" \
| jq -r '.workspace_id'); \
echo " $$branch → $$FORK"; \
done; \
echo ""; \
echo "Each fork enters quarantine, runs reseal hooks, then is READY with distinct identity."
clean:
cargo clean