deploy

package
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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

This section is empty.

Variables

This section is empty.

Functions

func NewService

func NewService(
	store Store,
	instStore instance.Store,
	providers *provider.Registry,
	events event.Bus,
	authProvider auth.Provider,
	vault secrets.Vault,
) *service

NewService creates a deploy service with the given dependencies.

Types

type ConfigFile added in v1.3.0

type ConfigFile struct {
	Name    string `db:"name"    json:"name"`    // e.g. "app-config"
	Path    string `db:"path"    json:"path"`    // mount path, e.g. "/etc/app/config.yaml"
	Format  string `db:"format"  json:"format"`  // "json", "yaml", "env", "text"
	Content string `db:"content" json:"content"` // file content (stored in vault at deploy time)
}

ConfigFile defines a configuration file (JSON/YAML/env/text) that is stored in the vault and mounted into the container at deploy time.

type CreateTemplateRequest added in v1.3.0

type CreateTemplateRequest struct {
	Name        string                    `json:"name"                   validate:"required"`
	Description string                    `json:"description,omitempty"`
	Image       string                    `json:"image"                  validate:"required"`
	Strategy    string                    `json:"strategy,omitempty"`
	Resources   provider.ResourceSpec     `json:"resources"`
	Ports       []provider.PortSpec       `json:"ports,omitempty"`
	Volumes     []provider.VolumeSpec     `json:"volumes,omitempty"`
	HealthCheck *provider.HealthCheckSpec `json:"health_check,omitempty"`
	Env         map[string]string         `json:"env,omitempty"`
	Secrets     []SecretRef               `json:"secrets,omitempty"`
	ConfigFiles []ConfigFile              `json:"config_files,omitempty"`
	Labels      map[string]string         `json:"labels,omitempty"`
	Annotations map[string]string         `json:"annotations,omitempty"`
	CommitSHA   string                    `json:"commit_sha,omitempty"`
	Notes       string                    `json:"notes,omitempty"`
}

CreateTemplateRequest holds the parameters for creating a deployment template.

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"`
	Image       string            `json:"image"                  validate:"required"`
	Env         map[string]string `json:"env,omitempty"`
	Strategy    string            `json:"strategy,omitempty"`
	Notes       string            `json:"notes,omitempty"`
	CommitSHA   string            `json:"commit_sha,omitempty"`
	ConfigFiles []ConfigFile      `json:"config_files,omitempty"` // Vault-powered config files from template.
	Secrets     []SecretRef       `json:"secrets,omitempty"`      // Secret references from template.
}

DeployRequest holds the parameters for initiating a deployment.

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"`
	Image       string            `db:"image"        json:"image"`
	Env         map[string]string `db:"env"          json:"env,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.

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"`
	Image      string            `db:"image"       json:"image"`
	Env        map[string]string `db:"env"         json:"env,omitempty"`
	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.

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 SecretRef added in v1.3.0

type SecretRef struct {
	Key  string             `db:"key"  json:"key"`
	Type secrets.SecretType `db:"type" json:"type"`
}

SecretRef is a lightweight reference to a secret needed at deploy time.

type Service

