.PHONY: all help setup check-deps db setup-env migrate build run test clean docker-build docker-run
all: check-deps setup-env db migrate build run
help:
@echo "Claw Spawn - Available Commands"
@echo "========================================"
@echo ""
@echo " make - Full setup and start (default)"
@echo " make setup - Initial environment setup"
@echo " make db - Create database if not exists"
@echo " make migrate - Run database migrations"
@echo " make build - Build release binary"
@echo " make run - Start the server"
@echo " make dev - Quick dev mode (checks, migrates, runs)"
@echo " make test - Run all tests"
@echo " make clean - Clean build artifacts"
@echo " make docker-build - Build Docker image"
@echo " make docker-run - Run with Docker Compose"
@echo ""
@echo "Environment Variables Required:"
@echo " CLAW_DATABASE_URL - PostgreSQL connection string"
@echo " CLAW_DIGITALOCEAN_TOKEN - DigitalOcean API token"
@echo " CLAW_ENCRYPTION_KEY - 32-byte base64 encoded key"
@echo ""
check-deps:
@echo "๐ Checking dependencies..."
@which cargo > /dev/null || (echo "โ Rust/Cargo not found. Install from https://rustup.rs/" && exit 1)
@echo "โ
Cargo found"
@which psql > /dev/null || (echo "โ PostgreSQL client (psql) not found" && exit 1)
@echo "โ
PostgreSQL client found"
@cargo sqlx --version > /dev/null 2>&1 || (echo "โ ๏ธ sqlx-cli not found. Run: cargo install sqlx-cli" && exit 1)
@echo "โ
sqlx-cli found"
@echo "โ
All dependencies satisfied!"
@echo ""
setup: check-deps setup-env
@echo "โ
Setup complete!"
@echo ""
@echo "Next steps:"
@echo " 1. Edit .env with your actual credentials"
@echo " 2. Run: make db"
@echo " 3. Run: make migrate"
@echo " 4. Run: make run"
setup-env:
@if [ ! -f .env ]; then \
echo "๐ Creating .env file..."; \
echo "CLAW_DATABASE_URL=postgres://postgres:postgres@localhost:5432/claw_spawn" > .env; \
echo "CLAW_DIGITALOCEAN_TOKEN=your_digitalocean_api_token_here" >> .env; \
echo "CLAW_ENCRYPTION_KEY=$$(openssl rand -base64 32)" >> .env; \
echo "CLAW_SERVER_HOST=0.0.0.0" >> .env; \
echo "CLAW_SERVER_PORT=8080" >> .env; \
echo "CLAW_OPENCLAW_IMAGE=ubuntu-22-04-x64" >> .env; \
echo "โ
Created .env with default values"; \
echo "โ ๏ธ IMPORTANT: Edit .env and add your DigitalOcean token!"; \
else \
echo "โ
.env file already exists"; \
fi
db:
@echo "๐๏ธ Setting up database..."
@if [ -z "$$CLAW_DATABASE_URL" ]; then \
echo "โ CLAW_DATABASE_URL not set. Run: make setup-env"; \
exit 1; \
fi
@DB_NAME=$$(echo "$$CLAW_DATABASE_URL" | sed -n 's/.*\/\([^?]*\).*/\1/p'); \
DB_HOST=$$(echo "$$CLAW_DATABASE_URL" | sed -n 's/.*@\([^:]*\):.*/\1/p'); \
DB_USER=$$(echo "$$CLAW_DATABASE_URL" | sed -n 's/.*:\/\/\([^:]*\):.*/\1/p'); \
psql -h $$DB_HOST -U $$DB_USER -d postgres -tc "SELECT 1 FROM pg_database WHERE datname = '$$DB_NAME'" | grep -q 1 || \
psql -h $$DB_HOST -U $$DB_USER -d postgres -c "CREATE DATABASE $$DB_NAME;" && \
echo "โ
Database created: $$DB_NAME" || \
echo "โ
Database already exists: $$DB_NAME"
migrate:
@echo "๐ Running migrations..."
@if [ -z "$$CLAW_DATABASE_URL" ]; then \
echo "โ CLAW_DATABASE_URL not set. Loading from .env..."; \
export $$(grep -v '^#' .env | xargs) && cargo sqlx migrate run; \
else \
cargo sqlx migrate run; \
fi
@echo "โ
Migrations complete!"
build:
@echo "๐จ Building release binary..."
@cargo build --release --bin claw-spawn-server
@echo "โ
Build complete!"
@echo " Binary: target/release/claw-spawn-server"
@echo ""
dev-build:
@echo "๐จ Building (dev mode)..."
@cargo build --bin claw-spawn-server
run:
@echo "๐ Starting server..."
@if [ -z "$$CLAW_DATABASE_URL" ]; then \
echo "๐ Loading environment from .env..."; \
export $$(grep -v '^#' .env | xargs) && ./target/release/claw-spawn-server; \
else \
./target/release/claw-spawn-server; \
fi
dev: check-deps dev-build
@echo "๐ Starting server in dev mode..."
@echo " (Use Ctrl+C to stop)"
@echo ""
@if [ -z "$$CLAW_DATABASE_URL" ]; then \
export $$(grep -v '^#' .env | xargs) && cargo run --bin claw-spawn-server; \
else \
cargo run --bin claw-spawn-server; \
fi
test:
@echo "๐งช Running tests..."
@cargo test
@echo "โ
Tests complete!"
check:
@echo "๐ Checking code..."
@cargo check
@echo "โ
Code check passed!"
fmt:
@echo "โจ Formatting code..."
@cargo fmt
@echo "โ
Code formatted!"
lint:
@echo "๐ Running clippy..."
@cargo clippy -- -D warnings
@echo "โ
Linting complete!"
clean:
@echo "๐งน Cleaning build artifacts..."
@cargo clean
@rm -rf target/
@echo "โ
Clean complete!"
reset: clean
@echo "โ ๏ธ This will delete the database and all data!"
@read -p "Are you sure? [y/N] " confirm && [ $$confirm = "y" ] || exit 1
@if [ -z "$$CLAW_DATABASE_URL" ]; then export $$(grep -v '^#' .env | xargs); fi; \
DB_NAME=$$(echo "$$CLAW_DATABASE_URL" | sed -n 's/.*\/\([^?]*\).*/\1/p'); \
DB_HOST=$$(echo "$$CLAW_DATABASE_URL" | sed -n 's/.*@\([^:]*\):.*/\1/p'); \
DB_USER=$$(echo "$$CLAW_DATABASE_URL" | sed -n 's/.*:\/\/\([^:]*\):.*/\1/p'); \
psql -h $$DB_HOST -U $$DB_USER -d postgres -c "DROP DATABASE IF EXISTS $$DB_NAME;" && \
echo "โ
Database dropped"
docker-build:
@echo "๐ณ Building Docker image..."
@docker build -t claw-spawn:latest .
@echo "โ
Docker image built: claw-spawn:latest"
docker-run:
@echo "๐ณ Starting with Docker Compose..."
@if [ -f docker-compose.yml ]; then \
docker-compose up --build; \
else \
echo "โ docker-compose.yml not found"; \
echo "Create one or use: make run"; \
fi
install-sqlx:
@echo "๐ฆ Installing sqlx-cli..."
@cargo install sqlx-cli --no-default-features --features native-tls,postgres
@echo "โ
sqlx-cli installed!"
migrate-add:
@read -p "Migration name: " name; \
cargo sqlx migrate add $$name
migrate-status:
@cargo sqlx migrate info
migrate-revert:
@cargo sqlx migrate revert
check-server:
@echo "๐ฅ Checking server health..."
@curl -s http://localhost:8080/health && echo "" || echo "โ Server not running"
generate-key:
@echo "๐ New encryption key:"
@openssl rand -base64 32
@echo ""
@echo "Add this to your .env file as CLAW_ENCRYPTION_KEY"
env:
@echo "๐ Current Environment:"
@echo "======================"
@echo "CLAW_DATABASE_URL: $${CLAW_DATABASE_URL:-<not set>}"
@echo "CLAW_SERVER_HOST: $${CLAW_SERVER_HOST:-<not set>}"
@echo "CLAW_SERVER_PORT: $${CLAW_SERVER_PORT:-<not set>}"
@echo "CLAW_OPENCLAW_IMAGE: $${CLAW_OPENCLAW_IMAGE:-<not set>}"
@echo "CLAW_DIGITALOCEAN_TOKEN: $${CLAW_DIGITALOCEAN_TOKEN:+<set>}"
@echo "CLAW_ENCRYPTION_KEY: $${CLAW_ENCRYPTION_KEY:+<set>}"