Files
pic/Makefile
T
roof 4ed2a6cbae fix: config persistence, setup script, and install docs
- app.py: ConfigManager now uses CONFIG_DIR env var for config file path
  instead of hardcoded './config/cell_config.json' — config was being read
  from the image's working directory, making all settings writes ephemeral
  (lost on container restart)
- wireguard_manager: generate_config uses configured address/port instead of
  hardcoded 10.0.0.1 in DNAT rules and Address field
- scripts/setup_cell.py: full setup script — generates WireGuard keys (wg
  binary or Python cryptography fallback), writes wg0.conf and cell_config.json
  with correct _identity key; CELL_NAME / VPN_ADDRESS / WG_PORT env vars
- Makefile: setup target passes env vars through; build-api / build-webui targets
- README: replace install.sh references with make setup && make start

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-22 07:37:11 -04:00

198 lines
6.0 KiB
Makefile

# Personal Internet Cell - Makefile
# Provides easy commands for managing the cell
.PHONY: help start stop restart status logs clean setup init-peers build build-api build-webui
# Default target
help:
@echo "Personal Internet Cell - Management Commands"
@echo ""
@echo "Setup (run once on a fresh host):"
@echo " setup - Create dirs, generate WireGuard keys, write configs, then: make start"
@echo " Env vars: CELL_NAME=mycell CELL_DOMAIN=cell VPN_ADDRESS=10.0.0.1/24 WG_PORT=51820"
@echo " init-peers - Reset peer list to empty"
@echo ""
@echo "Management:"
@echo " start - Start all services (docker compose up -d)"
@echo " stop - Stop all services"
@echo " restart - Restart all services"
@echo " status - Show container status + API health"
@echo " logs - Follow logs from all services"
@echo ""
@echo "Build:"
@echo " build - Rebuild API image"
@echo " build-api - Rebuild API image (no cache)"
@echo " build-webui - Rebuild Web UI image (no cache)"
@echo ""
@echo "Individual Services:"
@echo " start-dns - Start DNS service only"
@echo " start-api - Start API service only"
@echo " start-wg - Start WireGuard service only"
@echo ""
@echo "Maintenance:"
@echo " clean - Remove all containers and volumes"
@echo " backup - Backup configuration and data"
@echo " restore - Restore from backup"
# Setup commands
setup:
@echo "Setting up Personal Internet Cell..."
CELL_NAME=$(or $(CELL_NAME),mycell) \
CELL_DOMAIN=$(or $(CELL_DOMAIN),cell) \
VPN_ADDRESS=$(or $(VPN_ADDRESS),10.0.0.1/24) \
WG_PORT=$(or $(WG_PORT),51820) \
python3 scripts/setup_cell.py
init-peers:
@echo "Initializing peer configuration..."
@echo '[]' > data/api/peers.json
@echo "Peer configuration initialized."
# Management commands
start:
@echo "Starting Personal Internet Cell..."
docker-compose up -d
@echo "Services started. Check status with 'make status'"
stop:
@echo "Stopping Personal Internet Cell..."
docker-compose down
@echo "Services stopped."
restart:
@echo "Restarting Personal Internet Cell..."
docker-compose restart
@echo "Services restarted."
status:
@echo "Personal Internet Cell Status:"
@echo "================================"
docker-compose ps
@echo ""
@echo "API Status:"
@curl -s http://localhost:3000/health || echo "API not responding"
logs:
@echo "Showing logs from all services..."
docker-compose logs -f
# Individual service commands
start-dns:
@echo "Starting DNS service..."
docker-compose up -d dns
start-api:
@echo "Starting API service..."
docker-compose up -d api
start-wg:
@echo "Starting WireGuard service..."
docker-compose up -d wireguard
start-webui:
@echo "Starting WebUi service..."
docker-compose up -d webui
# Maintenance commands
clean:
@echo "Cleaning up containers and volumes..."
docker-compose down -v
docker system prune -f
@echo "Cleanup complete."
backup:
@echo "Creating backup..."
@mkdir -p backups
@tar -czf backups/cell-backup-$(shell date +%Y%m%d-%H%M%S).tar.gz \
config/ data/ docker-compose.yml Makefile README.md
@echo "Backup created in backups/ directory."
restore:
@echo "Available backups:"
@ls -la backups/cell-backup-*.tar.gz 2>/dev/null || echo "No backups found"
@echo ""
@echo "To restore, run: tar -xzf backups/cell-backup-YYYYMMDD-HHMMSS.tar.gz"
# Development commands
dev:
@echo "Starting development environment..."
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d
build:
@echo "Building API service..."
docker-compose build api
build-api:
@echo "Rebuilding API (no cache)..."
docker-compose build --no-cache api
docker-compose up -d api
build-webui:
@echo "Rebuilding Web UI (no cache)..."
docker-compose build --no-cache webui
docker-compose up -d webui
# Testing commands
test:
@echo "Running all unit and integration tests with pytest..."
pytest tests/ api/tests/
test-all:
@echo "Running all tests using the unified test runner..."
python3 api/tests/run_tests.py
# Remove or update old test targets that reference non-existent files
test-unit:
@echo "Running unit tests only..."
pytest tests/
test-coverage:
@echo "Running tests with coverage..."
pytest tests/ api/tests/ --cov=api --cov-report=html --cov-report=term-missing -v
test-api:
@echo "Testing API endpoints..."
cd api && python3 -m pytest tests/test_api_endpoints.py -v
test-cli:
@echo "Testing CLI tool..."
cd api && python3 -m pytest tests/test_cli_tool.py -v
test-phase1:
@echo "Testing Phase 1 (Network Foundation)..."
cd api && python3 -m pytest tests/test_network_manager.py tests/test_phase1_endpoints.py -v
test-phase2:
@echo "Testing Phase 2 (WireGuard & Peer Registry)..."
cd api && python3 -m pytest tests/test_wireguard_manager.py tests/test_phase2_endpoints.py -v
test-phase3:
@echo "Testing Phase 3 (Core Digital Services)..."
cd api && python3 -m pytest tests/test_phase3_managers.py tests/test_phase3_endpoints.py -v
test-phase4:
@echo "Testing Phase 4 (VPN Gateway & Routing)..."
cd api && python3 -m pytest tests/test_phase4_routing.py tests/test_phase4_endpoints.py -v
test-all-phases:
@echo "Testing all phases..."
cd api && python3 -m pytest tests/ -v
# Network commands
show-routes:
@echo "Current routing table:"
@docker exec cell-wireguard wg show || echo "WireGuard not running"
add-peer:
@echo "Usage: make add-peer PEER_NAME=name PEER_IP=ip PEER_KEY=public_key"
@if [ -n "$(PEER_NAME)" ] && [ -n "$(PEER_IP)" ] && [ -n "$(PEER_KEY)" ]; then \
curl -X POST http://localhost:3000/api/peers \
-H "Content-Type: application/json" \
-d '{"name":"$(PEER_NAME)","ip":"$(PEER_IP)","public_key":"$(PEER_KEY)"}'; \
else \
echo "Please provide PEER_NAME, PEER_IP, and PEER_KEY parameters"; \
fi
list-peers:
@echo "Configured peers:"
@curl -s http://localhost:3000/api/peers | python3 -m json.tool || echo "API not responding"