Building a self-serve deployment stack with Caddy and Docker
Today I built an infrastructure that lets me deploy any site or webapp to a subdomain in a few commands, with automatic SSL. Hereβs how it works. π― The goal To be able to do: ./deploy.sh my-app nginx:alpine # β https://my-app.example.com (SSL included, ready in seconds) Without having to: Manually configure DNS Manage SSL certificates Expose host ports Write complex nginx configs ποΈ High-level architecture βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β CLOUDFLARE β β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β β β Zone: example.com β β β β *.example.com β A record β Server IP β β β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β βΌ :80/:443 βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β SERVER β β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β β β CADDY β β β β - Reverse proxy β β β β - Auto-SSL via Let's Encrypt (DNS challenge) β β β β - Wildcard certificate *.example.com β β β β - Dynamic routing to containers β β β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β β β β β β β βΌ βΌ βΌ β β βββββββββββββββ βββββββββββββββ βββββββββββββββ β β β Container β β Container β β Container β β β β app-a β β app-b β β app-c β β β βββββββββββββββ βββββββββββββββ βββββββββββββββ β β β β Network: apps-network (bridge) β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ π§ Components 1. Cloudflare DNS + wildcard The first step is to create a wildcard DNS record: ...