Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
113d739
✨ Added a shared Caddy for several production sites on one server (S13)
acburdine Nov 2, 2026
90c7073
Undid only what a shared-Caddy install created, and refused a stray i…
acburdine Nov 2, 2026
93bbf3d
Linked routes into place, and planned the shared Caddy's self-update …
acburdine Nov 2, 2026
c53b2a0
Marked each site's routes with their write, and reloaded the shared C…
acburdine Nov 2, 2026
38b50ee
Serialized the shared Caddy's reloads with the sites' route changes (…
acburdine Nov 2, 2026
6b501e0
Fixed the shared Caddy's update rollback, and required URL for local …
acburdine Nov 4, 2026
f3eaa60
Kept a site's shared-Caddy routes in its backup, and restored them (S13)
acburdine Nov 4, 2026
0db74ef
Required a checksum for the routes a backup holds (S13)
acburdine Nov 4, 2026
7a42f17
Merge remote-tracking branch 'origin/next-docker' into claude/youthfu…
claude Dec 6, 2026
c97802e
Made the shared Caddy static, with each site's own Caddy behind it (S13)
claude Dec 6, 2026
ff6f9a9
Documented what to keep a copy of in the shared Caddy's directory (S13)
claude Dec 6, 2026
efa836f
Updated ActivityPub to 1.3.7 to match main
claude Dec 6, 2026
d97e459
Fixed the backup e2e job for a Ghost image without Casper
claude Dec 6, 2026
3db4cde
Checked a site's domains and its shared Caddy wherever it joins, not …
claude Dec 6, 2026
4109505
Asked Compose and Docker for a site's names on the shared network (S13)
claude Dec 6, 2026
52ae3ce
Corrected what is said of two installs started at once for one domain…
claude Dec 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ backups
caddy/sites/*.caddy
caddy/custom/*.caddy
caddy/global/*.caddy
infra/caddy/custom/*.caddy
infra/caddy/global/*.caddy
docs
pages
scripts
Expand Down
9 changes: 8 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# interpolated by accident.

# --- Site mode -------------------------------------------------------------
# Exactly one site mode must be selected: `local` or `production`.
# Exactly one site mode must be selected: `local` or `production`, or `shared-caddy`
# for a production site behind the shared Caddy (docs/caddy.md#the-shared-caddy).
# Optional per-site profiles are added to the same list: `analytics`,
# `activitypub`, `supervisor`, and for a local site `mailpit`. Profiles are additive; adding
# an optional profile never changes the site mode.
Expand Down Expand Up @@ -73,6 +74,12 @@ GHOST_PORT="2368"
HTTP_PORT="80"
HTTPS_PORT="443"

# Behind the shared Caddy (`shared-caddy`): the hosts of URL and ADMIN_URL,
# which name the site's Caddy on the shared Caddy's network. `install` writes
# them; they must match URL and ADMIN_URL.
# INGRESS_HOST="example.com"
# INGRESS_ADMIN_HOST="admin.example.com"

# --- Lifecycle ------------------------------------------------------------
# Applied to long-running services only. One-shot jobs keep `restart: "no"`.
# production: unless-stopped
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ jobs:
- { name: Ghost nightly channel, script: ghost-nightly }
- { name: Migration from the released main layout, script: migrate-main }
- { name: Backup and restore, script: backup }
- { name: Shared Caddy, script: shared-caddy }
- { name: Import, script: import, node: "22" }
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ Linux. There is no native Windows launcher.
## Site modes

`install --local` selects Ghost and MySQL on loopback. A production install
adds Caddy with automatic HTTPS. [Configuration](docs/configuration.md#site-modes-and-profiles)
adds Caddy with automatic HTTPS; several production sites on one server share
one Caddy, set up with `install --infra` ([caddy.md](docs/caddy.md#the-shared-caddy)). [Configuration](docs/configuration.md#site-modes-and-profiles)
defines the modes and optional profiles; [installation](docs/install.md#optional-services)
explains how to enable them.

Expand Down
35 changes: 30 additions & 5 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# production ghost + db + caddy (HTTPS ingress)
# no-caddy ghost + db, a production site behind the operator's own proxy
# (nginx, Apache) on 127.0.0.1:${GHOST_PORT}
# shared-caddy ghost + db + caddy-internal, a production site behind the
# server's shared Caddy (infra/compose.yml), which holds 80 and 443
# Optional, per-site profiles: analytics, activitypub, and for local sites
# mailpit, and `supervisor`, which runs Ghost updates asked for in Ghost Admin
# (docs/upgrade-supervisor.md).
Expand All @@ -35,7 +37,7 @@ services:
# Do not alter this without updating the Tinybird Sync container as well
image: ${GHOST_IMAGE_REF:-${GHOST_IMAGE:-ghost}:${GHOST_VERSION:-6-next-alpine}}
restart: ${RESTART_POLICY:-unless-stopped}
profiles: [local, production, no-caddy]
profiles: [local, production, no-caddy, shared-caddy]
labels:
<<: *site-labels
org.ghost.docker.lifecycle: long-running
Expand Down Expand Up @@ -114,7 +116,7 @@ services:
db:
image: mysql:8.0.44@sha256:f37951fc3753a6a22d6c7bf6978c5e5fefcf6f31814d98c582524f98eae52b21
restart: ${RESTART_POLICY:-unless-stopped}
profiles: [local, production, no-caddy]
profiles: [local, production, no-caddy, shared-caddy]
labels:
<<: *site-labels
org.ghost.docker.lifecycle: long-running
Expand Down Expand Up @@ -186,7 +188,7 @@ services:
networks:
- ghost_network

caddy:
caddy: &caddy
image: caddy:2.10.2-alpine@sha256:953131cfea8e12bfe1c631a36308e9660e4389f0c3dfb3be957044d3ac92d446
restart: ${RESTART_POLICY:-unless-stopped}
profiles: [production]
Expand Down Expand Up @@ -217,6 +219,22 @@ services:
networks:
- ghost_network

# Behind the shared Caddy (docs/caddy.md#the-shared-caddy): the site's own
# Caddy, with the same routes and files, serving plain HTTP and publishing no
# port. The shared Caddy holds 80 and 443 and the certificates, and reaches
# this one on its network by the site's domains, which are its aliases there.
# Nothing else of the site is on that network.
caddy-internal:
<<: *caddy
profiles: [shared-caddy]
ports: []
networks:
ghost_network:
ingress:
aliases:
- ${INGRESS_HOST:-}.ghost.internal
- ${INGRESS_ADMIN_HOST:-${INGRESS_HOST:-}}.ghost.internal

traffic-analytics:
image: ghost/traffic-analytics:1.0.450@sha256:33c0ff8a369040e1455b790cf1711c2ea7f3174bcd26230dc9f7fc77b401816c
restart: ${RESTART_POLICY:-unless-stopped}
Expand All @@ -243,7 +261,7 @@ services:
- traffic-analytics-${COMPOSE_PROJECT_NAME:-ghost}

activitypub:
image: ghcr.io/tryghost/activitypub:1.3.0@sha256:59f0a7470df4ee27b609bd97f4189bf3c6c3f3ecf87f434bbe338fafd5f80070
image: ghcr.io/tryghost/activitypub:1.3.7@sha256:5a38227c42b9f2f2beb9add2b2ddfdfe922b63579e474819f3d67f341ca168c0
restart: ${RESTART_POLICY:-unless-stopped}
profiles: [activitypub]
labels:
Expand Down Expand Up @@ -316,7 +334,7 @@ services:
# or failed job stays stopped instead of being restarted by the daemon.

activitypub-migrate:
image: ghcr.io/tryghost/activitypub-migrations:1.3.0@sha256:ff5bbf14b71494a95611c6e799d981435b744116c52ad88d20be1d4fef43fa80
image: ghcr.io/tryghost/activitypub-migrations:1.3.7@sha256:99cb03c660fd7681678f77fd10a3b5e7c86b7d73e27962d47b11043f32e602fb
restart: "no"
profiles: [activitypub]
labels:
Expand Down Expand Up @@ -413,3 +431,10 @@ volumes:

networks:
ghost_network:
# The shared Caddy's network, which `install --infra` creates and no Compose
# project owns. Only a site behind the shared Caddy uses it.
ingress:
# Always ghost-ingress, which the manager finds the shared Caddy by; the
# integration tests alone name another.
name: ${INGRESS_NETWORK:-ghost-ingress}
external: true
24 changes: 23 additions & 1 deletion docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ The strict schema in [`src/meta.ts`](../manager/src/meta.ts) defines
`.ghost-docker.json`. It records installation provenance, resolved Ghost identity
and managed-file checksums. It is private, gitignored, atomically written and
machine-owned. Missing metadata is distinct from invalid metadata; commands
requiring it refuse either with an actionable diagnostic.
requiring it refuse either with an actionable diagnostic. The shared Caddy's
directory has metadata of its own `mode`, `infra`, with no site URL and no
Ghost; `requireMetadata` refuses it, so only `self-update` and `info` read it.

`source` distinguishes files installed from the image from files used in a
checkout. `stack.image` is the manager pin. `payload` stores the checksum of each
Expand Down Expand Up @@ -123,6 +125,26 @@ sites installed before, keeping any file in them that was edited. Caddy routes a
`templates/site.caddy`, then belong to the operator. [caddy.md](caddy.md) owns
route edits and reload instructions.

`src/shared.ts` is the shared Caddy: one Caddy project per daemon (`install
--infra`, with its own stack files in the payload's `infra/` and metadata of
the `infra` mode with no Ghost, so that `self-update` can keep them and the
launcher current without a backup, as it holds no data), on a network the
manager creates and labels with its directory, so no Compose project's `down`
removes it. It names no site: it obtains certificates on demand and passes
each request to `<host>.ghost.internal` on that network. A production install
finds it by the network and selects the `shared-caddy` profile, which runs
the site's own Caddy as `caddy-internal`: no published port, plain HTTP, and
the site's domains as its aliases on the shared network. The site's routes
and Caddy files stay in its own directory, so the file inventory, backup,
restore and `self-update` treat them as a single site's, and nothing is ever
written in the shared Caddy's directory for a site. Before any write, an
install or a restore refuses a domain another site's Caddy has on the
network, and a shared Caddy that is missing or has no container. Nothing
locks across sites, so verification asks again once the site's Caddy has
joined (`heldByAnother` in `src/shared.ts`): two sites started at once
are never both verified, since one that passed is still on the network when
the other is asked. Either may be the one that fails, or both.

`src/bundle/manifest.ts` defines the migration bundle schema and depends only on
zod so the exporter can share it. Import policy stays outside that schema.
`src/bundle/stage.ts` stages and validates input, `src/import.ts` sequences the
Expand Down
185 changes: 182 additions & 3 deletions docs/caddy.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

`./ghost-docker install --domain` writes this site's routes into
`caddy/sites/site.caddy`, once. From then on the file is yours, as the nginx
file Ghost-CLI generated was: the manager never rewrites it.
file Ghost-CLI generated was: the manager never rewrites it. That is so on a
server with [the shared Caddy](#the-shared-caddy) too: each site behind it
keeps its routes in its own directory.

## Layout

Expand Down Expand Up @@ -32,8 +34,8 @@ A site moved from `main` keeps its own Caddyfile as `caddy/sites/site.caddy`
main's snippets, which take no arguments, from `caddy/sites/legacy-snippets/`,
and proxies to bare service names (`ghost:2368`), which resolve on the site's
own network. Both keep working. Moving to this layout's snippets and aliases,
as `install` writes them, is optional, and is needed before the site joins a
shared Caddy.
as `install` writes them, is optional, and is needed before the site could
join a shared Caddy.

## Changing routes

Expand Down Expand Up @@ -92,3 +94,180 @@ ActivityPub routes are always present. With the `activitypub` profile they
point at this site's own service; otherwise at the hosted service,
`https://ap.ghost.org`. ActivityPub, its migration job, database grants,
storage and serving URL all belong to the site.

## The shared Caddy

Only one program can hold ports 80 and 443, so several production sites on
one server share one Caddy, as Ghost-CLI's sites shared one nginx. Everything
else stays each site's own: Ghost, MySQL, ActivityPub, analytics, its routes,
backups, updates and restores work exactly as they do for a site on its own.
A local site never uses the shared Caddy, and a server without one runs each
production site with its own Caddy on 80 and 443, as before.

Set it up once, in a directory of its own, before the sites:

```bash
mkdir ~/caddy && cd ~/caddy
curl -fsSL https://docker.ghost.org/install.sh | bash -s -- install --infra --email you@example.com
```

Then install each site as usual, each in its own directory. On a server with
the shared Caddy, `install --domain` joins it. A site installed `--no-caddy`
does not. A domain another site behind it already answers to is refused
before anything is written. An existing site cannot be moved behind the
shared Caddy yet; it keeps its own Caddy, which needs 80 and 443, so set the
shared Caddy up on a server before its first production site.

### How it is connected

The shared Caddy names no site. It holds 80 and 443, obtains every site's
certificate, and passes each request, whole, to that site's own Caddy.

- The shared Caddy is its own Compose project (`ghost-infra` unless `--name`
says otherwise), with a `compose.yml` and `caddy/Caddyfile` of its own.
`install --infra` creates the network `ghost-ingress`, which belongs to no
Compose project, so taking the shared Caddy down never takes it away from
the sites.
- Each site behind it selects the `shared-caddy` profile. It keeps a Caddy of
its own, the service `caddy-internal`, with the same `caddy/` directory as a
site on its own: its routes are `caddy/sites/site.caddy` in the site's
directory, yours to edit, and in the site's backups. That Caddy publishes
no port and serves plain HTTP (the routes' addresses are `http://`).
- The site's Caddy joins `ghost-ingress` under the site's domains, as
`<domain>.ghost.internal` (`INGRESS_HOST` and `INGRESS_ADMIN_HOST` in the
site's `.env`). The shared Caddy passes a request for `example.com` to
`example.com.ghost.internal`. Nothing else of the site is on that network:
not Ghost, not MySQL.
- A name no site has is never passed anywhere: `.ghost.internal` resolves on
that network only. The shared Caddy obtains no certificate for such a name,
so a request for it fails at TLS. A name whose site is down, with its
certificate already obtained, is answered `502`.

So installing, changing or removing a site writes nothing in the shared
Caddy's directory and never reloads or restarts it. After editing a site's
routes, reload that site's Caddy, in the site's directory:

```bash
docker compose exec caddy-internal caddy reload --config /etc/caddy/Caddyfile
```

`docker compose down`, in a site's directory, takes that site away; no other
site is touched. `./ghost-docker check` in a site's directory reports the
site's own Caddy, the shared Caddy's health, and HTTPS through both.
`./ghost-docker list` shows the shared Caddy as `infra`, and each site behind
it as `shared-caddy`.

`install` writes `caddy/global/shared-caddy.caddy` into a site behind the
shared Caddy. It tells the site's Caddy to trust the shared one, so Ghost
learns the visitor used HTTPS; without it Ghost redirects to HTTPS for ever.

Ghost is still published on the site's loopback port, so a site behind the
shared Caddy can be reached without it.

Because each site carries its own Caddy, snippets and routes, sites on
different releases can route differently; a release that changes a snippet
changes it for the sites updated to it, and no others.

### Certificates

The shared Caddy obtains a site's certificate when its domain is first asked
for, not when the site is installed: the first request waits a few seconds
for it. It obtains one only for a name a site's Caddy answers to on
`ghost-ingress`, so a stranger pointing a domain at the server gets none.

The ACME account is the shared Caddy's, for every site: `install --infra
--email` writes it to `caddy/global/acme.caddy` in its directory, and other
global options (a DNS provider, an internal CA) go beside it. A site's own
`install --email` is refused on a server with the shared Caddy, and its
routes, served over plain HTTP, take no `tls` directive.

### More hostnames for a site

A site's Caddy is reached only by the names it has on `ghost-ingress`. To
serve a site under another hostname, add it to the site's routes and give
the site's Caddy the name, in the site's `compose.override.yml`:

```yaml
services:
caddy-internal:
networks:
ingress:
aliases:
- www.example.com.ghost.internal
```

Then `docker compose up -d` in the site's directory.

Sites of your own that are not Ghost sites go in the shared Caddy's
`caddy/custom/`, as for a single site; a name with a block there is served by
that block and never passed on.

### What it trusts

The shared network is not isolation between sites' Caddies: every container
on it can reach every site's Caddy, and so every site as a visitor would.
Ghost, MySQL, ActivityPub and analytics are never on it. Run sites behind one
Caddy only when you would trust them on one server anyway, as with Ghost-CLI.

The shared Caddy's `caddy_data` volume holds every site's certificates.

Two sites cannot share a domain. `install` and `restore` refuse a domain
another site's Caddy has, running or stopped, before they change anything.
A site taken down with `docker compose down` holds no name until it is up
again, so another site can be installed on its domain meanwhile. Whenever a
site is verified (after an install, a restore or an update, and by `check`),
a domain another site also holds is an error named `ingress`, and an
install that finds one removes what it created. So two installs started at
once for one domain are never both left serving it: an install that
succeeded is still on the network when the other is verified. Which of the
two is removed is not decided by which started first, and both can be. An
install with `--no-start` starts and verifies nothing, so this holds for it
only from its first `check`. A name added in `compose.override.yml` is
checked like the site's own.

### Restarting and updating it

Restarting the shared Caddy (`docker compose restart`, or `down` then
`up -d`, in its directory) interrupts every site behind it for those seconds,
and brings each back; certificates are kept in its `caddy_data` volume. A
site's own operations (`update`, `self-update`, `backup`, `restore`,
`docker compose down`) never restart it.

Its Caddy image is pinned in its `compose.yml`, by the release it runs.
`./ghost-docker self-update`, in its directory, moves it to a newer release as
for a site: untouched stack files are replaced, edited ones kept beside the
release's `.new`, and the launcher re-pinned; then Caddy is recreated, which
restarts it as above, reloads its configuration (so a changed Caddyfile is
loaded even when the container was not recreated), and must pass its health
check. There is no backup, because it holds no data. The release's images are
pulled before any file is written, so one that cannot be pulled changes
nothing. A failed update puts its files back, and starts the previous Caddy
again when it had been recreated. It never updates the sites behind it, and
their own `self-update` never touches it; each site's own Caddy is updated
with the site.

### What to keep a copy of

`./ghost-docker backup` is a site's command, and the shared Caddy's directory
has none: it holds no site's data, and `install --infra` sets it up again.
Two things in it are yours, and are not written again:

- `caddy/global/*.caddy`: the ACME account, and any other global options,
such as a DNS provider, whose file may hold an API token.
- `caddy/custom/*.caddy`: sites of your own that are not Ghost sites.

Keep a copy of those if you have edited them, and of `compose.override.yml`
if you wrote one. The certificates, in the `caddy_data` volume, need no copy:
Caddy obtains each again when its domain is next asked for. On a server with
many sites, that is many certificates at once, which Let's Encrypt's limits
can slow down; Caddy retries until it has them.

### Capacity

Each site's own Caddy uses little memory (about 15 MB idle), and the shared
one little more. What limits a server is each site's own Ghost and MySQL, and
ActivityPub and analytics where selected, which cost what they would on a
server of their own ([configuration.md](configuration.md#site-modes-and-profiles)
lists the optional services' costs). Size the server for the sum of them.
Let's Encrypt limits how many certificates one account obtains per hour;
many new sites first visited at once can reach it, and Caddy retries later.
Loading
Loading