Initial template

This commit is contained in:
hh
2026-09-08 19:15:15 +02:00
commit 02ae0764a4
10 changed files with 113 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
{{ project_slug | upper }}_DOMAIN={{ project_slug | replace('_', '-') }}.localhost
CLOUDFLARE_API_TOKEN=
+2
View File
@@ -0,0 +1,2 @@
.env
Caddyfile
+14
View File
@@ -0,0 +1,14 @@
{
admin localhost:2019
log {
format console
}
servers {
trusted_proxies cloudflare
client_ip_headers Cf-Connecting-Ip
}
}
import /etc/caddy/projects.d/*/site.caddy
+23
View File
@@ -0,0 +1,23 @@
{%- set dash = project_slug | replace('_', '-') -%}
# caddy
`site.caddy` routes `{{ '{$' }}{{ project_slug | upper }}_DOMAIN}` to the project's services over the external `caddy` docker network. It works standalone and inside a shared Caddy that fronts several projects.
Standalone:
```sh
docker network create caddy
cp Caddyfile.example Caddyfile
cp .env.example .env
docker compose up -d
```
Shared Caddy: mount this directory as `/etc/caddy/projects.d/{{ dash }}:ro`, keep `import /etc/caddy/projects.d/*/site.caddy` in its Caddyfile and put `{{ project_slug | upper }}_DOMAIN` in its environment.
Rules that keep `site.caddy` portable:
- the domain comes only from the environment variable
- no `tls` block, certificates are configured by the host Caddy (`acme_dns cloudflare {env.CLOUDFLARE_API_TOKEN}` in the global block)
- snippets are prefixed with the project slug because Caddy snippets are global
- mount the directory, not the file: a single-file bind mount goes stale when git replaces the inode
- keep `admin localhost:2019`, `admin off` makes `caddy reload` impossible
+24
View File
@@ -0,0 +1,24 @@
{%- set dash = project_slug | replace('_', '-') -%}
services:
caddy:
image: ghcr.io/caddybuilds/caddy-cloudflare:latest
restart: unless-stopped
ports:
- "0.0.0.0:80:80"
- "0.0.0.0:443:443"
- "0.0.0.0:443:443/udp"
networks:
- caddy
env_file:
- .env
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- .:/etc/caddy/projects.d/{{ dash }}:ro
- caddy_data:/data
networks:
caddy:
external: true
volumes:
caddy_data:
+17
View File
@@ -0,0 +1,17 @@
{%- set dash = project_slug | replace('_', '-') -%}
{%- set domain = project_slug | upper ~ '_DOMAIN' -%}
{$ {{- domain -}} } {
encode zstd gzip
{% if 'api' in routes and 'frontend' in routes %}
handle /api/* {
reverse_proxy {{ dash }}-api:8080
}
handle {
reverse_proxy {{ dash }}-frontend:3000
}
{% elif 'api' in routes %}
reverse_proxy {{ dash }}-api:8080
{% else %}
reverse_proxy {{ dash }}-frontend:3000
{% endif %}}
@@ -0,0 +1 @@
{{ _copier_answers|to_nice_yaml -}}