deploy

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package deploy provides a deployment provider system for agentkit that allows any omniagent implementation to deploy to multiple cloud targets via environment variable configuration.

Index

Constants

View Source
const (
	// EnvDeployProvider is the environment variable for selecting the provider.
	EnvDeployProvider = "AGENTKIT_DEPLOY_PROVIDER"

	// EnvPulumiBackend is the environment variable for the Pulumi backend URL.
	EnvPulumiBackend = "PULUMI_BACKEND_URL"

	// EnvPulumiAccessToken is the environment variable for Pulumi Cloud access.
	EnvPulumiAccessToken = "PULUMI_ACCESS_TOKEN"

	// EnvDryRun is the environment variable to enable dry-run mode.
	EnvDryRun = "AGENTKIT_DEPLOY_DRY_RUN"

	// EnvAutoApprove is the environment variable to auto-approve deployments.
	EnvAutoApprove = "AGENTKIT_DEPLOY_AUTO_APPROVE"
)

Environment variable names for configuration.

View Source
const DefaultProvider = "lightsail"

DefaultProvider is the default deployment provider when none is specified.

Variables

View Source
var (
	// ErrProviderNotFound is returned when a requested provider is not registered.
	ErrProviderNotFound = errors.New("deploy: provider not found")

	// ErrProviderAlreadyRegistered is returned when attempting to register a duplicate provider.
	ErrProviderAlreadyRegistered = errors.New("deploy: provider already registered")

	// ErrInvalidConfig is returned when configuration is invalid.
	ErrInvalidConfig = errors.New("deploy: invalid configuration")

	// ErrDeploymentFailed is returned when a deployment fails.
	ErrDeploymentFailed = errors.New("deploy: deployment failed")

	// ErrDeploymentNotFound is returned when a deployment stack is not found.
	ErrDeploymentNotFound = errors.New("deploy: deployment not found")

	// ErrOperationCanceled is returned when an operation is canceled via context.
	ErrOperationCanceled = errors.New("deploy: operation canceled")

	// ErrResourceQuotaExceeded is returned when cloud resource quotas are exceeded.
	ErrResourceQuotaExceeded = errors.New("deploy: resource quota exceeded")

	// ErrAuthenticationFailed is returned when cloud authentication fails.
	ErrAuthenticationFailed = errors.New("deploy: authentication failed")

	// ErrPulumiNotConfigured is returned when Pulumi backend is not configured.
	ErrPulumiNotConfigured = errors.New("deploy: pulumi backend not configured")
)

Sentinel errors for common deployment failures.

Functions

func HasProvider

func HasProvider(name ProviderName) bool

HasProvider checks if a provider is registered.

func MustRegisterProvider

func MustRegisterProvider(name ProviderName, factory ProviderFactory, priority int) error

MustRegisterProvider is like RegisterProvider but returns an error instead of panicking.

func RegisterProvider

func RegisterProvider(name ProviderName, factory ProviderFactory, priority int)

RegisterProvider registers a deployment provider factory with a given priority. Higher priority providers are preferred when multiple providers are available. Panics if a provider with the same name is already registered.

func ResetRegistry

func ResetRegistry()

ResetRegistry clears all registered providers. This is primarily useful for testing.

func UnregisterProvider

func UnregisterProvider(name ProviderName)

UnregisterProvider removes a provider from the registry. This is primarily useful for testing.

Types

type BuildConfig

type BuildConfig struct {
	// Context is the build context path.
	Context string `yaml:"context" json:"context"`

	// Dockerfile is the path to the Dockerfile.
	Dockerfile string `yaml:"dockerfile" json:"dockerfile"`

	// Args are build arguments.
	Args map[string]string `yaml:"args" json:"args"`
}

BuildConfig defines how to build the container image.

type Capabilities

