Deployment Service
Durable deployment workflow orchestration
Deployment Service
The DeploymentService orchestrates the complete deployment lifecycle, from building containers to assigning domains.
Location: go/apps/ctrl/workflows/deploy/
Proto: go/proto/hydra/v1/deployment.proto
Key: project_id
Operations
Deploy
flowchart TD
Start([Deploy Request]) --> FetchMeta[Fetch Metadata]
FetchMeta --> StatusBuilding[Status: Building]
StatusBuilding --> CreateKrane[Create in Krane]
CreateKrane --> PollStatus{Poll Until Ready}
PollStatus --> UpsertVMs[Upsert VM Records]
UpsertVMs --> PollStatus
PollStatus --> ScrapeAPI[Scrape OpenAPI Spec]
ScrapeAPI --> BuildRoutes[Build Ingress Routes]
BuildRoutes --> AssignRoutes[Call RoutingService]
AssignRoutes --> StatusReady[Status: Ready]
StatusReady --> UpdateLive[Update Live Deployment]
UpdateLive --> End([Complete])
style AssignRoutes fill:#e1f5fe
style StatusReady fill:#c8e6c9
Creates a new deployment:
- Fetch deployment, workspace, project, environment metadata
- Create deployment in Krane
- Poll until instances are running
- Scrape OpenAPI spec
- Call RoutingService to assign ingress routes atomically
- Update project's live deployment ID
Implementation: go/apps/ctrl/workflows/deploy/deploy_handler.go
Rollback
flowchart TD
Start([Rollback Request]) --> Validate[Validate Deployments]
Validate --> CheckVMs[Check Target VMs]
CheckVMs --> FindRoutes[Find Sticky Ingress Routes]
FindRoutes --> UpdateRoutes[Update Route Deployment IDs]
UpdateRoutes --> UpdateProject[Update Live Deployment]
UpdateProject --> End([Success])
style UpdateRoutes fill:#e1f5fe
style UpdateProject fill:#c8e6c9
Rolls back to a previous deployment:
- Validate source/target deployments
- Find sticky ingress routes (live + environment level)
- Update ingress routes to point to target deployment
- Update project metadata
Implementation: go/apps/ctrl/workflows/deploy/rollback_handler.go
Promote
flowchart TD
Start([Promote Request]) --> Validate[Validate Deployment]
Validate --> FindRoutes[Find All Ingress Routes]
FindRoutes --> UpdateRoutes[Update Route Deployment IDs]
UpdateRoutes --> UpdateProject[Update Live Deployment]
UpdateProject --> End([Success])
style UpdateRoutes fill:#e1f5fe
Promotes a deployment to live, removing rolled-back state:
- Validate deployment is ready
- Find all project ingress routes
- Update ingress routes to point to new deployment
- Clear rolled_back flag
Implementation: go/apps/ctrl/workflows/deploy/promote_handler.go
Why RoutingService?
All ingress route operations are delegated to RoutingService to:
- Ensure atomic updates to routing configuration
- Serialize ingress route operations per project
- Provide rollback capabilities for failed routing changes