state

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StateDir is the directory on the server where state is stored
	StateDir = "/var/lib/tako-cli"
	// MaxHistoryEntries is the maximum number of deployments to keep
	MaxHistoryEntries = 50
)

Variables

This section is empty.

Functions

func FormatDeploymentID

func FormatDeploymentID(id string) string

FormatDeploymentID formats a deployment ID for display

func FormatDuration

func FormatDuration(d time.Duration) string

FormatDuration formats a duration for display

func GetCurrentUser

func GetCurrentUser() string

GetCurrentUser returns the current system user for deployment tracking

Types

type DeploymentHistory

type DeploymentHistory struct {
	ProjectName string             `json:"projectName"`
	Server      string             `json:"server"`
	Deployments []*DeploymentState `json:"deployments"`
	LastUpdated time.Time          `json:"lastUpdated"`
}

DeploymentHistory contains all deployments for a project

type DeploymentState

type DeploymentState struct {
	ID          string                  `json:"id"`              // Unique deployment ID (timestamp-based)
	Timestamp   time.Time               `json:"timestamp"`       // When deployment occurred
	ProjectName string                  `json:"projectName"`     // Project name
	Version     string                  `json:"version"`         // Project version
	Status      DeploymentStatus        `json:"status"`          // success, failed, rolled_back
	Services    map[string]ServiceState `json:"services"`        // Deployed services
	User        string                  `json:"user"`            // Who deployed
	Host        string                  `json:"host"`            // Which server
	Duration    time.Duration           `json:"duration"`        // How long deployment took
	Message     string                  `json:"message"`         // Deployment message/notes
	Error       string                  `json:"error,omitempty"` // Error if failed
	// Git information
	GitCommit      string `json:"gitCommit,omitempty"`      // Full commit hash
	GitCommitShort string `json:"gitCommitShort,omitempty"` // Short commit hash (7 chars)
	GitBranch      string `json:"gitBranch,omitempty"`      // Branch name
	GitCommitMsg   string `json:"gitCommitMsg,omitempty"`   // Commit message
	GitAuthor      string `json:"gitAuthor,omitempty"`      // Commit author
	// CLI information
	CLIVersion string `json:"cliVersion,omitempty"` // Tako CLI version used for deployment
	CLICommit  string `json:"cliCommit,omitempty"`  // Tako CLI git commit hash
}

DeploymentState represents a single deployment's state

type DeploymentStatus

type DeploymentStatus string

DeploymentStatus represents deployment outcome

const (
	StatusInProgress DeploymentStatus = "in_progress"
	StatusSuccess    DeploymentStatus = "success"
	StatusFailed     DeploymentStatus = "failed"
	StatusRolledBack DeploymentStatus = "rolled_back"
)

type HealthCheckState

type HealthCheckState struct {
	Enabled   bool      `json:"enabled"`
	Path      string    `json:"path"`
	Healthy   bool      `json:"healthy"`
	LastCheck time.Time `json:"lastCheck"`
}

HealthCheckState represents health check status

type HistoryOptions

type HistoryOptions struct {
	Limit         int              // Max number of deployments to return
	Status        DeploymentStatus // Filter by status
	Service       string           // Filter by service name
	Since         time.Time        // Only deployments after this time
	IncludeFailed bool             // Include failed deployments
}

HistoryOptions for filtering deployment history

type ServiceState

type ServiceState struct {
	Name        string            `json:"name"`
	Image       string            `json:"image"`       // Image name with tag
	ImageID     string            `json:"imageId"`     // Docker image ID
	ContainerID string            `json:"containerId"` // Running container ID
	Port        int               `json:"port"`
	Replicas    int               `json:"replicas"`
	Env         map[string]string `json:"env"`
	HealthCheck HealthCheckState  `json:"healthCheck"`
}

ServiceState represents a deployed service's state

type StateManager

type StateManager struct {
	// contains filtered or unexported fields
}

StateManager manages deployment state on remote servers

func NewStateManager

func NewStateManager(client *ssh.Client, projectName, server string) *StateManager

NewStateManager creates a new state manager

func (*StateManager) CleanupOldDeployments

func (s *StateManager) CleanupOldDeployments() error

CleanupOldDeployments removes old deployment records

func (*StateManager) GetDeployment

func (s *StateManager) GetDeployment(deploymentID string) (*DeploymentState, error)

GetDeployment retrieves a specific deployment by ID

func (*StateManager) GetLatestSuccessful

func (s *StateManager) GetLatestSuccessful() (*DeploymentState, error)

GetLatestSuccessful returns the most recent successful deployment

func (*StateManager) GetPreviousDeployment

func (s *StateManager) GetPreviousDeployment(currentID string) (*DeploymentState, error)

GetPreviousDeployment returns the deployment before the current one

func (*StateManager) Initialize

func (s *StateManager) Initialize() error

Initialize ensures the state directory exists on the server

func (*StateManager) ListDeployments

func (s *StateManager) ListDeployments(opts *HistoryOptions) ([]*DeploymentState, error)

ListDeployments lists all deployments with optional filtering

func (*StateManager) LoadHistory added in v0.2.4

func (s *StateManager) LoadHistory() (*DeploymentHistory, error)

LoadHistory returns the deployment history from the remote server.

func (*StateManager) SaveDeployment

func (s *StateManager) SaveDeployment(deployment *DeploymentState) error

SaveDeployment saves a deployment state to the server with retry logic

type StateReplicator added in v0.2.4

type StateReplicator struct {
	// contains filtered or unexported fields
}

StateReplicator replicates deployment state from the manager node to worker nodes as read-only backups. If the manager loses state, it can be recovered from any worker. Replication is fire-and-forget — failures are logged as warnings and never block or fail a deployment.

func NewStateReplicator added in v0.2.4

func NewStateReplicator(pool *ssh.Pool, cfg *config.Config, environment, projectName string, verbose bool) *StateReplicator

NewStateReplicator creates a new state replicator.

func (*StateReplicator) RecoverStateFromWorkers added in v0.2.4

func (r *StateReplicator) RecoverStateFromWorkers() (*DeploymentHistory, string, error)

RecoverStateFromWorkers attempts to recover deployment history from worker nodes. It reads history.json from all workers in parallel and returns the one with the most recent LastUpdated timestamp. Returns (nil, "", nil) if no worker has state.

func (*StateReplicator) RecoverSwarmTokensFromWorkers added in v0.2.4

func (r *StateReplicator) RecoverSwarmTokensFromWorkers() ([]byte, string, error)

RecoverSwarmTokensFromWorkers attempts to recover encrypted swarm tokens from worker nodes. Returns the first non-empty result found. Returns (nil, "", nil) if no worker has tokens.

func (*StateReplicator) ReplicateDeployment added in v0.2.4

func (r *StateReplicator) ReplicateDeployment(deployment *DeploymentState, history *DeploymentHistory)

ReplicateDeployment replicates a deployment and its history to all worker nodes. It returns immediately — the actual replication runs in a background goroutine with a 30-second hard timeout. Errors are logged as warnings.

func (*StateReplicator) ReplicateSwarmTokens added in v0.2.4

func (r *StateReplicator) ReplicateSwarmTokens(encryptedData []byte)

ReplicateSwarmTokens replicates pre-encrypted swarm token data to all worker nodes. Returns immediately with a 15-second background timeout.

Jump to

Keyboard shortcuts

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