Watch
1
0
Fork
You've already forked Insoulum-Edge
0
The border router with Caddy container for my projects, that owns ports 80/443, terminates TLS and routes every request to the right place
  • Dockerfile 100%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-23 02:16:40 +03:00
.env.example Initial commit: Insoulum Edge 2026-11-23 00:36:15 +03:00
.gitignore Initial commit: Insoulum Edge 2026-11-23 00:36:15 +03:00
.rsync-exclude Initial commit: Insoulum Edge 2026-11-23 00:36:15 +03:00
Caddyfile Initial commit: Insoulum Edge 2026-11-23 00:36:15 +03:00
docker-compose.yml docker-compose: drop the unused project network 2026-11-23 00:45:34 +03:00
Dockerfile Initial commit: Insoulum Edge 2026-11-23 00:36:15 +03:00
README.md README: document startup order and the edge_default contract 2026-11-23 02:16:40 +03:00

Insoulum Edge

The border router for *.insoulum.ru: one Caddy container that owns ports 80/443, terminates TLS and routes every request to the right place.

It exists so that projects can stay dumb. Insoulum-Web serves files from disk, Lucario-Forge serves a port — neither of them knows that Caddy exists, and neither has to be edited when a new project appears. All routing lives here.

Structure

.
├── Caddyfile                ← every site and backend, the only routing map
├── docker-compose.yml       ← ports 80/443 + the edge_default network
├── Dockerfile               ← Caddy + caddy-dns/desec (DNS-01 for wildcards)
├── .env.example             ← DESEC_TOKEN, SITES_DIR
└── data/                    ← certificates (created at runtime, gitignored)

This repo is the only thing that owns ports 80/443. Static content lives in Insoulum-Web and is mounted read-only; backends like Lucario-Forge join edge_default and get a reverse_proxy block.

How routing works

Three rules, in order of specificity:

Rule Handles
insoulum.ru the apex — a wildcard cert does not cover it (RFC 6125)
git.insoulum.ru a backend: reverse_proxy forgejo:3000
*.insoulum.ru everything else: static files from /srv/{host}

Static sites need no block at all — the wildcard maps {host} to /srv/{host} and serves it. Add an explicit block only when a site needs something special (a redirect, custom headers, a rewrite); Caddy prefers the more specific match.

New backends get a block that names a container and a port:

myapp.insoulum.ru {
	import security-headers
	reverse_proxy myapp:8080
	import tls-desec
}

The project itself just has to join edge_default as an external network:

networks:
  edge_default:
    external: true
    name: edge_default

Startup order

Edge is the only container that touches the internet, so it goes first:

cd /opt/insoulum-edge && docker compose up -d    # 1. router, owns edge_default
cd /opt/forgejo       && docker compose up -d    # 2. backends, optional

Backends declare edge_default as external, so they refuse to start if the router has never been up. After that, order does not matter — they find each other by container name.

If git.insoulum.ru shows 502, the router is fine but Forgejo is not running. Everything else keeps working.

TLS

  • Wildcard *.insoulum.ru and the apex are issued via DNS-01 through the deSEC plugin — no public port 80 needed for validation.
  • Important: deSEC's ns2.desec.org syncs in ~70s (ns1 — ~3s), and Let's Encrypt checks both nameservers. That's why propagation_delay is 180s — without it issuance fails with No TXT record found.
  • Certificates live in data/ (bind-mount) and renew automatically. Copy data/ over during a migration to avoid re-issuing.

Deploy

The image is built locally — xcaddy compiles Go, which is an OOM risk on a 1 GB VDS.

First deploy (fresh server)

# Locally: build and pack
docker build -t insoulum-edge:1.0 .
docker save insoulum-edge:1.0 | gzip > insoulum-edge.tar.gz

# Ship
scp insoulum-edge.tar.gz <host>:/opt/insoulum-edge/
rsync -av --exclude-from='.rsync-exclude' ./ <host>:/opt/insoulum-edge/

# On the server
cd /opt/insoulum-edge
gunzip -c insoulum-edge.tar.gz | docker load
cp .env.example .env && vim .env      # DESEC_TOKEN, SITES_DIR
chmod 600 .env
docker compose up -d

After up, Caddy requests the certificates. First issuance takes ~3–4 minutes. Watch it:

docker logs -f insoulum-edge       # wait for "certificate obtained successfully"

Updating

Changed Command
Caddyfile rsync + docker compose restart
docker-compose.yml (ports, networks) rsync + docker compose up -d --force-recreate
image (new Caddy version) rebuild locally, ship, docker load, up -d --force-recreate

docker compose restart does not re-read docker-compose.yml — it reuses the running container's config. Use --force-recreate after editing env.

Adding a subdomain

  1. Static site — create sites/<sub>.insoulum.ru/index.html in Insoulum-Web, add a DNS A-record. Nothing to do here.
  2. Backend — add a site block above, make the project join edge_default, add a DNS A-record, then rsync + restart.

Consumers

Project Role
Insoulum-Web static sites in sites/, mounted here read-only
Lucario-Forge Forgejo, joined to edge_default, served at git.insoulum.ru

Notes

  • SITES_DIR is the one knob that points outside this repo. On the server it is /opt/insoulum/sites; locally it defaults to ./sites.
  • The Server header is hidden, security headers are attached to every response — see the security-headers snippet.
  • edge_default has a fixed name on purpose: consumers declare it as external and would break if it were renamed with the project.