Documentation
¶
Index ¶
- Constants
- Variables
- func BackupContainer(s *Server, name string)
- func BuildImage(s *Server, name, source string) (string, error)
- func ConfigureInsecureRegistry(s *Server, addr string)
- func RemoveContainer(s *Server, name string)
- func Rollback(s *Server, name string) error
- func StartService(s *Server, service *Service) error
- func StopService(s *Server, name string) error
- func SyncSecrets(from *Server, to []*Server)
- func UploadImage(s *Server, imagePath string) (string, error)
- func WaitForHealthy(s *Server, container string, timeoutSecs int) error
- func WaitForRegistry(s *Server, host string)
- type Backend
- type Healthcheck
- type LoadBalancer
- type LoadBalancerConfig
- type LoadBalancerProvider
- type LogConfig
- type Mount
- type Platform
- type Port
- type Region
- type Resources
- type SSHKeyProvider
- type Server
- func (s *Server) Connect(args ...string) error
- func (s *Server) Copy(local, remote string) error
- func (s *Server) Interactive() error
- func (s *Server) RunScript(localPath string) error
- func (s *Server) SSH(args ...string) (string, error)
- func (s *Server) SSHWithTimeout(timeout time.Duration, args ...string) (string, error)
- func (s *Server) WaitForSSH(timeout time.Duration) error
- func (s *Server) Write(remotePath string, data []byte, executable bool) error
- type ServerOptions
- type Service
- type Size
- type TagProvider
- type VPCProvider
- type Volume
Constants ¶
const DefaultSSHTimeout = 60 * time.Second
DefaultSSHTimeout is the default timeout for SSH commands (60 seconds). Set Server.SSHTimeout to override per-server or use SSHWithTimeout for per-call.
Variables ¶
var ( // ErrNotFound is returned when a resource doesn't exist ErrNotFound = errors.New("resource not found") // ErrTimeout is returned when an operation times out ErrTimeout = errors.New("operation timed out") // ErrUnsupportedRegion is returned when a region is not supported by the provider ErrUnsupportedRegion = errors.New("unsupported region") // ErrUnsupportedSize is returned when a size is not supported by the provider ErrUnsupportedSize = errors.New("unsupported size") )
Functions ¶
func BackupContainer ¶
BackupContainer stops and renames the current container for rollback.
func BuildImage ¶
BuildImage uploads source and builds a Docker image on the server. Uses git archive to capture all tracked files, avoiding brittle hardcoded lists.
func ConfigureInsecureRegistry ¶
ConfigureInsecureRegistry writes /etc/docker/daemon.json on the server to allow pulling from an insecure (HTTP) private registry. Only restarts Docker if the config actually changed.
func RemoveContainer ¶
RemoveContainer force-removes a Docker container by name.
func StartService ¶
StartService runs a service container on the server.
func StopService ¶
StopService kills and removes a container on the server.
func SyncSecrets ¶
SyncSecrets copies /etc/secrets/* from one server to each target server. Public keys and SSH keys are set to 644 so non-root container users can read them.
func UploadImage ¶
UploadImage uploads a Docker image tar.gz to the server and loads it. Returns the image name extracted from the file path.
func WaitForHealthy ¶
WaitForHealthy waits for a Docker container to report healthy status.
func WaitForRegistry ¶
WaitForRegistry waits for a Docker registry to be reachable from this server.
Types ¶
type Backend ¶
type Backend interface {
// Servers
CreateServer(opts ServerOptions) (*Server, error)
GetServer(name string) (*Server, error)
DeleteServer(id string) error
// Volumes
CreateVolume(name string, sizeGB int, region Region) (*Volume, error)
GetVolume(name string) (*Volume, error)
AttachVolume(volumeID, serverID string) error
DetachVolume(volumeID string) error
}
Backend is the interface that providers implement.
type Healthcheck ¶
type Healthcheck struct {
Cmd string // Command to run (e.g., "curl -f http://localhost/health")
Interval string // Time between checks (e.g., "30s")
Timeout string // Time to wait for check to complete (e.g., "10s")
Retries int // Consecutive failures before unhealthy
StartPeriod string // Grace period before health checks start (e.g., "5s")
}
Healthcheck configures container health checking
type LoadBalancer ¶
type LoadBalancer struct {
ID string
Name string
IP string // Public IP address
Status string // "new", "active", "errored"
}
LoadBalancer represents a cloud load balancer.
type LoadBalancerConfig ¶
type LoadBalancerConfig struct {
Name string
Region Region
VpcID string // VPC to attach to
ServerIDs []int // Backend server IDs
Tags []string // Tags to target servers (alternative to ServerIDs)
Port int // Frontend port (default 443)
TargetPort int // Backend port (default 80)
HealthPath string // Health check path (default "/health")
}
LoadBalancerConfig configures load balancer creation.
type LoadBalancerProvider ¶
type LoadBalancerProvider interface {
CreateLoadBalancer(cfg LoadBalancerConfig) (*LoadBalancer, error)
GetLoadBalancer(name string) (*LoadBalancer, error)
DeleteLoadBalancer(id string) error
}
LoadBalancerProvider is an optional interface for load balancer management.
type LogConfig ¶
type LogConfig struct {
Driver string // Log driver (e.g., "json-file", "syslog")
Options map[string]string // Driver-specific options
}
LogConfig configures container logging
type Platform ¶
type Platform struct {
Backend
}
Platform provides cloud infrastructure operations. Use providers to create: mock.New(), digitalocean.New(), aws.New(), gcp.New()
type Port ¶
type Port struct {
Host int
Container int
Bind string // Optional bind address (e.g., "127.0.0.1")
}
Port maps a host port to a container port
type Region ¶
type Region string
Region represents a geographic location for cloud resources. Use these constants instead of provider-specific region codes.
const ( // NYC represents the New York region. NYC Region = "nyc" // SFO represents the San Francisco region. SFO Region = "sfo" // TOR represents the Toronto region. TOR Region = "tor" // LON represents the London region. LON Region = "lon" // AMS represents the Amsterdam region. AMS Region = "ams" // FRA represents the Frankfurt region. FRA Region = "fra" // SGP represents the Singapore region. SGP Region = "sgp" // SYD represents the Sydney region. SYD Region = "syd" // BLR represents the Bangalore region. BLR Region = "blr" )
Supported cloud regions, grouped by continent.
type Resources ¶
type Resources struct {
CPUs string // CPU limit (e.g., "0.5", "2")
Memory string // Memory limit (e.g., "512m", "1g")
}
Resources configures CPU and memory limits
type SSHKeyProvider ¶
type SSHKeyProvider interface {
// GetSSHKeyFingerprint finds or registers an SSH key, returns fingerprint.
GetSSHKeyFingerprint(publicKey string) (string, error)
}
SSHKeyProvider is an optional interface for SSH key management.
type Server ¶
type Server struct {
ID string
Name string
IP string
PrivateIP string // Private IP for VPC networking (empty if no VPC)
Size string // e.g., "s-1vcpu-2gb"
Region string // e.g., "nyc1"
Status string // creating, active, off
SSHTimeout time.Duration // Per-command SSH timeout (0 = DefaultSSHTimeout)
// contains filtered or unexported fields
}
Server represents a cloud virtual machine
func (*Server) Copy ¶
Copy uploads a file to the server via SCP. Uses a 5-minute timeout to prevent indefinite hangs on large files.
func (*Server) Interactive ¶
Interactive opens an interactive SSH shell
func (*Server) RunScript ¶
RunScript uploads and runs a setup script on the server. If the script file doesn't exist locally, it's a no-op.
func (*Server) SSH ¶
SSH executes a command on the server and returns output. Uses the configured SSHTimeout (default 60s) to prevent indefinite hangs. SECURITY: Arguments are shell-escaped to prevent command injection.
func (*Server) SSHWithTimeout ¶
SSHWithTimeout executes a command on the server with a specific timeout. Use this for long-running operations like docker build that need more time.
func (*Server) WaitForSSH ¶
WaitForSSH waits until the server accepts SSH connections. Uses a real SSH command to verify full authentication works, not just a TCP dial (sshd may accept connections before it's ready to authenticate).
type ServerOptions ¶
type ServerOptions struct {
Name string
Size Size
Region Region
Image string // Provider-specific image ID/slug
SSHKey string // SSH key fingerprint (use GetSSHKeyFingerprint to get)
Tags []string
Backups bool // Enable provider-managed backups
VpcID string // VPC ID for private networking (optional)
}
ServerOptions configures server creation.
type Service ¶
type Service struct {
Name string
Image string
Command []string
Ports []Port
Volumes []Mount
Env map[string]string
Network string
Restart string
Healthcheck *Healthcheck
Resources *Resources
Logging *LogConfig
Privileged bool
}
Service represents a Docker container to run on a server
type Size ¶
type Size string
Size represents a server size tier. Use these constants instead of provider-specific instance types.
const ( // Micro is 1 vCPU, 1GB RAM — suited for dev/testing. Micro Size = "micro" // Small is 1 vCPU, 2GB RAM — suited for small apps. Small Size = "small" // Medium is 2 vCPU, 4GB RAM — suited for standard apps. Medium Size = "medium" // Large is 4 vCPU, 8GB RAM — suited for larger workloads. Large Size = "large" // XLarge is 8 vCPU, 16GB RAM — suited for high performance. XLarge Size = "xlarge" )
Supported server size tiers with approximate resource allocations.
type TagProvider ¶
TagProvider is an optional interface for tagging servers with provider-specific tags.
type VPCProvider ¶
type VPCProvider interface {
// CreateVPC creates a VPC network, returning its ID.
CreateVPC(name, region, description string) (string, error)
// GetVPC looks up a VPC by name and returns its ID.
GetVPC(name string) (string, error)
}
VPCProvider is an optional interface for VPC management.