You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 49cb340
Browse filesBrowse the repository at this point in the historyBrowse files
feat(service): support custom domains on preview branches (#354)
## Purpose of change
Let users manage custom domains on preview and staging branches through
`service domain --branch <name>`.
## What's changed and why
- Remove the production-only guard shared by add, show, retry, wait, and
delete. Domain commands still default to production when `--branch` is
omitted.
- Keep service selection, domain lookup, and recovery actions scoped to
the selected branch app. Recovery commands include the resolved project
and service IDs plus the quoted branch name. Invalid-hostname and
invalid-timeout recovery also preserve a supplied branch before target
selection.
- Update help, deployment-required advice, and product docs. Remove the
retired `SERVICE.BRANCH_NOT_DEPLOYABLE` error.
- Cover feature and staging registration and the other four domain
commands with branch app and domain IDs.
- Use the API recovery hint for custom-domain quota errors. The
workspace hourly limit tells users to wait; deleting a domain does not
restore that budget. Inventory quota errors without a hint keep the
existing deletion guidance.
- Use one private recovery-command formatter across the error paths so
project, service, and branch selectors cannot drift. Regression tests
cover missing deployments and DNS failures on a branch name that needs
shell quoting.
Companion changes: [Console and domain
support](prisma/pdp-control-plane#5746) and
[public docs](prisma/web#8514). The REST API
already accepts branch apps; the Console restriction is removed by the
platform PR. Publish the docs after the platform change is deployed and
this CLI change is released.
<!-- cli-domain-terminal-examples:start -->
## Terminal examples
Captured from this PR's current head
(`54b4ea48389004d000508070c0ca1c05a1f57d43`) with the in-process CLI
harness and synthetic API responses. ANSI colors are removed. These are
actual CLI-rendered examples, not live DNS or certificate tests. The
successful fixture assumes the required DNS records already exist.
TXT/Cloudflare-specific CLI guidance is a separate change in
[#370](#370).
### Add and wait on staging
`--branch` selects the app for each invocation. Keep the same selectors
on follow-up commands; omitting `--branch` still defaults to production.
```console
$ prisma service domain add staging.example.com --project acme-app --service hello-world --branch staging
✔ Added staging.example.com to hello-world.
workspace: Acme Inc
project: acme-app
branch: staging
service: hello-world
hostname: staging.example.com
status: provisioning_tls
dns CNAME: staging.example.com -> switchboard.ewr.prisma.build (ttl 300)
→ Wait for activation: prisma service domain wait staging.example.com
→ Show the domain: prisma service domain show staging.example.com
$ prisma service domain wait staging.example.com --project acme-app --service hello-world --branch staging
staging.example.com: active
✔ staging.example.com is live at https://staging.example.com
workspace: Acme Inc
project: acme-app
branch: staging
service: hello-world
hostname: staging.example.com
status: active
```
Both commands exit with status `0`. The `branch: staging` row confirms
the selected branch.
### DNS recovery keeps the selected branch
A branch name with spaces is quoted in the recovery command. The command
also carries the resolved project and service IDs, so retrying targets
the same app.
```console
$ prisma service domain add staging.example.com --project acme-app --service hello-world --branch 'feature/domain fix'
✘ [SERVICE.DOMAIN_DNS_NOT_CONFIGURED] DNS is not configured for "staging.example.com"
why: Create a CNAME to switchboard.ewr.prisma.build first.
→ Add CNAME staging.example.com -> switchboard.ewr.prisma.build at your DNS provider, then rerun the domain command.
→ Add the domain: prisma service domain add staging.example.com --service svc_staging --project proj_1 --branch 'feature/domain fix'
```
Exit status: `2`.
### The hourly budget gives wait guidance
The API's recovery hint tells users to wait. Deleting an existing domain
does not restore the hourly creation budget.
```console
$ prisma service domain add staging.example.com --project acme-app --service hello-world --branch staging
✘ [SERVICE.DOMAIN_QUOTA_EXCEEDED] Custom domain quota exceeded
why: Failed to add custom domain: This workspace can create 10 custom domains per hour. Try again in 60 minutes. Wait before adding another custom domain to this workspace.
→ Wait before adding another custom domain to this workspace.
```
Exit status: `2`.
<!-- cli-domain-terminal-examples:end -->
## Testing notes / Before-after
Before: any domain command with a preview branch failed before calling
the API. After: `prisma service domain add staging.example.com --service
web --branch staging` targets that branch's app.
Passed:
- Full CLI package suite: 1,048 passed, one existing skipped test.
- Root `pnpm typecheck` (nine tasks), `pnpm format`, `pnpm lint`, and
`pnpm check:error-reference`.
- Local end-to-end tests: seven passed. The 48 live API tests were
skipped because their service token is not configured.
Root `pnpm test` and a serial retry stop at the unchanged CLI-engine
test “consent with a token: a wrong answer re-prompts instead of
failing” after its five-second timeout. That test also fails in
isolation, without loading the changed CLI command code. The full
changed CLI package suite passes separately.
API calls are exercised through the in-process CLI test harness. Live
DNS and TLS issuance were not exercised.
Copy file name to clipboardExpand all lines: docs/product/error-conventions.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -201,4 +201,12 @@ If a production action is blocked or fails, the output should make clear whether
201
201
202
202
Every error should help the user recover without opening another document first.
203
203
204
+
Custom-domain input errors preserve an explicitly supplied `--branch` in recovery
205
+
commands, even when validation fails before the service is selected. Recovery must
206
+
not silently switch a preview or staging request to production.
207
+
208
+
Custom-domain quota errors use the API's recovery hint when supplied. An hourly
209
+
creation limit requires waiting; deleting a domain does not restore that budget.
210
+
Without an API hint, the CLI keeps its advice to free an existing domain slot.
211
+
204
212
If a condition is expected and actionable, document it as a structured failure. If it is a bug, do not hide it behind a fake user-facing success envelope.
Copy file name to clipboardExpand all lines: docs/reference/error-reference.md
+19-6Lines changed: 19 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -473,10 +473,6 @@ A `project` or `branch` group command was invoked with unusable arguments — fo
473
473
474
474
A `--branch` flag was passed with an empty or whitespace-only value to a service command; the check runs before any resolution because a blank value must never fall through to the default-branch behavior of omitting the flag. The fix is to pass a non-empty branch name, or omit `--branch` to target the default branch. Meta: none.
475
475
476
-
### SERVICE.BRANCH_NOT_DEPLOYABLE
477
-
478
-
A `service domain` command was pointed at a non-production branch, which the domain-target resolver refuses because custom domains on preview branches are not supported in Public Beta. The fix is to use `--branch production`, or attach the domain after promoting to the production branch. Meta: none.
479
-
480
476
### SERVICE.DELETE_FAILED
481
477
482
478
`service delete` called the platform's app-teardown API and it rejected; the underlying error's message becomes `why` and the original error is carried in `cause`. Next actions point at `service show` and `service version list` for the service. Meta: none.
@@ -497,13 +493,30 @@ The general "Management API call failed" wrapper for the `service` command famil
497
493
498
494
The hostname given to a `service domain` command is not a usable custom domain — raised either by local validation before any API call (protocol, path, port, wildcard, single label, or bad DNS labels) or when `service domain add` gets a plain HTTP 400 rejection from the domain API. The fix is to pass a bare hostname such as `shop.acme.com`. Meta: `status`, `apiCode`, `hint` (API-rejection path only; none for local validation).
499
495
496
+
### SERVICE.DOMAIN_OWNERSHIP_REQUIRED
497
+
498
+
The API could not find the TXT record proving that this workspace may attach the
499
+
hostname. Add the exact name and value in the API hint, keep the TXT record for
500
+
future attachments in this workspace, and rerun the suggested command. Recovery
501
+
preserves the selected service, project, and branch. This does not mean that the
502
+
service needs another deployment. Meta: `status`, `apiCode`, `hint`.
503
+
504
+
### SERVICE.DOMAIN_CLOUDFLARE_PROXY
505
+
506
+
The API found Cloudflare proxy addresses while the hostname's routing check
507
+
failed. Set that DNS record to DNS only (gray cloud) and rerun the suggested
508
+
command. After the domain is Active, Proxied can be enabled again with Full
509
+
(strict) SSL/TLS. Keep `/.well-known/acme-challenge/*` accessible without caching
510
+
or security challenges so Prisma can renew the certificate. Meta: `status`,
511
+
`apiCode`, `hint`.
512
+
500
513
### SERVICE.DOMAIN_NOT_FOUND
501
514
502
515
A `service domain` command targeted a hostname that is not attached to the resolved service — raised when the service's domain listing has no matching hostname, or when a show/delete/retry/wait call gets HTTP 404. The fix is to check the hostname and service, or add the domain first. Meta: none.
503
516
504
517
### SERVICE.DOMAIN_QUOTA_EXCEEDED
505
518
506
-
`service domain add` was refused because the custom-domain quota is reached — HTTP 429, or a 409 whose text mentions a quota, maximum, or limit. The fix is to delete an existing custom domain before adding another. Meta: `status`, `apiCode`, `hint`.
519
+
`service domain add` was refused because the custom-domain quota is reached — HTTP 429, or a 409 whose text mentions a quota, maximum, or limit. The CLI uses the API's recovery hint when supplied, including waiting for an hourly creation budget. Without a hint, it advises deleting an existing custom domain before adding another. Meta: `status`, `apiCode`, `hint`.
507
520
508
521
### SERVICE.DOMAIN_RETRY_NOT_ELIGIBLE
509
522
@@ -551,7 +564,7 @@ A `service logs` response body ended without the terminal record that closes a p
551
564
552
565
### SERVICE.NO_VERSIONS
553
566
554
-
The resolved service has no usable version for the command — raised by `service open` when the service has no versions, by `service logs` when it has no live version, and by `service domain add` when the API answers 422 because the production service has no promoted version that can receive a custom domain. The fix on the domain path is to promote a version on the production branch first, then add the domain again. Meta: `status`, `apiCode`, `hint` (domain-add path only; otherwise none).
567
+
The resolved service has no usable version for the command — raised by `service open` when the service has no versions, by `service logs` when it has no live version, and by `service domain add` when the API answers 422 because the selected service has no promoted version that can receive a custom domain. The fix on the domain path is to promote a version on the selected branch first, then add the domain again. Meta: `status`, `apiCode`, `hint` (domain-add path only; otherwise none).
"Manage custom domains for a service. Register hostnames, drive DNS and TLS verification, inspect status",
296
296
description:
297
-
"Custom domains point hostnames you own at a service's production branch. After add, create the DNS record the platform reports; wait and retry drive DNS verification and TLS provisioning to done.",
297
+
"Custom domains point hostnames you own at a service on any branch. Commands default to production; use --branch to select another branch. After add, create the DNS record the platform reports; wait and retry drive DNS verification and TLS provisioning to done.",
summary: "Register a custom domain on the service's production branch",
15
+
summary: "Register a custom domain on the selected service branch",
16
16
description:
17
-
"Points a hostname you own at the service instead of its generated URL. After registering, create the DNS record the platform asks for, then 'service domain wait' blocks until verification and TLS provisioning finish.",
"Points a hostname you own at the service instead of its generated URL. Add the routing CNAME and workspace TXT record shown by Console or the verification error, then rerun this command. Keep the TXT record for future attachments in this workspace. Use 'service domain wait' to wait for TLS provisioning.",
// biome-ignore lint/performance/noAwaitInLoops: this polls one domain until it settles, reporting each status change in the order it happened; the sleep between reads keeps the management API request rate down.
0 commit comments