5b. Route a whole subtree at one profile
An app that dispatches on subdomain — a tenant per host, a branch per host — wants every name under its surface, not one router per tenant. Declare it per profile:
compose: file: docker-compose.preview.yml profiles: [backend, frontend] subdomains: [backend]validate shows what that resolved to:
$ PR=123 pstack validatestack: pr-123✓ spec parses — kind: isolated, 1 axis/axes, stack "pr-123" compose: docker-compose.preview.yml [backend, frontend] subdomains: *.backend-pr-123.preview.example.com → backend (one label) router generated; ${PSTACK_WILD_BACKEND} is for a service with its own traefik labels TLS: DNS-01 hosts order one certificate per deployment; other modes serve none - db: up, assert_goneCheck that hostname. pstack derived it from the profile, the stack and PREVIEW_DOMAIN, so a wrong
domain here is a router that parses, deploys, and never matches anything. (DOMAIN is accepted as a
legacy alias; a name declared in the spec beats either one picked up from the ambient environment.)
An entry attaches to the service whose routing name (pstack.routing.service_name, else the service
name) equals it. For a service routed by pstack.routing.* labels, pstack writes the wildcard router
itself: <name>-<stack>-wild, same service, priority 2, so the exact host still wins on rule length.
An entry that attaches to nothing is a note: in validate and in the deploy log.
A service with its own traefik.* labels writes its own router and spends the rule pstack hands it
in an environment variable:
backend: profiles: [backend] labels: - traefik.enable=true - traefik.http.routers.backend.rule=Host(`backend-${STACK}.${PREVIEW_DOMAIN}`) - traefik.http.routers.backend.tls=true - traefik.http.routers.backend-wild.rule=${PSTACK_WILD_BACKEND} - traefik.http.routers.backend-wild.priority=2 - traefik.http.routers.backend-wild.service=backend - traefik.http.routers.backend-wild.tls=true - traefik.http.services.backend.loadbalancer.server.port=3000No $$ escaping: compose interpolates the file from its environment and does not re-scan what it
substituted, so the rule’s backticks and its $ anchor reach Traefik intact. The variable is exported
on every compose subcommand, not just up: on down an unset variable would substitute empty
and compose would be reasoning about a differently-labelled project than the one it created.
A host: that is a domain this host serves (the preview domain or an added one), a parent of one, or
a control hostname is refused, even when no service uses pstack.routing.* labels: a priority-2
wildcard there would take that domain’s traffic.
DNS, TLS and wake
Section titled “DNS, TLS and wake”subdomains: [backend] defaults to one label: api.backend-pr-123.… yes, a.b.backend-pr-123.…
no.
-
DNS: nothing to add. The
*.<domain>record the host already has answers deeper names too (RFC 4592). One caveat: while Let’s Encrypt validates the subtree’s certificate, lego’s_acme-challenge.backend-pr-123.<domain>TXT record makes that name exist, so it and its subtree stop resolving through*.<domain>. Resolvers cache the miss for the zone’s negative TTL. This happens at first issue and at renewal, about every 60 days. -
TLS: the host’s
*.<domain>certificate covers one label, so the subtree needs its own:Mode The -wildrouterDeploy log note dns01orders backend-pr-123.<domain>+*.backend-pr-123.<domain>: one certificate per deployment, against Let’s Encrypt’s ~50 per registered domain per week (control-plane.md)none http01tls=true, no certificate (HTTP-01 cannot issue wildcards); the deploy still succeedsbackend: *.backend-pr-123.<domain> has no certificate on an http01 host (wildcards need DNS-01)unknown tls=true, no certificate; the deploy still succeedsbackend: *.backend-pr-123.<domain> has no certificate on a host whose certificate mode is unknowndns-persist-01tls=true; served by name if the stored pair’s SANs cover*.backend-pr-123.<domain>backend: *.backend-pr-123.<domain> is served only if the stored wildcard covers itDeployments made before this pick up their certificate on the next
uporPOST /api/tls/redeploy. -
Wake: the wake catch-all matches any depth under the domain, so a request to a sleeping stack’s subtree wakes it.
{ backend: any } matches any depth. Traefik routes it, and no certificate can cover more than one
label: on dns01 the *.backend-pr-123.<domain> pin still applies, and the log notes that deeper
names get none. Use it where plain HTTP is fine for the deeper names.
Turning a subtree on without editing the spec
Section titled “Turning a subtree on without editing the spec”A deployment’s Subdomains list in either UI (or
PUT /api/deployments/{id}/subdomains { service, depth }, depth one, any or null) sets the same
wildcard for one service with a generated host, stored on this host rather than in the spec, so a CI
redeploy from the repo’s spec keeps it. It applies on the next deploy. The spec wins: a service its
compose.subdomains names shows Set in spec and answers 409; null always clears a row.
GET /api/deployments/{id}/subdomains lists the candidates, each { service, host, subdomains, from }
(from: spec, host or null), plus any row whose service lost its generated host, so it can be
cleared. The deployment’s own compose.subdomains stays the spec’s. Forgetting the deployment drops
its rows.