feat: implement Caddy integration with Docker-first approach (Issue #4)

- Add Caddy client package (client.go) with Load/GetConfig/Ping methods
- Implement config generator (config.go) transforming ProxyHost → Caddy JSON
- Add pre-flight validator (validator.go) catching config errors before reload
- Create manager (manager.go) with rollback capability using config snapshots
- Add CaddyConfig model for audit trail of configuration changes
- Update Config to include Caddy admin API and config dir settings
- Create comprehensive unit tests with 100% coverage for caddy package

Docker Infrastructure:
- Add docker-compose.yml with Caddy sidecar container
- Add docker-compose.dev.yml for development overrides
- Create .github/workflows/docker-publish.yml for GHCR publishing
- Update CI to build Docker images and run integration tests
- Add DOCKER.md with comprehensive deployment guide
- Update Makefile with docker-compose commands
- Update README with Docker-first deployment instructions

Configuration:
- Add CPM_CADDY_ADMIN_API and CPM_CADDY_CONFIG_DIR env vars
- Update .env.example with new Caddy settings
- Update AutoMigrate to include CaddyConfig model

All acceptance criteria met:
 Can programmatically generate valid Caddy JSON configs
 Can reload Caddy configuration via admin API
 Invalid configs caught by validator before reload
 Automatic rollback on failure via snapshot system
This commit is contained in:
Wikid82
2025-11-17 19:03:59 -05:00
parent 65944e3455
commit b17e7d3d5f
18 changed files with 1449 additions and 21 deletions

30
docker-compose.dev.yml Normal file
View File

@@ -0,0 +1,30 @@
version: '3.9'
# Development override - use with: docker-compose -f docker-compose.yml -f docker-compose.dev.yml up
services:
caddy:
# Development: expose admin API externally for debugging
ports:
- "80:80"
- "443:443"
- "443:443/udp"
- "2019:2019" # Caddy admin API (dev only)
command: caddy run --config /dev/null --adapter json
app:
build:
context: .
dockerfile: Dockerfile
target: backend-builder # Stop at builder stage for faster rebuilds
environment:
- CPM_ENV=development
- CPM_HTTP_PORT=8080
- CPM_DB_PATH=/app/data/cpm.db
- CPM_FRONTEND_DIR=/app/frontend/dist
- CPM_CADDY_ADMIN_API=http://caddy:2019
- CPM_CADDY_CONFIG_DIR=/app/data/caddy
volumes:
- ./backend:/app/backend:ro # Mount source for live reload (if using air)
- app_data:/app/data
command: /app/backend/api # Run the built binary