-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
187 lines (154 loc) · 8.03 KB
/
Makefile
File metadata and controls
187 lines (154 loc) · 8.03 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
.PHONY: build check test test-unit test-integration fmt lint clean \
docker-up docker-down db-setup db-reset \
guest-agent image firecracker-bins 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 binary"
@echo " make image Build Ubuntu 24.04 guest rootfs (requires root)"
@echo " make firecracker-bins Download Firecracker + Jailer binaries"
# ── 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-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-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 binary) ─────────────────────────────────────────
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 rootfs image ────────────────────────────────────────────────────────
image: guest-agent
@echo "Building Ubuntu 24.04 guest rootfs (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
# ── Firecracker binaries ──────────────────────────────────────────────────────
FC_VERSION ?= v1.9.0
FC_DIR ?= /var/lib/arbor/firecracker/bin
firecracker-bins:
@echo "Downloading Firecracker $(FC_VERSION)..."
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)"
@echo "Now download a kernel: see https://github.com/firecracker-microvm/firecracker/blob/main/docs/getting-started.md"
# ── 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 a 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 .
# ── 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