use caddyfile instead of api

This commit is contained in:
pavel 2026-05-14 23:36:16 +02:00
commit 3c79a8c778
9 changed files with 206 additions and 248 deletions

View file

@ -6,7 +6,7 @@ Features:
- Workspace model mapping each app-user workspace to a host Unix account
- Create projects per authenticated user
- Auto-create Forgejo repository or onboard an existing repository URL
- Auto-create Caddy reverse-proxy route via Admin API (optional)
- Auto-generate Caddyfile route fragment and reload Caddy (optional)
- Manage project env vars
- Auto-generate user-scoped systemd service per project
- PostgreSQL persistence with startup migration
@ -43,20 +43,33 @@ Important:
- `FORGEJO_ORG` switches creation from personal repos to org repos.
- `UNIX_SOCKET_PATH` enables unix socket listener in addition to `LISTEN_ADDR`.
- `CADDY_ROUTE_ENABLED=true` enables route provisioning.
- `CADDY_AUTH_ENABLED=true` enables authentik-style forward auth on provisioned app routes.
- `CADDY_AUTH_UPSTREAM` sets auth upstream dial (default `localhost:9000`).
- `CADDY_AUTH_URI` sets auth check URI (default `/outpost.goauthentik.io/auth/caddy`).
- `CADDY_FRAGMENT_PATH` points to generated Caddyfile fragment path (default `/etc/caddy/fragments/project-manager.caddy`).
- `CADDY_RELOAD_COMMAND` command run after fragment write (default `sudo -n systemctl reload caddy`).
- `CADDY_AUTH_IMPORT_NAME` snippet import name used per app host block (default `auth`).
- `CADDY_PERSIST_CONFIG_PATH` is only useful if you still use Caddy Admin API externally.
- `CADDY_ADMIN_URL` points to the Caddy Admin API (default `http://localhost:2019`).
- `CADDY_SERVER_ID` is the HTTP server object id under `apps.http.servers` (default `srv0`).
- `CADDY_DOMAIN_SUFFIX` controls generated host as `<slug>.<suffix>` (if empty: `<user>-<slug>.local`).
- `WEBHOOK_BASE_URL` sets absolute webhook URLs returned by API/UI (recommended behind reverse proxy).
## Caddy API Behavior
## Caddyfile Fragment Behavior
On project creation, when Caddy routing is enabled, the app appends a route to:
- `POST /config/apps/http/servers/<CADDY_SERVER_ID>/routes`
On provisioning/reprovision, when `CADDY_ROUTE_ENABLED=true`, the app regenerates a managed fragment containing all project routes and then runs `CADDY_RELOAD_COMMAND`.
Route shape:
- `match.host = [<project host>]`
- `handle[0].handler = reverse_proxy`
- `handle[0].upstreams[0].dial = unix/<unix-user-home>/projects/<app>/app.sock`
Each route block is:
- `<slug>.<domain> {`
- `import auth` (name controlled by `CADDY_AUTH_IMPORT_NAME`, optional when auth enabled)
- `log`
- `reverse_proxy unix//<unix-user-home>/projects/<app>/app.sock`
- `}`
In your static `/etc/caddy/Caddyfile`, include:
```caddyfile
import /etc/caddy/fragments/project-manager.caddy
```
## Workspaces and Unix Users