Repository navigation
How it works
What happens between a build request and a published site, and the rules publish and publish-worker share.
flowchart LR
nextcloud[Nextcloud] -- "POST /static-sites" --> proxy[host proxy]
visitors[visitors] -- "GET /sites/" --> proxy
proxy -- "/" --> gateway["nginx-fpm-gateway (nginx)"]
gateway --> publish["publish (PHP-FPM)"]
publish --> rabbitmq[RabbitMQ]
rabbitmq --> worker["publish-worker × n"]
worker -- "content download, status callback" --> nextcloud
worker -- writes --> sites[("sites/")]
proxy -- "/sites/" --> sites
| Component | Runs as | Does |
|---|---|---|
| host proxy | nginx or any proxy on the host | Terminates TLS. Forwards / to nginx-fpm-gateway, serves the published sites at /sites/
|
nginx-fpm-gateway |
nginx container | Passes every request to PHP-FPM in publish over FastCGI |
publish |
PHP-FPM container | Checks the bearer token and the request, puts a BuildJob on q.builds, answers 202
|
| RabbitMQ |
rabbitmq:4 container |
Holds q.builds, and the delays exchange for the worker's retry |
publish-worker |
PHP CLI containers, PUBLISH_WORKER_REPLICAS of them, default 2 |
Takes one job at a time: downloads, renders, swaps the site into sites/, calls back |
POST /static-sites requires Authorization: Bearer <PUBLISH_API_TOKEN>. The scheme is case-sensitive,
and the token may contain A-Z a-z 0-9 - _ + ~ / . with optional trailing =; hex, base64 and
base64url all qualify.
- A firewall in
config/packages/security.yamlchecks the token. Its oneaccess_controlrule requiresROLE_APIfor every path, so a new endpoint is protected unless that file says otherwise. - The check runs on
kernel.request, before the controller: a malformed body without a token is a401. Routing runs earlier, so an unknown path is a404. -
/healthhassecurity: false, so a probe with a staleAuthorizationheader still gets200. -
/auth-verificationanswers200only with a valid token, so Collectives can test its URL and token before sending builds. A missing or wrong token is a401. - A blank
PUBLISH_API_TOKENanswers every request with401. An unset one cannot be resolved, so a request with a token gets a500. Either way nothing is enqueued.
publish checks every field of a build request; the
API reference lists the rules. publish-worker does not
check them again and uses static_site_id, slug and build_id as directory names, so publish
is the only check.
POST /static-sites/slug-available with {"data": {"slug": "..."}} answers
{"data": {"available": true}} when no stored site holds the slug, whatever that site's status, and
false otherwise. It stores and queues nothing, so a create can still answer 409 when another
site took the slug in between.
| Request | Operation | Fields under data
|
|---|---|---|
POST /static-sites |
create |
static_site_id, build_id, slug, title, content_download_url, callback_status_url, render_options
|
PATCH /static-sites/{id} |
update |
build_id, title, content_download_url, callback_status_url, optional render_options
|
DELETE /static-sites/{id} |
delete |
callback_status_url |
Collectives generates both ids, static_site_id and the build_id of every create and update, as UUIDv7.
StaticSiteController stores the site in static_site as pending with the request's
build_id, commits, then dispatches the build. A failed dispatch undoes the write: a create leaves
no entry, an update or delete leaves the entry as it was.
A create answers 409 when the static_site_id is already stored or another site holds the
slug. An update or delete answers 404 for an unknown id, and 409 while the site's last
operation is pending, unless it has been pending for longer than PENDING_TIMEOUT_SECONDS
(default 600). An update also answers 409 when its build_id does not sort after the stored
one, so a repeated or stale request changes nothing. An update keeps the site's slug.
A 202 has no body. Every 400, 404, 409 and 503 from these endpoints has the body
{"data": {"error_message": "..."}}.
StaticSiteController dispatches an App\Message\BuildJob through
Symfony Messenger.
config/packages/messenger.yaml routes it to the builds transport, which publishes it to the
default exchange with q.builds as the routing key. publish has no handler for it.
The body is JSON from Messenger's symfony_serializer; the class's property names are the keys:
{ "build_id": "...", "static_site_id": "...", "operation": "create", "slug": "...",
"callback_status_url": "...", "created_at": "...", "title": "...",
"content_download_url": "...", "render_options": null }A delete has build_id, title and content_download_url null, and keeps the site's stored build_id. Messenger adds a type header with the
class name and X-Message-Stamp-* headers.
render_options is any JSON value from the request, null when it is absent. publish and
publish-worker pass it on unchecked; ssg-library validates it and lists the
options.
publish-worker decodes the body into its own App\Message\BuildJob, found by the type header. Both
classes have the same namespace, name and properties, and operation is required, so they change
together; a message that does not decode is dropped without a callback.
The broker creates the publish user, q.builds and the delays exchange from
definitions.json when it starts. Neither service declares anything (auto_setup: false).
publish answers 202 only after the broker confirms the message.
publish-worker takes one message at a time: it downloads the archive, extracts it, renders the pages
with ssg-library, and swaps the site into
sites/<slug>/. Then it PATCHes the outcome to callback_status_url.
A delete builds nothing: publish-worker removes sites/<slug>/, then the entry, then reports
deleted.
| Outcome | What happens |
|---|---|
| Success | create and update: the site goes live, static_site.status becomes published, and published with the publish_url is reported. Delete: the site and its entry are gone, and deleted is reported |
| Transient failure | retried once after 15s through the delays exchange, then handled as a permanent failure |
| Permanent failure |
failed is reported. A create first removes its site and its entry; an update or delete keeps what is published and marks the entry failed
|
The callback body is {"status": "published", "data": {"publish_url": ...}},
{"status": "deleted", "data": {}} or {"status": "failed", "data": {"error_message": ...}}.
Nextcloud has to accept all three. Delivery is at-least-once, so Nextcloud must treat a repeated
status as one.
A failed create leaves nothing behind, so Collectives can POST the site again with a new
build_id. Only when publish-worker cannot reach the database does the entry stay; the next POST
then gets a 409 until an operator removes it.
build-pipeline.md in publish-worker describes the directories, the swap and the retries in detail.