state

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultLeaseTTL = 30 * time.Minute
View Source
const MaxHistoryEntries = 50

Variables

View Source
var ErrNotFound = errors.New("takod state document not found")

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"`
	Environment string             `json:"environment,omitempty"`
	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
	Environment string                  `json:"environment,omitempty"`
	Version     string                  `json:"version"`         // Project version
	Status      DeploymentStatus        `json:"status"`          // success, warmed, 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"
	StatusWarmed     DeploymentStatus = "warmed"
	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 LeaseInfo added in v0.3.0

type LeaseInfo struct {
	ID          string    `json:"id"`
	ProjectName string    `json:"projectName"`
	Environment string    `json:"environment"`
	Operation   string    `json:"operation"`
	Who         string    `json:"who"`
	PID         int       `json:"pid"`
	CreatedAt   time.Time `json:"createdAt"`
	ExpiresAt   time.Time `json:"expiresAt"`
}

LeaseInfo describes a remote takod deployment lease.

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 history through the node-local takod state API.

func NewStateManager

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

NewStateManager creates a state manager that uses the default takod socket.

func NewStateManagerWithSocket added in v0.3.0

func NewStateManagerWithSocket(client *ssh.Client, projectName, environment, server, socket string) *StateManager

NewStateManagerWithSocket creates a state manager using a configured takod socket.

func (*StateManager) AcquireLease added in v0.3.0

func (s *StateManager) AcquireLease(operation, environment string, ttl time.Duration) (*LeaseInfo, error)

AcquireLease acquires the remote deployment lease for this project.

func (*StateManager) AcquireLeaseContext added in v0.7.0

func (s *StateManager) AcquireLeaseContext(ctx context.Context, operation, environment string, ttl time.Duration) (*LeaseInfo, error)

AcquireLeaseContext acquires the remote deployment lease bounded by ctx.

func (*StateManager) CleanupOldDeployments

func (s *StateManager) CleanupOldDeployments() error

CleanupOldDeployments prunes old entries from the history document.

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 is retained for callers that want to eagerly validate state access.

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 takod state.

func (*StateManager) LoadHistoryContext added in v0.7.0

func (s *StateManager) LoadHistoryContext(ctx context.Context) (*DeploymentHistory, error)

LoadHistoryContext returns the deployment history from takod state bounded by ctx.

func (*StateManager) ReadLease added in v0.3.0

func (s *StateManager) ReadLease() (*LeaseInfo, error)

ReadLease returns the currently held remote lease, or nil if none exists.

func (*StateManager) ReadLeaseContext added in v0.7.0

func (s *StateManager) ReadLeaseContext(ctx context.Context) (*LeaseInfo, error)

ReadLeaseContext returns the currently held remote lease bounded by ctx, or nil if none exists.

func (*StateManager) ReleaseLease added in v0.3.0

func (s *StateManager) ReleaseLease(lease *LeaseInfo) error

ReleaseLease releases the remote lease if it is still owned by this process.

func (*StateManager) ReleaseLeaseContext added in v0.7.0

func (s *StateManager) ReleaseLeaseContext(ctx context.Context, lease *LeaseInfo) error

ReleaseLeaseContext releases the remote lease if it is still owned by this process, bounded by ctx and the cleanup timeout.

func (*StateManager) SaveDeployment

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

SaveDeployment saves a deployment state with retry logic.

func (*StateManager) SaveDeploymentContext added in v0.7.0

func (s *StateManager) SaveDeploymentContext(ctx context.Context, deployment *DeploymentState) error

SaveDeploymentContext saves a deployment state with retry logic bounded by ctx.

func (*StateManager) SaveHistory added in v0.3.0

func (s *StateManager) SaveHistory(history *DeploymentHistory) error

SaveHistory writes a full deployment history document through takod.

func (*StateManager) SaveHistoryContext added in v0.7.0

func (s *StateManager) SaveHistoryContext(ctx context.Context, history *DeploymentHistory) error

SaveHistoryContext writes a full deployment history document through takod bounded by ctx.

func (*StateManager) WithRequestTimeout added in v0.4.16

func (s *StateManager) WithRequestTimeout(timeout time.Duration) *StateManager

WithRequestTimeout returns a shallow copy that uses a custom takod request deadline. A non-positive timeout keeps the package default.

type StateReplicator added in v0.2.4

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

StateReplicator replicates deployment history across the takod mesh.

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) ReplicateDeployment added in v0.2.4

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

ReplicateDeployment replicates a deployment and its history to every environment mesh node using the legacy 30s background timeout. Writes are idempotent, so including the node that initially saved the deployment is acceptable.

func (*StateReplicator) ReplicateDeploymentContext added in v0.7.0

func (r *StateReplicator) ReplicateDeploymentContext(ctx context.Context, deployment *DeploymentState, history *DeploymentHistory) error

ReplicateDeploymentContext replicates a deployment and its history to every environment mesh node, bounded by both ctx and the legacy 30s timeout.

Jump to

Keyboard shortcuts

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