Documentation
¶
Overview ¶
Package deployments provides infrastructure for managing custom deployments (static sites, Next.js apps, Go/Node.js backends, and SQLite databases)
Index ¶
- Constants
- Variables
- type Deployment
- type DeploymentDomain
- type DeploymentError
- type DeploymentEvent
- type DeploymentHealthCheck
- type DeploymentHistory
- type DeploymentRequest
- type DeploymentResponse
- type DeploymentStatus
- type DeploymentType
- type HomeNodeAssignment
- type HomeNodeManager
- func (hnm *HomeNodeManager) AssignHomeNode(ctx context.Context, namespace string) (string, error)
- func (hnm *HomeNodeManager) GetHomeNode(ctx context.Context, namespace string) (string, error)
- func (hnm *HomeNodeManager) GetStaleNamespaces(ctx context.Context, staleThreshold time.Duration) ([]string, error)
- func (hnm *HomeNodeManager) MigrateNamespace(ctx context.Context, namespace, newNodeID string) error
- func (hnm *HomeNodeManager) UpdateHeartbeat(ctx context.Context, namespace string) error
- func (hnm *HomeNodeManager) UpdateResourceUsage(ctx context.Context, namespace string, ...) error
- type NodeCapacity
- type PortAllocation
- type PortAllocator
- func (pa *PortAllocator) AllocatePort(ctx context.Context, nodeID, deploymentID string) (int, error)
- func (pa *PortAllocator) DeallocatePort(ctx context.Context, deploymentID string) error
- func (pa *PortAllocator) GetAllocatedPort(ctx context.Context, deploymentID string) (int, string, error)
- func (pa *PortAllocator) GetAvailablePortCount(ctx context.Context, nodeID string) (int, error)
- func (pa *PortAllocator) GetNodePortCount(ctx context.Context, nodeID string) (int, error)
- type Replica
- type ReplicaManager
- func (rm *ReplicaManager) CreateReplica(ctx context.Context, deploymentID, nodeID string, port int, isPrimary bool, ...) error
- func (rm *ReplicaManager) GetActiveReplicaNodes(ctx context.Context, deploymentID string) ([]string, error)
- func (rm *ReplicaManager) GetNodeIP(ctx context.Context, nodeID string) (string, error)
- func (rm *ReplicaManager) GetReplicaPort(ctx context.Context, deploymentID, nodeID string) (int, error)
- func (rm *ReplicaManager) GetReplicas(ctx context.Context, deploymentID string) ([]Replica, error)
- func (rm *ReplicaManager) IsReplicaNode(ctx context.Context, deploymentID, nodeID string) (bool, error)
- func (rm *ReplicaManager) RemoveReplicas(ctx context.Context, deploymentID string) error
- func (rm *ReplicaManager) SelectReplicaNodes(ctx context.Context, primaryNodeID string, count int) ([]string, error)
- func (rm *ReplicaManager) UpdateReplicaStatus(ctx context.Context, deploymentID, nodeID string, status ReplicaStatus) error
- type ReplicaStatus
- type RestartPolicy
- type RoutingType
Constants ¶
const ( MinPort = 10000 // Minimum allocatable port MaxPort = 19999 // Maximum allocatable port ReservedMinPort = 10000 // Start of reserved range ReservedMaxPort = 10099 // End of reserved range UserMinPort = 10100 // Start of user-allocatable range )
Port range constants
const ( DefaultMemoryLimitMB = 256 DefaultCPULimitPercent = 50 DefaultDiskLimitMB = 1024 DefaultHealthCheckInterval = 30 // seconds DefaultMaxRestartCount = 10 )
Default resource limits
const DefaultReplicaCount = 2
DefaultReplicaCount is the default number of replicas per deployment
Variables ¶
var ( ErrNoPortsAvailable = &DeploymentError{Message: "no ports available on node"} ErrNoNodesAvailable = &DeploymentError{Message: "no nodes available for deployment"} ErrDeploymentNotFound = &DeploymentError{Message: "deployment not found"} ErrNamespaceNotAssigned = &DeploymentError{Message: "namespace has no home node assigned"} ErrSubdomainTaken = &DeploymentError{Message: "subdomain already in use"} )
Errors
Functions ¶
This section is empty.
Types ¶
type Deployment ¶
type Deployment struct {
ID string `json:"id"`
Namespace string `json:"namespace"`
Name string `json:"name"`
Type DeploymentType `json:"type"`
Version int `json:"version"`
Status DeploymentStatus `json:"status"`
// Content storage
ContentCID string `json:"content_cid,omitempty"`
BuildCID string `json:"build_cid,omitempty"`
// Runtime configuration
HomeNodeID string `json:"home_node_id,omitempty"`
Port int `json:"port,omitempty"`
Subdomain string `json:"subdomain,omitempty"`
Environment map[string]string `json:"environment,omitempty"` // Unmarshaled from JSON
// Resource limits
MemoryLimitMB int `json:"memory_limit_mb"`
CPULimitPercent int `json:"cpu_limit_percent"`
DiskLimitMB int `json:"disk_limit_mb"`
// Health & monitoring
HealthCheckPath string `json:"health_check_path,omitempty"`
HealthCheckInterval int `json:"health_check_interval"`
RestartPolicy RestartPolicy `json:"restart_policy"`
MaxRestartCount int `json:"max_restart_count"`
// Metadata
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeployedBy string `json:"deployed_by"`
}
Deployment represents a deployed application or service
type DeploymentDomain ¶
type DeploymentDomain struct {
ID string `json:"id"`
DeploymentID string `json:"deployment_id"`
Namespace string `json:"namespace"`
Domain string `json:"domain"`
RoutingType RoutingType `json:"routing_type"`
NodeID string `json:"node_id,omitempty"`
IsCustom bool `json:"is_custom"`
TLSCertCID string `json:"tls_cert_cid,omitempty"`
VerifiedAt *time.Time `json:"verified_at,omitempty"`
VerificationToken string `json:"verification_token,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
DeploymentDomain represents a custom domain mapping
type DeploymentError ¶
DeploymentError represents a deployment-related error
func (*DeploymentError) Error ¶
func (e *DeploymentError) Error() string
func (*DeploymentError) Unwrap ¶
func (e *DeploymentError) Unwrap() error
type DeploymentEvent ¶
type DeploymentEvent struct {
ID string `json:"id"`
DeploymentID string `json:"deployment_id"`
EventType string `json:"event_type"`
Message string `json:"message,omitempty"`
Metadata string `json:"metadata,omitempty"` // JSON
CreatedAt time.Time `json:"created_at"`
CreatedBy string `json:"created_by,omitempty"`
}
DeploymentEvent represents an audit trail event
type DeploymentHealthCheck ¶
type DeploymentHealthCheck struct {
ID string `json:"id"`
DeploymentID string `json:"deployment_id"`
NodeID string `json:"node_id"`
Status string `json:"status"` // healthy, unhealthy, unknown
ResponseTimeMS int `json:"response_time_ms,omitempty"`
StatusCode int `json:"status_code,omitempty"`
ErrorMessage string `json:"error_message,omitempty"`
CheckedAt time.Time `json:"checked_at"`
}
DeploymentHealthCheck represents a health check result
type DeploymentHistory ¶
type DeploymentHistory struct {
ID string `json:"id"`
DeploymentID string `json:"deployment_id"`
Version int `json:"version"`
ContentCID string `json:"content_cid,omitempty"`
BuildCID string `json:"build_cid,omitempty"`
DeployedAt time.Time `json:"deployed_at"`
DeployedBy string `json:"deployed_by"`
Status string `json:"status"`
ErrorMessage string `json:"error_message,omitempty"`
RollbackFromVersion *int `json:"rollback_from_version,omitempty"`
}
DeploymentHistory tracks deployment versions for rollback
type DeploymentRequest ¶
type DeploymentRequest struct {
Namespace string `json:"namespace"`
Name string `json:"name"`
Type DeploymentType `json:"type"`
Subdomain string `json:"subdomain,omitempty"`
// Content
ContentTarball []byte `json:"-"` // Binary data, not JSON
Environment map[string]string `json:"environment,omitempty"`
// Resource limits
MemoryLimitMB int `json:"memory_limit_mb,omitempty"`
CPULimitPercent int `json:"cpu_limit_percent,omitempty"`
// Health monitoring
HealthCheckPath string `json:"health_check_path,omitempty"`
// Routing
LoadBalanced bool `json:"load_balanced,omitempty"` // Create load-balanced DNS records
CustomDomain string `json:"custom_domain,omitempty"` // Optional custom domain
}
DeploymentRequest represents a request to create a new deployment
type DeploymentResponse ¶
type DeploymentResponse struct {
DeploymentID string `json:"deployment_id"`
Name string `json:"name"`
Namespace string `json:"namespace"`
Status string `json:"status"`
URLs []string `json:"urls"` // All URLs where deployment is accessible
Version int `json:"version"`
CreatedAt time.Time `json:"created_at"`
}
DeploymentResponse represents the result of a deployment operation
type DeploymentStatus ¶
type DeploymentStatus string
DeploymentStatus represents the current state of a deployment
const ( DeploymentStatusDeploying DeploymentStatus = "deploying" DeploymentStatusActive DeploymentStatus = "active" DeploymentStatusFailed DeploymentStatus = "failed" DeploymentStatusDegraded DeploymentStatus = "degraded" DeploymentStatusStopped DeploymentStatus = "stopped" DeploymentStatusUpdating DeploymentStatus = "updating" )
type DeploymentType ¶
type DeploymentType string
DeploymentType represents the type of deployment
const ( DeploymentTypeStatic DeploymentType = "static" // Static sites (React, Vite) DeploymentTypeNextJS DeploymentType = "nextjs" // Next.js SSR DeploymentTypeNextJSStatic DeploymentType = "nextjs-static" // Next.js static export DeploymentTypeGoBackend DeploymentType = "go-backend" // Go native binary DeploymentTypeGoWASM DeploymentType = "go-wasm" // Go compiled to WASM DeploymentTypeNodeJSBackend DeploymentType = "nodejs-backend" // Node.js/TypeScript backend )
type HomeNodeAssignment ¶
type HomeNodeAssignment struct {
Namespace string `json:"namespace"`
HomeNodeID string `json:"home_node_id"`
AssignedAt time.Time `json:"assigned_at"`
LastHeartbeat time.Time `json:"last_heartbeat"`
DeploymentCount int `json:"deployment_count"`
TotalMemoryMB int `json:"total_memory_mb"`
TotalCPUPercent int `json:"total_cpu_percent"`
}
HomeNodeAssignment maps a namespace to its home node
type HomeNodeManager ¶
type HomeNodeManager struct {
// contains filtered or unexported fields
}
HomeNodeManager manages namespace-to-node assignments
func NewHomeNodeManager ¶
func NewHomeNodeManager(db rqlite.Client, portAllocator *PortAllocator, logger *zap.Logger) *HomeNodeManager
NewHomeNodeManager creates a new home node manager
func (*HomeNodeManager) AssignHomeNode ¶
AssignHomeNode assigns a home node to a namespace (or returns existing assignment)
func (*HomeNodeManager) GetHomeNode ¶
GetHomeNode retrieves the home node for a namespace
func (*HomeNodeManager) GetStaleNamespaces ¶
func (hnm *HomeNodeManager) GetStaleNamespaces(ctx context.Context, staleThreshold time.Duration) ([]string, error)
GetStaleNamespaces returns namespaces that haven't sent a heartbeat recently
func (*HomeNodeManager) MigrateNamespace ¶
func (hnm *HomeNodeManager) MigrateNamespace(ctx context.Context, namespace, newNodeID string) error
MigrateNamespace moves a namespace from one node to another (used for node failures)
func (*HomeNodeManager) UpdateHeartbeat ¶
func (hnm *HomeNodeManager) UpdateHeartbeat(ctx context.Context, namespace string) error
UpdateHeartbeat updates the last heartbeat timestamp for a namespace
func (*HomeNodeManager) UpdateResourceUsage ¶
func (hnm *HomeNodeManager) UpdateResourceUsage(ctx context.Context, namespace string, deploymentCount, memoryMB, cpuPercent int) error
UpdateResourceUsage updates the cached resource usage for a namespace
type NodeCapacity ¶
type NodeCapacity struct {
NodeID string `json:"node_id"`
DeploymentCount int `json:"deployment_count"`
AllocatedPorts int `json:"allocated_ports"`
AvailablePorts int `json:"available_ports"`
UsedMemoryMB int `json:"used_memory_mb"`
AvailableMemoryMB int `json:"available_memory_mb"`
UsedCPUPercent int `json:"used_cpu_percent"`
AvailableDiskMB int64 `json:"available_disk_mb"`
Score float64 `json:"score"` // Calculated capacity score
}
NodeCapacity represents available resources on a node
type PortAllocation ¶
type PortAllocation struct {
NodeID string `json:"node_id"`
Port int `json:"port"`
DeploymentID string `json:"deployment_id"`
AllocatedAt time.Time `json:"allocated_at"`
}
PortAllocation represents an allocated port on a specific node
type PortAllocator ¶
type PortAllocator struct {
// contains filtered or unexported fields
}
PortAllocator manages port allocation across nodes
func NewPortAllocator ¶
func NewPortAllocator(db rqlite.Client, logger *zap.Logger) *PortAllocator
NewPortAllocator creates a new port allocator
func (*PortAllocator) AllocatePort ¶
func (pa *PortAllocator) AllocatePort(ctx context.Context, nodeID, deploymentID string) (int, error)
AllocatePort finds and allocates the next available port for a deployment on a specific node Port range: 10100-19999 (10000-10099 reserved for system use)
func (*PortAllocator) DeallocatePort ¶
func (pa *PortAllocator) DeallocatePort(ctx context.Context, deploymentID string) error
DeallocatePort removes a port allocation for a deployment
func (*PortAllocator) GetAllocatedPort ¶
func (pa *PortAllocator) GetAllocatedPort(ctx context.Context, deploymentID string) (int, string, error)
GetAllocatedPort retrieves the currently allocated port for a deployment
func (*PortAllocator) GetAvailablePortCount ¶
GetAvailablePortCount returns the number of available ports on a node
func (*PortAllocator) GetNodePortCount ¶
GetNodePortCount returns the number of allocated ports on a node
type Replica ¶
type Replica struct {
DeploymentID string `json:"deployment_id"`
NodeID string `json:"node_id"`
Port int `json:"port"`
Status ReplicaStatus `json:"status"`
IsPrimary bool `json:"is_primary"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Replica represents a deployment replica on a specific node
type ReplicaManager ¶
type ReplicaManager struct {
// contains filtered or unexported fields
}
ReplicaManager manages deployment replicas across nodes
func NewReplicaManager ¶
func NewReplicaManager(db rqlite.Client, homeNodeMgr *HomeNodeManager, portAllocator *PortAllocator, logger *zap.Logger) *ReplicaManager
NewReplicaManager creates a new replica manager
func (*ReplicaManager) CreateReplica ¶
func (rm *ReplicaManager) CreateReplica(ctx context.Context, deploymentID, nodeID string, port int, isPrimary bool, status ReplicaStatus) error
CreateReplica inserts a replica record for a deployment on a specific node.
func (*ReplicaManager) GetActiveReplicaNodes ¶
func (rm *ReplicaManager) GetActiveReplicaNodes(ctx context.Context, deploymentID string) ([]string, error)
GetActiveReplicaNodes returns node IDs of all active replicas for a deployment.
func (*ReplicaManager) GetReplicaPort ¶
func (rm *ReplicaManager) GetReplicaPort(ctx context.Context, deploymentID, nodeID string) (int, error)
GetReplicaPort returns the port allocated for a deployment on a specific node.
func (*ReplicaManager) GetReplicas ¶
GetReplicas returns all replicas for a deployment.
func (*ReplicaManager) IsReplicaNode ¶
func (rm *ReplicaManager) IsReplicaNode(ctx context.Context, deploymentID, nodeID string) (bool, error)
IsReplicaNode checks if the given node is an active replica for the deployment.
func (*ReplicaManager) RemoveReplicas ¶
func (rm *ReplicaManager) RemoveReplicas(ctx context.Context, deploymentID string) error
RemoveReplicas deletes all replica records for a deployment.
func (*ReplicaManager) SelectReplicaNodes ¶
func (rm *ReplicaManager) SelectReplicaNodes(ctx context.Context, primaryNodeID string, count int) ([]string, error)
SelectReplicaNodes picks additional nodes for replicas, excluding the primary node. Returns up to count node IDs.
func (*ReplicaManager) UpdateReplicaStatus ¶
func (rm *ReplicaManager) UpdateReplicaStatus(ctx context.Context, deploymentID, nodeID string, status ReplicaStatus) error
UpdateReplicaStatus updates the status of a specific replica.
type ReplicaStatus ¶
type ReplicaStatus string
ReplicaStatus represents the status of a deployment replica on a node
const ( ReplicaStatusPending ReplicaStatus = "pending" ReplicaStatusActive ReplicaStatus = "active" ReplicaStatusFailed ReplicaStatus = "failed" ReplicaStatusRemoving ReplicaStatus = "removing" )
type RestartPolicy ¶
type RestartPolicy string
RestartPolicy defines how a deployment should restart on failure
const ( RestartPolicyAlways RestartPolicy = "always" RestartPolicyOnFailure RestartPolicy = "on-failure" RestartPolicyNever RestartPolicy = "never" )
type RoutingType ¶
type RoutingType string
RoutingType defines how DNS routing works for a deployment
const ( RoutingTypeBalanced RoutingType = "balanced" // Load-balanced across nodes RoutingTypeNodeSpecific RoutingType = "node_specific" // Specific to one node )