Documentation
¶
Overview ¶
Package deploy defines the deployment and release domain entities, the deployment service interface, strategy abstraction, and persistence store for tracking deployments and immutable release snapshots.
Index ¶
Constants ¶
const ( ServiceStatePending = "pending" ServiceStateRunning = "running" ServiceStateSucceeded = "succeeded" ServiceStateFailed = "failed" )
Service-level progress states. Match the keys used in Deployment.ServiceProgress so callers can compare directly.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DeployListResult ¶
type DeployListResult struct {
Items []*Deployment `json:"items"`
NextCursor string `json:"next_cursor,omitempty"`
Total int `json:"total"`
}
DeployListResult holds a page of deployments with cursor-based pagination.
type DeployRequest ¶
type DeployRequest struct {
InstanceID id.ID `json:"instance_id" validate:"required"`
Services []provider.ServiceDeploySpec `json:"services" validate:"required,min=1"`
Strategy string `json:"strategy,omitempty"`
Notes string `json:"notes,omitempty"`
CommitSHA string `json:"commit_sha,omitempty"`
}
DeployRequest holds the parameters for initiating a deployment. Services lists only the services being changed; services not listed inherit their snapshot from the prior Release.
type DeployState ¶
type DeployState string
DeployState represents the lifecycle state of a deployment.
const ( // DeployPending indicates the deployment is queued. DeployPending DeployState = "pending" // DeployRunning indicates the deployment is in progress. DeployRunning DeployState = "running" // DeploySucceeded indicates the deployment completed successfully. DeploySucceeded DeployState = "succeeded" // DeployFailed indicates the deployment failed. DeployFailed DeployState = "failed" // DeployRolledBack indicates the deployment was rolled back. DeployRolledBack DeployState = "rolled_back" // DeployCancelled indicates the deployment was cancelled. DeployCancelled DeployState = "cancelled" )
type Deployment ¶
type Deployment struct {
ctrlplane.Entity
TenantID string `db:"tenant_id" json:"tenant_id"`
InstanceID id.ID `db:"instance_id" json:"instance_id"`
ReleaseID id.ID `db:"release_id" json:"release_id"`
State DeployState `db:"state" json:"state"`
Strategy string `db:"strategy" json:"strategy"`
Services []provider.ServiceDeploySpec `db:"services" json:"services"`
ServiceProgress map[string]string `db:"service_progress" json:"service_progress,omitempty"`
ProviderRef string `db:"provider_ref" json:"provider_ref,omitempty"`
StartedAt *time.Time `db:"started_at" json:"started_at,omitempty"`
FinishedAt *time.Time `db:"finished_at" json:"finished_at,omitempty"`
Error string `db:"error" json:"error,omitempty"`
Initiator string `db:"initiator" json:"initiator"`
}
Deployment tracks a single deploy operation for an instance.
Services is the per-service slice of the rollout — partial deploys list only the services being changed. ServiceProgress tracks each service's state independently so canary/rolling strategies can report which services have made it through.
type ListOptions ¶
type ListOptions struct {
Cursor string `json:"cursor,omitempty"`
Limit int `json:"limit,omitempty"`
}
ListOptions configures deployment or release listing with pagination.
type Release ¶
type Release struct {
ctrlplane.Entity
TenantID string `db:"tenant_id" json:"tenant_id"`
InstanceID id.ID `db:"instance_id" json:"instance_id"`
Version int `db:"version" json:"version"`
Services []provider.ServiceSnapshot `db:"services" json:"services"`
Notes string `db:"notes" json:"notes,omitempty"`
CommitSHA string `db:"commit_sha" json:"commit_sha,omitempty"`
Active bool `db:"active" json:"active"`
}
Release is an immutable snapshot of an application version.
Services holds a per-service snapshot at the moment of the deploy. Releases are always self-contained: a partial deploy that only touches service "api" still produces a Release whose other services' snapshots are inherited from the prior Release. Rollback always restores one Release to its full multi-service state.
type ReleaseListResult ¶
type ReleaseListResult struct {
Items []*Release `json:"items"`
NextCursor string `json:"next_cursor,omitempty"`
Total int `json:"total"`
}
ReleaseListResult holds a page of releases with cursor-based pagination.
type Service ¶
type Service interface {
// Deploy creates a new release and deploys it to the instance.
Deploy(ctx context.Context, req DeployRequest) (*Deployment, error)
// RecordInitial persists the v1 Release + a synthetic
// already-succeeded Deployment for a freshly-provisioned
// instance whose container/pod is already running.
//
// This closes the gap where workload.Create + spawnReplica
// produced a running instance without ever recording a Release
// — which left:
// - the dashboard's Deployments list empty after Create,
// - rollback with no v1 target,
// - partial deploys silently dropping un-listed services
// because there was no prior Release to inherit from.
//
// Idempotent: when a Release already exists for the instance,
// RecordInitial returns the existing first Release without
// inserting a duplicate. Safe to call from spawnReplica's
// adoption path (where the instance row may have been created
// by a prior workload create).
RecordInitial(ctx context.Context, instanceID id.ID) (*Release, error)
// Rollback reverts to a specific release.
Rollback(ctx context.Context, instanceID id.ID, releaseID id.ID) (*Deployment, error)
// Cancel aborts an in-progress deployment.
Cancel(ctx context.Context, deploymentID id.ID) error
// GetDeployment returns a specific deployment.
GetDeployment(ctx context.Context, deploymentID id.ID) (*Deployment, error)
// ListDeployments lists deployments for an instance.
ListDeployments(ctx context.Context, instanceID id.ID, opts ListOptions) (*DeployListResult, error)
// GetRelease returns a specific release.
GetRelease(ctx context.Context, releaseID id.ID) (*Release, error)
// ListReleases lists releases for an instance.
ListReleases(ctx context.Context, instanceID id.ID, opts ListOptions) (*ReleaseListResult, error)
}
Service manages deployments and releases for instances.
type Store ¶
type Store interface {
// InsertDeployment persists a new deployment.
InsertDeployment(ctx context.Context, d *Deployment) error
// GetDeployment retrieves a deployment by ID within a tenant.
GetDeployment(ctx context.Context, tenantID string, deployID id.ID) (*Deployment, error)
// UpdateDeployment persists changes to an existing deployment.
UpdateDeployment(ctx context.Context, d *Deployment) error
// ListDeployments returns a filtered, paginated list of deployments for an instance.
ListDeployments(ctx context.Context, tenantID string, instanceID id.ID, opts ListOptions) (*DeployListResult, error)
// InsertRelease persists a new release.
InsertRelease(ctx context.Context, r *Release) error
// GetRelease retrieves a release by ID within a tenant.
GetRelease(ctx context.Context, tenantID string, releaseID id.ID) (*Release, error)
// ListReleases returns a filtered, paginated list of releases for an instance.
ListReleases(ctx context.Context, tenantID string, instanceID id.ID, opts ListOptions) (*ReleaseListResult, error)
// NextReleaseVersion returns the next auto-incrementing version number for an instance.
NextReleaseVersion(ctx context.Context, tenantID string, instanceID id.ID) (int, error)
}
Store is the persistence interface for deployments and releases.
type Strategy ¶
type Strategy interface {
// Name returns the strategy identifier (e.g., "rolling", "blue-green").
Name() string
// Execute performs the deployment according to the strategy.
Execute(ctx context.Context, params StrategyParams) error
}
Strategy defines how a deployment is executed. Implementations handle the mechanics of rolling, blue-green, canary, etc.
type StrategyParams ¶
type StrategyParams struct {
Deployment *Deployment
Provider provider.Provider
OnProgress func(phase string, percent int, message string)
OnServiceProgress func(serviceName string, state string)
}
StrategyParams provides everything a strategy needs to execute a deployment.
OnServiceProgress (optional) is invoked when a strategy advances a single service's rollout state — e.g. canary moves service "api" from "pending" → "running" → "succeeded" without touching service "web". The deploy service uses these callbacks to update the Deployment.ServiceProgress map so dashboards and observers see per-service granularity. Strategies that don't have per-service granularity (rolling, recreate) update every service to the same state in lockstep.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package strategies provides built-in deployment strategy implementations.
|
Package strategies provides built-in deployment strategy implementations. |