-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
206 lines (168 loc) · 7.29 KB
/
Copy pathMakefile
File metadata and controls
206 lines (168 loc) · 7.29 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
.PHONY: build dev db db-vm db-down migrate sqlc vet clean e2e-drain \
landing-dev landing-build \
install-deps remote-provision remote-sync remote-build remote-initramfs remote-run \
dev-up dev-down dashboard-build remote-dashboard remote-restart
DATABASE_URL ?= postgres://kindling:kindling@localhost:5432/kindling?sslmode=disable
# Empty database recommended (e.g. `createdb kindling_e2e` once). See `contrib/e2e-drain.sh`.
E2E_DATABASE_URL ?= postgres://kindling:kindling@127.0.0.1:5432/kindling_e2e?sslmode=disable
REMOTE_HOST ?= kindling-dev
REMOTE_DIR ?= /home/ubuntu/kindling
# Optional: OVH public IPv4 so runtime_url uses it (passed to kindling serve --advertise-host)
REMOTE_PUBLIC_IP ?=
# Optional: public IP or DNS of the host so API/dashboard show a browser-openable runtime_url (crun/cloud-hypervisor publish 0.0.0.0:port).
KINDLING_RUNTIME_ADVERTISE_HOST ?=
# Vite injects this as the API origin for production static dashboard builds (must match public_base_url on split-host).
# Override for local builds, e.g. DASHBOARD_API_URL=http://127.0.0.1:8080 make dashboard-build
DASHBOARD_API_URL ?= https://api.kindling.systems
# === Local ===
# Build the binary (codesign with entitlements on macOS for Apple VZ)
build:
go build -o bin/kindling ./cmd/kindling
@if [ "$$(uname)" = "Darwin" ]; then \
codesign --entitlements contrib/kindling.entitlements --force -s - bin/kindling; \
fi
# Build kindling-mac daemon (darwin only, requires CGO for sqlite3)
kindling-mac:
CGO_ENABLED=1 go build -o bin/kindling-mac ./cmd/kindling-mac
@if [ "$$(uname)" = "Darwin" ]; then \
codesign --entitlements contrib/kindling.entitlements --force -s - bin/kindling-mac; \
fi
# Install both binaries
install-mac: kindling-mac
install -m 755 bin/kindling /usr/local/bin/kindling
install -m 755 bin/kindling-mac /usr/local/bin/kindling-mac
# Run locally (requires Postgres via `make db`)
dev: build kernel initramfs
./bin/kindling serve
# Data directory
KINDLING_DATA ?= $(HOME)/.kindling
# Download prebuilt kernel (or build from source with `make kernel-build`)
KERNEL_RELEASE ?= kernel-v0.1.0
kernel:
@mkdir -p $(KINDLING_DATA)
@test -f $(KINDLING_DATA)/vmlinuz.bin && exit 0 || true
@ARCH=$$(uname -m); \
if [ "$$ARCH" = "arm64" ]; then ARCH="arm64"; fi; \
echo "Downloading Kindling kernel ($$ARCH)..." && \
curl -fsSL "https://github.com/Peppermint-Lab/kindling/releases/download/$(KERNEL_RELEASE)/vmlinuz-$$ARCH" \
-o $(KINDLING_DATA)/vmlinuz.bin && \
echo "Kernel downloaded to $(KINDLING_DATA)/vmlinuz.bin" || \
(echo "Prebuilt kernel not found. Building from source..." && bash scripts/build-kernel.sh)
# Download prebuilt initramfs
initramfs-download:
@mkdir -p $(KINDLING_DATA)
@test -f $(KINDLING_DATA)/initramfs.cpio.gz && exit 0 || true
@ARCH=$$(uname -m); \
if [ "$$ARCH" = "arm64" ]; then ARCH="arm64"; fi; \
echo "Downloading initramfs ($$ARCH)..." && \
curl -fsSL "https://github.com/Peppermint-Lab/kindling/releases/download/$(KERNEL_RELEASE)/initramfs-$$ARCH.cpio.gz" \
-o $(KINDLING_DATA)/initramfs.cpio.gz && \
echo "Initramfs downloaded to $(KINDLING_DATA)/initramfs.cpio.gz"
# Build kernel from source (only needed to create new releases)
kernel-build:
@rm -f $(KINDLING_DATA)/vmlinuz.bin
@bash scripts/build-kernel.sh
# Build initramfs with guest agent (requires GNU cpio; see scripts/build-initramfs-local.sh)
initramfs:
@bash scripts/build-initramfs-local.sh
# Start local Postgres (see contrib/dev-postgres.sh; no Docker required)
db:
@bash contrib/dev-postgres.sh start
# Start local Postgres inside the persistent kindling-mac box VM (macOS)
db-vm:
@bash contrib/dev-postgres-vm.sh start
# Stop local Postgres
db-down:
@bash contrib/dev-postgres.sh stop
# Run schema migration
migrate:
psql $(DATABASE_URL) -f internal/database/schema.sql
# Regenerate sqlc
sqlc:
sqlc generate
# Lint
vet:
go vet ./...
# End-to-end drain API + server reconciler (Postgres required; not run in default `go test ./...`).
e2e-drain:
KINDLING_E2E_DATABASE_URL="$(E2E_DATABASE_URL)" go test -tags=integration -v ./internal/e2e/... -count=1
# Clean build artifacts
clean:
rm -rf bin/
# === Landing Page ===
landing-dev:
@cd web/landing && npx vite --port 5174
landing-build:
@cd web/landing && npm run build
# === Dashboard (Vite → web/dashboard/dist) ===
dashboard-build:
@cd web/dashboard && VITE_API_URL="$(DASHBOARD_API_URL)" npm run build
# Build with DASHBOARD_API_URL and sync dist/ to REMOTE_HOST (remote-sync excludes dist/)
remote-dashboard: dashboard-build
rsync -az web/dashboard/dist/ $(REMOTE_HOST):$(REMOTE_DIR)/web/dashboard/dist/
remote-restart:
ssh $(REMOTE_HOST) 'sudo systemctl restart kindling'
# === Remote Dev (OVH) ===
# Local macOS/Linux dev: Homebrew (Darwin) or prints sudo command (Linux) — see contrib/install-host-deps.sh
install-deps:
@bash contrib/install-host-deps.sh
# One-time: install host deps on remote, then provision Go/firmware/kernel
remote-provision:
scp contrib/install-host-deps.sh $(REMOTE_HOST):/tmp/kindling-install-host-deps.sh
ssh $(REMOTE_HOST) 'sudo bash /tmp/kindling-install-host-deps.sh --all'
ssh $(REMOTE_HOST) 'bash -s' < contrib/remote/provision.sh
# Sync code to remote
remote-sync:
rsync -az --delete \
--exclude '.git' \
--exclude 'node_modules' \
--exclude 'bin' \
--exclude 'dist' \
--exclude '.claude' \
. $(REMOTE_HOST):$(REMOTE_DIR)/
# Build on remote
remote-build: remote-sync
ssh $(REMOTE_HOST) 'cd $(REMOTE_DIR) && go build -o bin/kindling ./cmd/kindling && \
sudo setcap cap_net_admin,cap_net_bind_service+ep "$(REMOTE_DIR)/bin/kindling" && \
(if [ -f /usr/local/bin/cloud-hypervisor ]; then sudo setcap cap_net_admin+ep /usr/local/bin/cloud-hypervisor; fi)'
# Build initramfs on remote
remote-initramfs: remote-sync
ssh $(REMOTE_HOST) 'cd $(REMOTE_DIR) && bash scripts/build-initramfs.sh'
# Set up VM networking on remote
remote-networking:
ssh $(REMOTE_HOST) 'bash -s' < scripts/setup-networking.sh
# Run kindling on remote
remote-run: remote-build
ssh $(REMOTE_HOST) 'cd $(REMOTE_DIR) && \
if [ -n "$(REMOTE_PUBLIC_IP)" ]; then \
./bin/kindling serve --advertise-host "$(REMOTE_PUBLIC_IP)"; \
else \
./bin/kindling serve; \
fi'
# Install systemd + /etc/kindling on REMOTE_HOST (run once per server; needs sudo)
remote-prod-install: remote-build
ssh $(REMOTE_HOST) 'sudo bash $(REMOTE_DIR)/contrib/setup-kindling-prod.sh'
# Full dev setup: sync, build, run API + dashboard
dev-up: remote-build
@echo "Stopping any existing kindling..."
-@ssh $(REMOTE_HOST) 'pkill -f "bin/kindling" 2>/dev/null; true'
-@pkill -f "ssh -f -N -L 8080:localhost:8080" 2>/dev/null; true
@sleep 1
@echo "Starting SSH tunnel..."
@ssh -f -N -L 8080:localhost:8080 $(REMOTE_HOST)
@echo "Starting kindling API on $(REMOTE_HOST)..."
@ssh $(REMOTE_HOST) 'cd $(REMOTE_DIR) && nohup ./bin/kindling serve > /tmp/kindling.log 2>&1 &'
@sleep 2
@echo "Starting dashboard..."
@cd web/dashboard && nohup npx vite > /tmp/kindling-dashboard.log 2>&1 &
@echo ""
@echo "=== Kindling dev environment ==="
@echo "API: http://localhost:8080"
@echo "Dashboard: http://localhost:5173"
@echo "Logs: ssh $(REMOTE_HOST) tail -f /tmp/kindling.log"
# Stop everything
dev-down:
-@ssh $(REMOTE_HOST) 'pkill -f "bin/kindling" 2>/dev/null; true'
-@pkill -f "ssh -f -N -L 8080:localhost:8080" 2>/dev/null; true
-@pkill -f "vite" 2>/dev/null; true
@echo "Kindling stopped."