type Capabilities struct {
	// AutoScaling indicates the provider supports auto-scaling.
	AutoScaling bool `json:"auto_scaling"`

	// CustomDomain indicates the provider supports custom domain mapping.
	CustomDomain bool `json:"custom_domain"`

	// HTTPS indicates the provider supports HTTPS termination.
	HTTPS bool `json:"https"`

	// VPC indicates the provider supports VPC networking.
	VPC bool `json:"vpc"`

	// SecretsIntegration indicates the provider integrates with secrets managers.
	SecretsIntegration bool `json:"secrets_integration"`

	// Preview indicates the provider supports deployment previews.
	Preview bool `json:"preview"`

	// Rollback indicates the provider supports deployment rollback.
	Rollback bool `json:"rollback"`

	// MaxMemoryMB is the maximum memory allocation in MB.
	MaxMemoryMB int `json:"max_memory_mb"`
}

Capabilities describes what features a provider supports.

type ConfigError

type ConfigError struct {
	Field string
	Err   error
}

ConfigError wraps an error with configuration context.

func NewConfigError

func NewConfigError(field string, err error) *ConfigError

NewConfigError creates a new ConfigError.

func (*ConfigError) Error

func (e *ConfigError) Error() string

Error implements the error interface.

func (*ConfigError) Unwrap

func (e *ConfigError) Unwrap() error

Unwrap returns the underlying error.

type DeployConfig

type DeployConfig struct {
	// Stack contains the core stack configuration.
	Stack StackConfig `yaml:"stack" json:"stack"`

	// Provider is the deployment provider name ("lightsail", "ecs", "cloudrun", "docker").
	Provider string `yaml:"provider" json:"provider"`

	// ProviderConfig contains provider-specific configuration.
	// Use type assertion to access (e.g., cfg.ProviderConfig.(*LightsailConfig)).
	ProviderConfig any `yaml:"provider_config" json:"provider_config"`

	// PulumiBackend is the Pulumi state backend URL.
	// Examples: "file://~/.pulumi", "s3://my-bucket/pulumi", "https://api.pulumi.com"
	PulumiBackend string `yaml:"pulumi_backend" json:"pulumi_backend"`

	// DryRun performs a preview without making changes.
	DryRun bool `yaml:"dry_run" json:"dry_run"`

	// AutoApprove skips confirmation prompts.
	AutoApprove bool `yaml:"auto_approve" json:"auto_approve"`
}

DeployConfig holds the configuration for a deployment.

func LoadDeployConfig

func LoadDeployConfig(path string) (*DeployConfig, error)

LoadDeployConfig loads a deployment configuration from a YAML file. Environment variables override file values (precedence: env > file > defaults).

func NewDeployConfig

func NewDeployConfig() *DeployConfig

NewDeployConfig creates a new DeployConfig with defaults applied.

func (*DeployConfig) GetProviderName

func (c *DeployConfig) GetProviderName() string

GetProviderName returns the effective provider name, considering env overrides.

func (*DeployConfig) Validate

func (c *DeployConfig) Validate() error

Validate checks that the configuration is valid.

type DeploymentError

type DeploymentError struct {
	StackName string
	State     DeploymentState
	Err       error
}

DeploymentError wraps an error with deployment context.

func NewDeploymentError

func NewDeploymentError(stackName string, state DeploymentState, err error) *DeploymentError

NewDeploymentError creates a new DeploymentError.

func (*DeploymentError) Error

func (e *DeploymentError) Error() string

Error implements the error interface.

func (*DeploymentError) Unwrap

func (e *DeploymentError) Unwrap() error

Unwrap returns the underlying error.

type DeploymentState

type DeploymentState string

DeploymentState represents the current state of a deployment.

const (
	// StateUnknown indicates the deployment state is unknown.
	StateUnknown DeploymentState = "unknown"

	// StatePending indicates the deployment is pending.
	StatePending DeploymentState = "pending"

	// StateInProgress indicates the deployment is in progress.
	StateInProgress DeploymentState = "in_progress"

	// StateSucceeded indicates the deployment succeeded.
	StateSucceeded DeploymentState = "succeeded"

	// StateFailed indicates the deployment failed.
	StateFailed DeploymentState = "failed"

	// StateDestroying indicates the deployment is being destroyed.
	StateDestroying DeploymentState = "destroying"

	// StateDestroyed indicates the deployment was destroyed.
	StateDestroyed DeploymentState = "destroyed"
)