type Service interface {
	// Deploy creates a new release and deploys it to the instance.
	Deploy(ctx context.Context, req DeployRequest) (*Deployment, 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)

	// CreateTemplate creates a new reusable deployment template.
	CreateTemplate(ctx context.Context, req CreateTemplateRequest) (*Template, error)

	// GetTemplate returns a specific deployment template.
	GetTemplate(ctx context.Context, templateID id.ID) (*Template, error)

	// UpdateTemplate updates an existing deployment template.
	UpdateTemplate(ctx context.Context, templateID id.ID, req UpdateTemplateRequest) (*Template, error)

	// DeleteTemplate removes a deployment template.
	DeleteTemplate(ctx context.Context, templateID id.ID) error

	// ListTemplates lists deployment templates for the current tenant.
	ListTemplates(ctx context.Context, opts ListOptions) (*TemplateListResult, 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)

	// InsertTemplate persists a new deployment template.
	InsertTemplate(ctx context.Context, t *Template) error

	// GetTemplate retrieves a deployment template by ID within a tenant.
	GetTemplate(ctx context.Context, tenantID string, templateID id.ID) (*Template, error)

	// UpdateTemplate persists changes to an existing deployment template.
	UpdateTemplate(ctx context.Context, t *Template) error

	// DeleteTemplate removes a deployment template.
	DeleteTemplate(ctx context.Context, tenantID string, templateID id.ID) error

	// ListTemplates returns a paginated list of deployment templates for a tenant.
	ListTemplates(ctx context.Context, tenantID string, opts ListOptions) (*TemplateListResult, 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)
}

StrategyParams provides everything a strategy needs to execute a deployment.

type Template added in v1.3.0

type Template struct {
	ctrlplane.Entity

	TenantID    string                    `db:"tenant_id"    json:"tenant_id"`
	Name        string                    `db:"name"         json:"name"`
	Description string                    `db:"description"  json:"description,omitempty"`
	Image       string                    `db:"image"        json:"image"`
	Strategy    string                    `db:"strategy"     json:"strategy"`
	Resources   provider.ResourceSpec     `db:"resources"    json:"resources"`
	Ports       []provider.PortSpec       `db:"ports"        json:"ports,omitempty"`
	Volumes     []provider.VolumeSpec     `db:"volumes"      json:"volumes,omitempty"`
	HealthCheck *provider.HealthCheckSpec `db:"health_check" json:"health_check,omitempty"`
	Env         map[string]string         `db:"env"          json:"env,omitempty"`
	Secrets     []SecretRef               `db:"secrets"      json:"secrets,omitempty"`
	ConfigFiles []ConfigFile              `db:"config_files" json:"config_files,omitempty"`
	Labels      map[string]string         `db:"labels"       json:"labels,omitempty"`
	Annotations map[string]string         `db:"annotations"  json:"annotations,omitempty"`
	CommitSHA   string                    `db:"commit_sha"   json:"commit_sha,omitempty"`
	Notes       string                    `db:"notes"        json:"notes,omitempty"`
}

Template is a reusable deployment configuration that can be saved and applied when creating new deployments.

type TemplateListResult added in v1.3.0

type TemplateListResult struct {
	Items []*Template `json:"items"`
	Total int         `json:"total"`
}

TemplateListResult holds a page of templates with a total count.

type UpdateTemplateRequest added in v1.3.0

type UpdateTemplateRequest struct {
	Name        *string                   `json:"name,omitempty"`
	Description *string                   `json:"description,omitempty"`
	Image       *string                   `json:"image,omitempty"`
	Strategy    *string                   `json:"strategy,omitempty"`
	Resources   *provider.ResourceSpec    `json:"resources,omitempty"`
	Ports       []provider.PortSpec       `json:"ports,omitempty"`
	Volumes     []provider.VolumeSpec     `json:"volumes,omitempty"`
	HealthCheck *provider.HealthCheckSpec `json:"health_check,omitempty"`
	Env         map[string]string         `json:"env,omitempty"`
	Secrets     []SecretRef               `json:"secrets,omitempty"`
	ConfigFiles []ConfigFile              `json:"config_files,omitempty"`
	Labels      map[string]string         `json:"labels,omitempty"`
	Annotations map[string]string         `json:"annotations,omitempty"`
	CommitSHA   *string                   `json:"commit_sha,omitempty"`
	Notes       *string                   `json:"notes,omitempty"`
}

UpdateTemplateRequest holds the parameters for updating a deployment template. Pointer fields enable partial updates — only non-nil fields are applied.

Directories

Path Synopsis
Package strategies provides built-in deployment strategy implementations.
Package strategies provides built-in deployment strategy implementations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL