Deployment orchestration
Deployment orchestration turns a release request into a controlled change to a project environment. It joins durable deployment records with planned jobs, source and image work, runtime providers, node placement, readiness checks, route activation, and recovery. See Deployment lifecycle for the wider release model, Projects and environments for configuration ownership, Domains and networking for public routes, and Project groups and templates for shared defaults.
Orchestration model
The system keeps the release record, its executable work, and the environment's selected release as separate concerns. A deployment records one release attempt. Jobs perform the work. The environment changes to the new release only after the candidate is ready and the route and worker state checks pass.
This diagram shows the main path from a release request to a public deployment.
flowchart LR
A[Release request] --> B[Deployment record]
B --> C[Planned job workflow]
C --> D[Source or image input]
D --> E[Build or artifact selection]
E --> F[Node delivery and startup]
F --> G[Readiness checks]
G --> H[Route and worker confirmation]
H --> I[Environment promotion]
I --> J[Optional evidence and reconciliation]
I --> K[Older resource cleanup]
Deployment records
Release identity
The deployment record is the durable identity of one release attempt. It links the attempt to a project and environment and keeps the state needed for status views, route selection, container records, recovery, and cleanup. A running candidate remains separate from the environment's public deployment until completion promotes it.
References: crates/…/deploy_compose.rs• L503-587 crates/…/mark_deployment_complete.rs• L677-708
Generation ordering
The job processor serializes deployment generation changes for one environment. A newer manual, webhook, or recovery request can supersede older work without allowing that work to become current later. Durable requests can be replayed after a restart, while duplicate or already superseded recovery work is skipped.
References: crates/…/job_processor.rs• L221-464 crates/…/job_processor.rs• L940-991
Workflow admission
Workflow admission is the point where a pending deployment is allowed to run. Deployment gates can block or allow this transition, and a gate error blocks the release. Admission also checks that the project and environment still exist before execution begins.
References: crates/…/job_processor.rs• L603-657 crates/…/job_processor.rs• L1362-1502
Workflow stages
Source acquisition
Source acquisition creates the input for builds and source-only static releases. Private and public repositories use their configured access paths. A deployment can target a branch, tag, or fixed commit. Uploaded source enters the same later workflow after bounded and confined archive handling.
References: crates/…/download_repo.rs• L306-375 crates/…/prepare_source_bundle.rs• L112-310
Image build
The image build stage converts checked-out source into an artifact that later jobs can identify and deliver. The build uses an existing Dockerfile when present or a selected project preset when it is not. Workspace-aware projects can use the repository root so sibling packages and root lockfiles remain available to the build.
The build result records the image identity and enough placement data for later stages to select the right image. A multi-architecture build can produce one native image per target platform. Worker builds receive only approved non-secret values. Values that a framework must embed into the built application or that require package credentials keep the build on the control plane when possible, or fail with a clear reason.
References: crates/…/build_image.rs• L25-152 crates/…/build_image.rs• L542-575 crates/…/build_image.rs• L1383-1459 crates/…/workflow_execution_service.rs• L1281-1429
Build location selection
Build location selection aligns the build with the workload policy and the target node platforms. A control-plane profile selects a worker when local workloads are disabled. A requested worker build is a preference when the worker cannot produce a safe matching artifact, so the system can fall back to the control plane and record that choice instead of failing silently.
CI builds select eligible workers for their artifact targets and apply the same platform and secret rules. When several platforms are required, each selected worker builds its own platform and the later deploy stage uses the matching result.
References: crates/…/workflow_execution_service.rs• L1411-1559 crates/…/build_image.rs• L867-925
Image delivery
Image delivery makes the selected artifact available on the node that will run each replica. A worker-built image can stream from its recorded builder to a target node. Registry images are pulled by the target when possible, with a verified local copy as a fallback. Every reuse and transfer checks image identity rather than trusting a mutable tag.
The deployer chooses the tag that matches each target platform and refuses a known platform mismatch before startup. A replica placed on the control plane imports a worker-built image only when the control plane has a usable image store and the image identity matches the build result.
References: crates/…/deploy_image.rs• L49-195 crates/…/deploy_image.rs• L1897-2205
Replica placement
Replica placement chooses a local or worker node for each replica. It applies node targets and labels, platform support, node health, workload policy, and access rules. The selected node and the image tag used there stay attached to the replica so completion and cleanup can report the real runtime state.
The workflow performs an early check for an impossible dedicated-node selection before source work begins. The full placement decision still happens after the image exists because the image platform can narrow the available nodes.
References: crates/…/workflow_execution_service.rs• L985-1053 crates/…/deploy_image.rs• L286-310
Application readiness
Application readiness confirms that each started replica can serve the expected workload. The deployer resolves the routed port from explicit configuration, image data, or a fallback. When no port is configured, an existing runtime PORT value is aligned with the port that receives traffic.
Readiness can include an HTTP health check. A stopped or repeatedly restarting container fails the candidate with an operator-facing reason and bounded logs. Failed candidates are stopped and retained only when durable ownership records make diagnosis safe. Cancellation removes them instead of retaining them.
References: crates/…/deploy_image.rs• L431-455 crates/…/deploy_image.rs• L1800-1895 crates/…/deploy_image.rs• L2200-2319
Compose release
Compose deployment treats a multi-service stack as one release candidate. It resolves and checks the configuration, service exclusions, paths, variables, public service ports, and safe health paths before it changes the running stack. It prepares files, builds, and pulls images while the old stack remains live. Only then does it stop the old stack and start the prepared stack.
Compose secrets are materialized for the current attempt and mounted only for services that may read them. The candidate gets a unique secret generation, and obsolete generations are pruned after the old stack stops. Cancellation is checked at safe phase boundaries and compensates by tearing down the candidate. A failed stack is stopped and retained for authenticated inspection only when its ownership can be recorded safely.
Compose output records service names, image names, port bindings, and health information for the completion job. Excluded services are removed before preparation, and service-scoped secrets that no longer match a service are reported instead of being silently treated as delivered.
References: crates/…/deploy_compose.rs• L503-738 crates/…/deploy_compose.rs• L1023-1303 crates/…/deploy_compose.rs• L1305-1644 crates/…/deploy_compose.rs• L1697-1791
Pipeline contracts
Pipeline contracts keep job dependencies and typed outputs aligned across source, build, and deployment stages. The validation path checks that jobs are created in order, that missing upstream output fails the next stage, and that a complete workflow can pass repository and image data into deployment.
References: crates/…/pipeline_validation.rs• L294-389 crates/…/pipeline_validation.rs• L392-497 crates/…/pipeline_validation.rs• L500-641
Release evidence
Release evidence gives operators useful information after a candidate is live. The screenshot job resolves the public deployment URL, waits for the application to settle, validates and stores the image, then records its location on the deployment. The pipeline and on-demand capture paths share one per-deployment capture slot, so they cannot overwrite each other's result.
Screenshot capture has a hard time limit and remains separate from the required release barrier. A portless deployment skips the capture because it has no public URL.
References: crates/…/take_screenshot.rs• L21-114 crates/…/take_screenshot.rs• L235-303 crates/…/take_screenshot.rs• L324-444
Release completion
Release completion is the barrier between a ready candidate and a selected environment deployment. It first persists routing inputs, then changes the environment's selected deployment only when the candidate is still current. It waits for the route table and active workers to apply the new route and DNS generations when cluster DNS is enabled.
If route or worker confirmation fails, completion restores the last usable deployment and leaves the old runtime in place. A sleeping environment is woken only after the new route is ready, and the wake operation is checked again. A late rollback or superseding workflow cannot overwrite a newer state.
References: crates/…/mark_deployment_complete.rs• L136-250 crates/…/mark_deployment_complete.rs• L677-946 crates/…/mark_deployment_complete.rs• L948-1087
Provider coordination
Runtime service values
Managed providers supply runtime values that source and image builds cannot create. The planner combines those values with project and environment settings before the workload starts. Required provider data must resolve first, and a remote replica is blocked when a required service has no safe address reachable from its node.
References: crates/…/workflow_planner.rs• L439-474 crates/…/deploy_image.rs• L406-428
Repository configuration
Repository configuration extends a release without changing its main shape. The shared .temps.yaml contract can guide build behavior and later repository-declared support settings. The build stage reads it from the confined build context and reports an invalid file instead of ignoring it.
References: crates/…/build_image.rs• L1439-1459 crates/…/build_image.rs• L1461-1559
Post-deploy reconciliation
Post-deploy reconciliation applies optional repository settings after the completion barrier. Cron jobs, metric alerts, agents, and workflows can be updated after the release is live. Their failures remain visible in the timeline but do not undo an already selected deployment.
References: crates/…/workflow_execution_service.rs• L620-630 crates/…/workflow_execution_service.rs• L970-979
Supporting infrastructure
Workflow execution
Workflow execution loads durable job records and turns them into runnable jobs in execution order. It applies early placement checks, builds each job with the services required by its profile, tracks job state and logs, and checks database-backed cancellation while the workflow runs.
The executor keeps required release work separate from optional follow-up work. It also owns the cross-stage contracts for image tags, identities, platforms, builder nodes, and image configuration. Setup failures close planned job rows so a failed workflow does not leave its timeline stuck in pending. Anonymous deploy telemetry and optional security audit reporting do not become prerequisites for a release.
References: crates/…/workflow_execution_service.rs• L452-546 crates/…/workflow_execution_service.rs• L573-721 crates/…/workflow_execution_service.rs• L918-1081 crates/…/workflow_execution_service.rs• L1215-1559
Job processing
The job processor receives deployment requests from the queue and starts planning and execution. It acknowledges durable work only after processing settles. Restart reconciliation closes interrupted work and marks non-current deployments so replay can use generation and duplicate checks instead of repeating partial side effects.
References: crates/…/job_processor.rs• L154-176 crates/…/job_processor.rs• L710-991
Node health and failover
Node health tracking separates detection from recovery. A stale heartbeat marks a node offline and raises an operator alarm, but its workloads stay in place during the configured failover grace period. This avoids moving healthy workloads during a short network or control-plane outage.
When the grace period ends, failover retires replicas on the offline node. If healthy replicas remain elsewhere, the environment keeps serving. If all replicas were on the failed node, one fenced recovery deployment is queued for the environment. When the node returns, the system queues recovery work for replicas removed during failover. The work is bounded, idempotent, and retried until it is recorded or no longer needed.
References: crates/…/node_health_check.rs• L27-161 crates/…/node_health_check.rs• L508-697 crates/…/node_health_check.rs• L699-968
Cleanup ownership
Cleanup removes runtime resources only when durable records identify the exact resource and its owning node. Failed Compose candidates use the same rule before they are retained for diagnosis or removed. A cleanup retry keeps the record until deletion succeeds, so an interrupted operation does not make a live resource appear gone.
References: crates/…/deploy_compose.rs• L590-711 crates/…/workflow_execution_service.rs• L39-75
Change checklist
When these files or sections are changed, remember to consider these:
- Keep build outputs aligned with platform-specific tags, image identities, builder-node ownership, rollback reuse, image transfer, static extraction, and scans.
- Keep workspace build-root selection aligned with generated Dockerfiles, ignore rules, project directories, and sibling-package access.
- Keep worker build argument policy aligned with secret values, framework-inlined variables, package-manager credentials, CI dispatch, and control-plane fallback.
- Keep workflow job types, dependency IDs, typed outputs, required-for-completion flags, and executor construction cases aligned.
- Keep early placement checks aligned with the later platform-aware replica scheduler so a pre-build rejection does not disagree with deployment.
- Keep Compose configuration checks, service exclusions, route bindings, secret generations, cancellation compensation, and retained-candidate records in the same order.
- Keep
PORT, image-exposed ports, health paths, Compose public ports, route records, and completion outputs aligned. - Keep route promotion, route-table confirmation, worker route/DNS acknowledgements, sleeping-environment wake-up, rollback, and supersession checks aligned.
- Keep screenshot provider availability, timeout bounds, the shared capture guard, storage validation, and deployment-record updates aligned.
- Keep heartbeat watch restarts, offline alarms, failover grace periods, failover stamps, recovery redeploy fencing, and recovered-replica restoration aligned.
- Keep optional telemetry, audit, screenshot, and post-deploy work isolated from the required release-completion barrier.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A worker build lacks verified platform metadata | Deployment may select an image that cannot run on a target node | Worker builds must publish platform data before deployment. |
| A multi-platform build misses one required platform | Some target nodes have no compatible artifact | Required platform builds must complete before rollout. |
| A worker build needs a secret that a framework embeds into its output | The built application ships with a missing value or exposes a credential path | The build stays on the control plane when possible and otherwise fails with a remedy. |
| A worker-built tag changes before transfer or rollback | A node can run an image different from the release artifact | Source and target image identities are checked before and after transfer. |
| A Compose check or image preparation fails | The current stack can suffer avoidable downtime | Configuration checks and preparation happen before teardown. |
| Compose cancellation arrives after startup | The cancelled stack can remain live | Safe phase checks compensate with candidate teardown. |
| A Compose secret scope names a missing or renamed service | The service starts without the expected credential | Service scopes are resolved and unmatched scopes are logged. |
| A failed candidate has no durable ownership record | Cleanup or diagnosis can leak an unmanaged runtime resource | Retention requires recorded ownership; otherwise the candidate is removed. |
| Route or worker generation confirmation times out | The environment can report success while traffic still reaches an older backend | Completion rolls back to the last usable deployment. |
| A concurrent rollback changes a candidate to stopped during propagation | The old workflow can incorrectly mark itself completed | Completion rechecks state before finalization and aborts when superseded. |
| The control plane restarts while health checks are paused | Old heartbeat timestamps can trigger immediate mass failover | Heartbeat grace periods restart after a long health-check gap. |
| Failover work is queued but its stamp is not recorded | The next health tick can repeat the pass | Failover is idempotent and records the stamp only after all work is handled. |
| A screenshot provider hangs or an on-demand capture already holds the slot | The deployment workflow can stall or two captures can race | Capture has a hard timeout and one shared per-deployment slot. |
| Workflow assembly fails after job rows are planned | The deployment is terminal but its timeline remains pending | Setup failure cancels all planned pending rows through the job tracker. |
Key files
| File | Why to read it |
|---|---|
| crates/…/workflow_execution_service.rs | Shows how durable job records become workflows, how placement and build location are selected, and how required and optional work are separated. |
| crates/…/build_image.rs | Shows the source-to-image boundary, workspace context selection, worker secret policy, platform-aware outputs, and builder ownership. |
| crates/…/deploy_image.rs | Shows platform-aware image delivery, replica outputs, port alignment, readiness, and identity checks. |
| crates/…/deploy_compose.rs | Shows Compose validation, preparation, secret delivery, safe replacement, cancellation compensation, and retained failures. |
| crates/…/mark_deployment_complete.rs | Shows route promotion, route and worker confirmation, rollback, sleeping-environment wake-up, and final state selection. |
| crates/…/node_health_check.rs | Shows heartbeat detection, delayed failover, recovery redeploys, alarms, and replica restoration. |
| crates/…/take_screenshot.rs | Shows post-release evidence capture, provider bounds, storage recording, and capture de-duplication. |
| crates/…/pipeline_validation.rs | Shows the expected dependency chain and typed data flow between source, build, and deployment jobs. |
| crates/…/workflow_planner.rs | Shows how project and environment settings become deployment job records and completion barriers. |
| crates/…/job_processor.rs | Shows queue intake, generation ordering, admission, retry behavior, and restart recovery. |
| docs/deployment-lifecycle.md | Provides the parent view of deployment intent and lifecycle state. |
| docs/projects-and-environments.md | Explains where settings that shape orchestration are owned. |
| docs/project-groups-and-templates.md | Explains shared defaults that can shape planned deployment work. |
| docs/domains-and-networking.md | Explains how completion makes a deployment reachable. |