Deployment states.

func (DeploymentState) IsTerminal

func (s DeploymentState) IsTerminal() bool

IsTerminal returns true if this state is a terminal state.

func (DeploymentState) String

func (s DeploymentState) String() string

String implements the Stringer interface.

type DeploymentStatus

type DeploymentStatus struct {
	// StackName is the unique identifier for this deployment.
	StackName string `json:"stack_name"`

	// State is the current deployment state.
	State DeploymentState `json:"state"`

	// Provider is the name of the provider used.
	Provider string `json:"provider"`

	// Version is the deployment version (e.g., git sha, timestamp).
	Version string `json:"version,omitempty"`

	// StartTime is when the deployment started.
	StartTime time.Time `json:"start_time"`

	// EndTime is when the deployment ended (zero if still running).
	EndTime time.Time `json:"end_time,omitempty"`

	// Duration is the elapsed time.
	Duration time.Duration `json:"duration,omitempty"`

	// Resources lists the deployed resources.
	Resources []Resource `json:"resources,omitempty"`

	// Outputs contains deployment outputs (e.g., URLs, IPs).
	Outputs map[string]string `json:"outputs,omitempty"`

	// Error contains error details if the deployment failed.
	Error string `json:"error,omitempty"`

	// Message provides additional status information.
	Message string `json:"message,omitempty"`

	// Metadata contains provider-specific metadata.
	Metadata map[string]any `json:"metadata,omitempty"`
}

DeploymentStatus represents the full status of a deployment.

func (*DeploymentStatus) CalculateSummary

func (s *DeploymentStatus) CalculateSummary() ResourceSummary

CalculateSummary computes a summary from the resources.

type HealthCheckConfig

type HealthCheckConfig struct {
	// Path is the HTTP health check path.
	Path string `yaml:"path" json:"path"`

	// IntervalSeconds is the check interval.
	IntervalSeconds int `yaml:"interval_seconds" json:"interval_seconds"`

	// TimeoutSeconds is the check timeout.
	TimeoutSeconds int `yaml:"timeout_seconds" json:"timeout_seconds"`

	// HealthyThreshold is the number of successful checks required.
	HealthyThreshold int `yaml:"healthy_threshold" json:"healthy_threshold"`

	// UnhealthyThreshold is the number of failed checks before unhealthy.
	UnhealthyThreshold int `yaml:"unhealthy_threshold" json:"unhealthy_threshold"`
}

HealthCheckConfig defines health check settings.

type ImageConfig

type ImageConfig struct {
	// Repository is the container image repository.
	Repository string `yaml:"repository" json:"repository"`

	// Tag is the image tag (default: "latest").
	Tag string `yaml:"tag" json:"tag"`

	// Digest is the image digest for immutable deployments.
	Digest string `yaml:"digest" json:"digest"`

	// Build contains build configuration if building from source.
	Build *BuildConfig `yaml:"build" json:"build"`
}

ImageConfig defines container image settings.

type LogEntry

type LogEntry struct {
	// Timestamp is the time the log was generated.
	Timestamp string `json:"timestamp"`

	// Level is the log level (info, warn, error).
	Level string `json:"level"`

	// Message is the log message.
	Message string `json:"message"`

	// Source identifies where the log came from.
	Source string `json:"source,omitempty"`
}

LogEntry represents a single log entry from a deployment.

type LogProvider

type LogProvider interface {
	Provider

	// StreamLogs streams deployment logs to the provided channel.
	StreamLogs(ctx context.Context, stackName string, logs chan<- LogEntry) error
}

LogProvider is an optional interface for providers that support log streaming.

type PreviewProvider

type PreviewProvider interface {
	Provider

	// Preview shows what would be deployed without making changes.
	Preview(ctx context.Context, cfg *DeployConfig) (*PreviewResult, error)
}

PreviewProvider is an optional interface for providers that support preview deployments.

type PreviewResult

type PreviewResult struct {
	// StackName is the name of the stack.
	StackName string `json:"stack_name"`

	// Creates lists resources that would be created.
	Creates []ResourcePreview `json:"creates,omitempty"`

	// Updates lists resources that would be updated.
	Updates []ResourcePreview `json:"updates,omitempty"`

	// Deletes lists resources that would be deleted.
	Deletes []ResourcePreview `json:"deletes,omitempty"`

	// Summary provides a human-readable summary.
	Summary string `json:"summary"`
}

PreviewResult contains the result of a deployment preview.

type Provider

type Provider interface {
	// Deploy deploys the configuration to the target platform.
	// Returns a DeploymentStatus on success or error on failure.
	Deploy(ctx context.Context, cfg *DeployConfig) (*DeploymentStatus, error)

	// Status returns the current status of a deployment.
	Status(ctx context.Context, stackName string) (*DeploymentStatus, error)

	// Destroy removes all resources associated with a deployment.
	Destroy(ctx context.Context, stackName string) error

	// Name returns the unique identifier for this provider.
	Name() string

	// Capabilities returns the capabilities of this provider.
	Capabilities() Capabilities

	// Close releases any resources held by the provider.
	Close() error
}

Provider defines the interface for deployment providers. Implementations must be thread-safe.

func GetProvider

func GetProvider(cfg *DeployConfig) (Provider, error)

GetProvider returns a provider for the given configuration. It checks AGENTKIT_DEPLOY_PROVIDER env var first, then cfg.Provider, then defaults.

func GetProviderByName

func GetProviderByName(name ProviderName, cfg *DeployConfig) (Provider, error)

GetProviderByName returns a provider by its name.

type ProviderError

type ProviderError struct {
	Provider string
	Op       string
	Err      error
}

ProviderError wraps an error with provider context.

func NewProviderError

func NewProviderError(provider, op string, err error) *ProviderError

NewProviderError creates a new ProviderError.

func (*ProviderError) Error

func (e *ProviderError) Error() string

Error implements the error interface.

func (*ProviderError) Unwrap

func (e *ProviderError) Unwrap() error

Unwrap returns the underlying error.

type ProviderFactory

type ProviderFactory func(cfg *DeployConfig) (Provider, error)

ProviderFactory creates a new Provider instance.

type ProviderInfo

type ProviderInfo struct {
	Name     ProviderName `json:"name"`
	Priority int          `json:"priority"`
}

ProviderInfo contains metadata about a registered provider.

func ListProviderInfo

func ListProviderInfo() []ProviderInfo

ListProviderInfo returns detailed information about registered providers.

type ProviderName

type ProviderName string

ProviderName is a type alias for provider names to improve type safety.

const (
	ProviderLightsail ProviderName = "lightsail"
	ProviderECS       ProviderName = "ecs"
	ProviderCloudRun  ProviderName = "cloudrun"
	ProviderDocker    ProviderName = "docker"
)

Standard provider names.

func ListProviders

func ListProviders() []ProviderName

ListProviders returns a list of registered provider names, sorted by priority (highest first).

type Resource

type Resource struct {
	// URN is the unique resource name in Pulumi format.
	URN string `json:"urn"`

	// Type is the resource type (e.g., "aws:lightsail:ContainerService").
	Type string `json:"type"`

	// Name is the resource name.
	Name string `json:"name"`

	// ID is the provider-specific resource ID.
	ID string `json:"id,omitempty"`

	// State is the resource state (e.g., "created", "updated", "deleted").
	State string `json:"state"`

	// Outputs contains resource-specific outputs.
	Outputs map[string]any `json:"outputs,omitempty"`
}

