Test in development, then promote #
On this page
Prompt:
Add a development environment, so I can test before production.
Also works:
- "Let me try each version somewhere before my users see it."
- "The new version works. Put it live."
One call, tzcloud_create_environment, turns development on (Turn the development environment on). After that, each deploy goes to development first. Once you say yes, tzcloud_promote puts the tested version on production (Promote to production). If the app has only production, deploying puts the version live. There is no separate promote step.
How the hostnames are formed explains the application's label, the unique suffix added at creation, and both hostname forms.
What your AI does #
- Reads the
develop-then-promoteandreleaseskills (read_context, idsskill:develop-then-promoteandskill:release) and follows them. - Calls
tzcloud_create_environmentonce, when you ask for a development environment. - Before promoting, requests each route the change touched on the development hostname and checks
tzcloud_read_logsfor errors. - Once development is
deployed, promotes if you already asked for the promote; otherwise, asks you and waits for your yes. With no prior approval and nobody to ask, stops and reports. - Asks for no browser approval:
tzcloud_create_environmentandtzcloud_promoterun without one.
What you need #
- An application created as Deploy from your computer describes.
- Every application can have a development environment. It always sleeps when idle. Its awake time is billed separately at the Shared 0.5 GB rate by default. The owner can match production's size and pay that size's rate. Size and usage gives the limits and explains charges; the pricing page gives the current rates.
Before your AI starts #
For your AI: Check the following before starting.
- Your AI assistant connected and signed in (Connect your AI assistant).
- The application identifier, which
tzcloud_list_applicationsreturns.
Before the first development deploy, answer two questions.
- Who may open the development app? Anyone with the hostname can open a public app.
- Which outside services will the app call? Check that development uses test accounts and keys for any service that sends messages or changes data.
Steps #
You turn development on once. After that, you deploy each version to development and promote it to production.
Turn the development environment on #
A new application has only production, so a deploy goes straight there. Turn on development to test a hosted copy before promoting it to production. Check the manifest's audience before deploying. If it is public, anyone with the development address can reach the app. The hostname asks search engines to skip it. If production needs the previous version, use tzcloud_roll_back.
Your AI assistant calls tzcloud_create_environment with the application identifier and environment: "development". The work is done when the call returns, and it needs no browser approval.
{ "application": "<application id>", "environment": "development" }
The call returns created: true and the development hostname. If the application already has development, the call returns created: false. It then changes nothing, except to finish any step an earlier call left undone. The hosted development copy of your server needs its first deploy before it can serve application routes.
The response lists missing sign-in and push credentials. It also lists each missing secret named by a manifest setting. Store each one with tzcloud_store_secret, naming development. The platform refuses the deploy if a setting refers to a missing secret. Your app can deploy with sign-in or push providers still unavailable because their credentials are missing. Submit the manifest again after storing a sign-in credential so the realm receives it. Check the deploy to see both kinds of missing credential before deploying.
You can call it before or after tzcloud_submit_manifest: either order ends in the same state. tzcloud_submit_manifest creates development's credentials on every application. Where the manifest declares a database, it also creates development's database. This holds whichever call comes first. tzcloud_create_environment adds the hosted development copy and creates no database. Each call reports the application's state as it read it, so two calls run at once can describe two different moments, and both are true.
From then on:
- a deploy goes to development, at
<label>-dev.ai.host, andtzcloud_promotemoves a version to production, at<label>.ai.host, where<label>is the application's currentlabel(The development hostname); - where the manifest declares the accounts service, development has its own realm, which is its own list of end users, and local runs sign testers in there;
- the manifest's
realmmember andpushproviders apply to development as well as production; - development's schedules run from its first deploy;
- test end users can be created on development too. Turning development on removes none from production, and your AI assistant's session still creates them there (Test sign-in with test end users).
Local data that names production's users matches no one on development, because development's realm has its own users.
Deploy to development #
With development on, a deploy goes to development. Your AI assistant calls tzcloud_deploy_command and runs the command line it returns, as steps 3 to 5 of Deploy from your computer describe. If production already serves a version, it keeps serving it while development deploys.
Check development before promoting #
By default, development has its own CPU and memory limits. Memory use and timings measured there can differ from those on a larger production copy.
To test at production's CPU and memory limits, the app owner can set development_at_size to true through set_app_size. If the call reports applying, wait for the change through read_status, then check the recorded setting. A development pod stays in the development group. Matching lowers the pod's CPU limit from 1 vCPU to 0.25 vCPU on Shared 0.5 GB or 0.5 vCPU on Shared 1 GB. On Shared 0.5 GB, a development container keeps its default limits and the awake-time rate stays the same. Development still sleeps when idle, and its awake time is billed separately at the matched size's rate.
If you also need to test on production's placement type, create a separate test application at the intended size and deploy to its production environment. Its server is charged for awake time at that size's rate. See the pricing page for rates. A shared database remains charged while the server sleeps (Size and usage). After testing, turn production sleep on or delete the test application.
For your AI: Check the changed behavior before promoting. A successful server deploy confirms that the server starts and passes its health checks. A serverless deploy publishes the version without a server health check. Check the changed routes in either case.
If you can run commands, write or update a verification script in the project. Give it the base URL so the same checks can run locally and against development. Check the expected responses and saved data, and make a failed check end the script with a nonzero status. Build a public upload gallery includes a tested upload service with such a script. Local tests with test doubles check application logic without calling the platform; also check the deployed service.
Without a shell, use tzcloud_request_route for GET and tzcloud_write_route for POST, PUT, PATCH or DELETE. Set environment: "development" on either call. Check saved data with tzcloud_query_database where needed. For routes that require sign-in, use test_end_user as Test the signed-in paths describes. Read development's logs with tzcloud_read_logs and investigate errors before promoting. A failed tzcloud_request_route answer's detail gives the reads for that request: one tzcloud_read_logs read for matching entries, then the console source that fits the app. Use container for servers and pool for functions. A static site has no function console.
Test writes that cannot be undone. First, exercise the data rule locally with a disposable database. Then use development for the end-to-end check. Create synthetic records there, run the actual write, and read the result back. If the rule permits the write only once, repeat the request and confirm that it cannot change the record again.
Confirm that the app uses development's database and storage files, and that any outside service the route writes to uses a test account. If you need a deployed check and cannot use development, use a separate test application with its own data and service accounts.
Promoting deploys the tested version to production. It does not copy development's records into production. Check production with a read-only request. If you have no isolated target for a permanent write, report that the write remains untested.
On a server, list read-only GET routes in the manifest's smoke_paths to check them before a deploy or promote switches traffic. A promote requests them from the new production copy, with production's data and secrets. Promoting the version production already serves skips these checks. Serverless versions run no smoke checks. See Listing smoke paths.
If you asked only for a place to test, your AI assistant stops after verifying the change on development. It reports the development hostname, the version it tested and any checks still open. It promotes only when you ask to put the tested version live or approve that step.
Promote to production #
Once the development deploy is deployed and you agree to put it live or have already asked to promote it, your AI coding agent calls tzcloud_promote with the application identifier and wait_seconds.
The promote reuses the deployed code and reads production settings from the current manifest. Production uses its own secrets, users, database and files. Migrations can change production data before the switch, and their changes can remain if the promote fails. See What a promote does to production's database.
Use tzcloud_promote with the exact version you tested. Without version, the tool takes the version development is serving when you call it.
{ "application": "<application id>", "version": 41, "wait_seconds": 45 }
Pass wait_seconds as a whole number from 1 to 45. If the operation is still running when the call returns, follow the returned next call. Without wait_seconds, the promote returns at once with status 202 and state: "deploying". The response's environment is always production.
If the reply is lost or comes from outside the platform, its outcome is unknown. Read production with tzcloud_read_status. Match the version and start time to your request. If the status does not identify the attempt, check production's rows in tzcloud_list_versions. Promote again only where it shows no promote started for your request.
The chat deploy tool, tzcloud_deploy_files, does not take rotate_database_credential. To rotate from chat, turn on development if needed and deploy there. Then use tzcloud_promote with rotate_database_credential: true.
Besides wait_seconds, tzcloud_promote takes two optional members:
version, the number of a deployed row in the version history. If the call gives no version and development runs none, the call is refused 409nothing_to_promote. If the number identifies no successfully deployed version of this application, the platform returns 404no_such_version.- Set
rotate_database_credential: trueto rotate the production database password when promoting a server version or a serverless version with functions. For a serverless version without functions, the platform returns 403serverless_unsupportedbefore it records the promotion. Omitrotate_database_credentialto promote that version. Existing production code can lose the ability to open new database connections between the password change and the traffic switch. See What happens during a promote.
To choose an earlier version, look for promotable: true in tzcloud_list_versions. A promote cannot use a version whose published client files were deleted, even while its image or serverless deployment is still kept.
A promote builds nothing. For a server, it reuses the deploy's image and the runtime harness built into it, so production runs the same code as the deployed version. Only a new server deploy takes the current harness. For serverless, the promote reuses the version's files and any function tree without applying compute or running a health gate.
On an application with one environment, tzcloud_promote is refused 409 environment_not_created, since the deploy already reaches production.
What a promote does to production's database #
If the manifest declares a database and production has none, the first promote creates one for a server or serverless app. For a server, the platform creates no tables and runs no migrations. Your application's own migration walk does that. It applies your migration files to production's database when the new production container starts, before its server listens. It does the same in development. For a serverless application, the platform applies the migration files that version's deploy kept to production's own database before the promoted version serves (Serverless migrations). A promote takes no snapshot of the data first.
For a server, the new container runs any new migration as it starts, while the old version still serves. For serverless, the platform runs the migration before the promoted version serves. A failed promote does not undo the change. A later rollback moves the code back but leaves the data as the migration left it. Add a database says how to write a migration that the running version keeps working through.
What happens during a promote #
On Shared 0.5 GB, production usually runs as a pod on shared machines. The steps below are the same there. If tzcloud_read_status shows grain as pod, the app runs on shared machines. It follows the same steps to start a new copy, check its health, and switch traffic.
A serverless promote uses the version's stored files and applies any serverless migrations. A version with functions gets a new production platform credential. A static-only version gets no platform credential.
When a promote rotates a function version's database password, it writes that version's settings first. It changes the password just before switching traffic. Until the earlier version stops taking calls, its calls that open a new database connection are refused.
A server promote works in this order:
- It creates a new production platform credential and gives it to the new container. The current value keeps working until the switch.
- With
rotate_database_credential: true, it sets a new password on the production database role before the new container starts. - It starts the new version's production container next to the one serving now. The new container gets production's settings and credentials, including
TURNZERO_CLOUD_REALM_KEYSwhere production has a realm. - It polls the health path on the new container alone, until it returns 200 three times in a row, three seconds apart. A 503 or a connection error between them starts the count again, inside the check's 180 seconds. Then any smoke paths are requested, unless production already serves this version. Once both pass, it switches the production hostname to the new container. A first promote records
deployedat once. Where production already serves a version, the switch waits until the promote is 10 seconds old, anddeployedcomes 3 seconds after it, once every router has the switch. - It removes the previous container about 15 seconds after the switch. That is the routers' lookup interval for the serving container, 10 seconds by default, plus a 5-second grace period.
After a server's first promote records deployed, a request may still be answered not_deployed for up to about 2 seconds while the routers pick up the new container.
A failed promote ends failed and names the outcome. If it started a new server container, the platform removes that container and leaves the serving container and its credential in place. After a successful server promote, the previous container keeps its platform credential until the platform removes that container.
If you rotate a server's database password on promote, the previous container cannot open new database connections between the rotation and the switch. Its open connections keep working.
At the switch, production's schedules restart. A scheduled run still in progress on the previous container can fail. The schedule runs again at its next due time.
For a server app, the platform sets up production jobs from the chosen version's declarations after the switch. Check any job you changed after the promote. The app can start serving even if job setup fails.
With wait_seconds, the promote's response includes the outcome if the promote ends within the wait. If it ended deployed, the response also carries server_errors_since, which counts production's 5xx responses since the version began serving (Check the release). The count covers only routes requested since then, so request the others you rely on.
For a server, the platform checks smoke_paths before a deploy or a promote to a different version switches traffic. If the promote has not ended within the wait, use the response's next call, tzcloud_read_status with wait_seconds, or find the version's row in tzcloud_list_versions.
A promote interrupted by a platform restart before its switch ends failed with the outcome interrupted within about fifteen minutes. One interrupted after its switch ends deployed, because the new version is already running.
You can promote a server version that production already serves to apply its settings again and create a new production platform credential. Set rotate_database_credential: true if you also want a new password on the production database role.
A promote of the function version that production already serves fails at the settings step, with or without rotation. The production password stays as it was.
To refresh settings on a serving function version, restart it. To rotate the password or create a new production platform credential for functions, deploy a new version to development and promote it. A static-only promote creates no platform credential.
Expected result #
With development turned on, the deploy is served at <label>-dev.ai.host, and the promote adds a "promote" row for production to the version history.
- After
tzcloud_create_environment,tzcloud_read_statuslists development beside production, development asnever_deployeduntil its first deploy. - After the promote,
tzcloud_read_statusshows production'sdeploy.stateasdeployedand itsversionas the selected version.
Refusals #
See the refusals reference for other platform errors.
A promote can also meet the refusals it shares with a deploy, such as deploy_in_flight and setting_secret_missing. The Refusals section of Deploy from your computer lists them.
After development is turned on, tzcloud_create_environment can also be refused name_bound_to_setting, custody_entry_missing, custody_entry_unmovable, or realm_not_declared. This happens while it copies the manifest's sign-in or push settings to development. Development stays on. The refusal's detail says what happened to the setting, and whether to call tzcloud_create_environment again or submit the manifest. Author the manifest explains each.
| Refusal | Status | Cause | Remedy |
|---|---|---|---|
nothing_to_promote |
409 | tzcloud_promote gave no version, and the development environment runs none. |
Deploy to development first, or pass a deployed version. |
no_such_version |
404 | tzcloud_promote: the version is not a deployed row of the application, or its environment was deleted. |
Use tzcloud_list_versions to choose an eligible deployed version of this application with promotable: true. |
serverless_unsupported |
403 | The promote call requests database password rotation for a serverless version without functions. | Omit rotate_database_credential to promote the version. |
version_image_pruned |
409 | tzcloud_promote: the platform's retention cleanup has marked the version's build for deletion or already removed it. |
Choose a version tzcloud_list_versions marks promotable. Or deploy that version's artifact again as a new version, then promote it. |
version_client_pruned |
409 | The named version's client files were deleted while its image or serverless deployment is still kept. | Choose a version tzcloud_list_versions marks promotable, or deploy the earlier artifact again to development and promote the new version. |
environment_not_created |
409 | tzcloud_promote on an application with one environment, whose deploy already reaches production. |
Deploy instead, or turn development on with tzcloud_create_environment first. |
target_environment_halted |
409 | tzcloud_promote while production is halted. |
Call tzcloud_halt_environment on production with resume: true, then promote again. |
deletion_in_progress |
409 | tzcloud_promote while a deletion of the application or of either environment runs. |
Wait for the deletion to finish; read_approval_status shows whether it completed. If it failed, request the same deletion again to complete it. |
invalid_request |
400 | tzcloud_create_environment named production, which always exists. |
Name development, or leave environment out. |
Related #
- Deploy from your computer builds and deploys the version you promote.
- Manage versions and environments rolls production back, reads the version history, and deletes the development environment.
- Applications and environments describes the two environments.
- What happens without asking lists what the platform does on its own, such as halting an idle development environment.
- Add sign-in to your app describes the realm a development environment gets.
- tzcloud_promote and tzcloud_create_environment are the actions' generated reference entries.