3 Commits
6 changed files with 8 additions and 26 deletions

No files matched your search

+2 -2
View File
@@ -1,8 +1,8 @@
# caddy # caddy
Copier template for a `caddy/` directory: a portable `site.caddy` for the project's `api` and `frontend` services, a standalone Caddy compose file and an example global Caddyfile. Copier template for a `caddy/` directory: a portable `site.caddy` for the project's `api` and `frontend`, a standalone compose file and an example Caddyfile.
```sh ```sh
copier copy --trust -d project_slug=my_thing -d 'routes=["api","frontend"]' <this-repo> <dest> copier copy --trust -d project_slug=my_thing -d 'routes=["api","frontend"]' <this-repo> <dest>
copier update -a .copier-answers.caddy.yml copier update -a .copier/caddy.yml
``` ```
+1 -1
View File
@@ -1,6 +1,6 @@
_subdirectory: template _subdirectory: template
_templates_suffix: .jinja _templates_suffix: .jinja
_answers_file: .copier-answers.caddy.yml _answers_file: .copier/caddy.yml
_envops: _envops:
keep_trailing_newline: true keep_trailing_newline: true
+1 -1
View File
@@ -1,2 +1,2 @@
{{ project_slug | upper }}_DOMAIN={{ project_slug | replace('_', '-') }}.localhost {{ project_slug | upper | replace('-', '_') }}_DOMAIN={{ project_slug | replace('_', '-') }}.localhost
CLOUDFLARE_API_TOKEN= CLOUDFLARE_API_TOKEN=
+1 -1
View File
@@ -1,2 +1,2 @@
.env .env
Caddyfile /Caddyfile
+2 -20
View File
@@ -1,23 +1,5 @@
{%- set dash = project_slug | replace('_', '-') -%} {%- set dash = project_slug | replace('_', '-') -%}
{%- set domain = project_slug | upper | replace('-', '_') ~ '_DOMAIN' -%}
# caddy # 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. `site.caddy` routes `{{ '{$' }}{{ domain }}}` to the project over the external `caddy` network. In a shared Caddy, mount this directory as `/etc/caddy/projects.d/{{ dash }}:ro` and set `{{ domain }}`. Keep it portable: domain only from the env, no `tls`, snippets prefixed with `{{ project_slug }}_`.
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
+1 -1
View File
@@ -1,5 +1,5 @@
{%- set dash = project_slug | replace('_', '-') -%} {%- set dash = project_slug | replace('_', '-') -%}
{%- set domain = project_slug | upper ~ '_DOMAIN' -%} {%- set domain = project_slug | upper | replace('-', '_') ~ '_DOMAIN' -%}
{$ {{- domain -}} } { {$ {{- domain -}} } {
encode zstd gzip encode zstd gzip
{% if 'api' in routes and 'frontend' in routes %} {% if 'api' in routes and 'frontend' in routes %}