Resource represents a deployed cloud resource.

type ResourceConfig

type ResourceConfig struct {
	// CPU is the CPU allocation (e.g., "0.25", "1", "2").
	CPU string `yaml:"cpu" json:"cpu"`

	// Memory is the memory allocation (e.g., "512", "1024", "2048" in MB).
	Memory string `yaml:"memory" json:"memory"`

	// Port is the container port to expose.
	Port int `yaml:"port" json:"port"`
}

ResourceConfig defines compute resources.

type ResourcePreview

type ResourcePreview struct {
	// URN is the unique resource name.
	URN string `json:"urn"`

	// Type is the resource type.
	Type string `json:"type"`

	// Name is the resource name.
	Name string `json:"name"`

	// Details provides additional information about the change.
	Details map[string]any `json:"details,omitempty"`
}

ResourcePreview describes a resource change in a preview.

type ResourceSummary

type ResourceSummary struct {
	// Total is the total number of resources.
	Total int `json:"total"`

	// Created is the number of resources created.
	Created int `json:"created"`

	// Updated is the number of resources updated.
	Updated int `json:"updated"`

	// Deleted is the number of resources deleted.
	Deleted int `json:"deleted"`

	// Unchanged is the number of unchanged resources.
	Unchanged int `json:"unchanged"`
}

ResourceSummary provides a summary of deployed resources.

type RollbackProvider

type RollbackProvider interface {
	Provider

	// Rollback reverts to a previous deployment version.
	Rollback(ctx context.Context, stackName string, targetVersion string) (*DeploymentStatus, error)

	// ListVersions returns available versions for rollback.
	ListVersions(ctx context.Context, stackName string) ([]string, error)
}

RollbackProvider is an optional interface for providers that support rollback.

type ScalingConfig

type ScalingConfig struct {
	// MinInstances is the minimum number of instances.
	MinInstances int `yaml:"min_instances" json:"min_instances"`

	// MaxInstances is the maximum number of instances.
	MaxInstances int `yaml:"max_instances" json:"max_instances"`

	// TargetCPUPercent is the target CPU utilization for scaling.
	TargetCPUPercent int `yaml:"target_cpu_percent" json:"target_cpu_percent"`
}

ScalingConfig defines scaling settings.

type SecretRef

type SecretRef struct {
	// Source is the secret source ("env", "ssm", "secrets-manager", "vault").
	Source string `yaml:"source" json:"source"`

	// Key is the secret key or path.
	Key string `yaml:"key" json:"key"`

	// Version is the secret version (optional).
	Version string `yaml:"version" json:"version"`
}

SecretRef references a secret from a secrets manager.

type StackConfig

type StackConfig struct {
	// Name is the stack name (e.g., "myapp-prod", "invest-advisor-staging").
	Name string `yaml:"name" json:"name"`

	// Project is the Pulumi project name.
	Project string `yaml:"project" json:"project"`

	// Description provides a human-readable description.
	Description string `yaml:"description" json:"description"`

	// Region is the cloud region for deployment.
	Region string `yaml:"region" json:"region"`

	// Tags are resource tags applied to all resources.
	Tags map[string]string `yaml:"tags" json:"tags"`

	// Image is the container image configuration.
	Image ImageConfig `yaml:"image" json:"image"`

	// Resources defines compute resources.
	Resources ResourceConfig `yaml:"resources" json:"resources"`

	// Environment contains environment variables.
	Environment map[string]string `yaml:"environment" json:"environment"`

	// Secrets contains secret references.
	Secrets map[string]SecretRef `yaml:"secrets" json:"secrets"`

	// HealthCheck defines the health check configuration.
	HealthCheck *HealthCheckConfig `yaml:"health_check" json:"health_check"`

	// Scaling defines the scaling configuration.
	Scaling *ScalingConfig `yaml:"scaling" json:"scaling"`
}

StackConfig defines the core deployment stack configuration.

Jump to

Keyboard shortcuts

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