Help us shape the future of Go! Take the 2026 Go Developer Survey

stack

package
v1.4.14 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Package stack executes the shared upgrade plan with a durable recovery journal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecutionPlan

func ExecutionPlan() []plan.Step

ExecutionPlan adapts the shared plan to stack execution after pins are updated. Inputs: shared DefaultSteps. Outputs: backup, pull, build, start and checks. Constraints: plugin and CLI pin application remain owned by update --yes.

func RestartCommand

func RestartCommand(snapshot string) string

RestartCommand restarts the pinned previous images and removes orphans, never volumes. Inputs: snapshot path. Outputs: executable compose command.

func RestoreCommand

func RestoreCommand(backupID string) string

RestoreCommand quotes an exact retained backup id for an operator shell command. Inputs: backup id. Outputs: executable restore guidance. Constraints: shell metacharacters in backup identifiers cannot execute commands.

func ResumeStep

func ResumeStep(j *Journal) string

ResumeStep reports the operation a real invocation would attempt next. Inputs: validated journal. Outputs: next step name or empty for blocked recovery. Constraints: completed and recovered runs begin a fresh backup on the next run.

func VerifyCommand

func VerifyCommand(backupID string) string

VerifyCommand quotes the command that re-checks a retained backup. Inputs: backup id. Outputs: executable verify guidance.

func WithExitClass

func WithExitClass(err error) error

WithExitClass binds the stack failure class ahead of any nested process exit. Inputs: structured stack error with its original cause. Outputs: explicit exit error. Constraints: E139 remains exit 2 and E403 remains exit 4 in both output modes.

Types

type Backend

type Backend interface {
	Backup(context.Context, *Journal) error
	VerifyBackup(context.Context, *Journal) error
	Run(context.Context, string, *Journal) error
	CheckPreviousImages(context.Context, *Journal) error
	StopServices(context.Context, *Journal) error
	Restore(context.Context, *Journal) error
	RestartPrevious(context.Context, *Journal) error
	CountRows(context.Context) (map[string]int64, error)
}

Backend connects ordered plan execution to existing project operations. Inputs: context and durable journal. Outputs: operation errors and backup proof. Constraints: operations must be idempotent; never delete backups or volumes.

type Journal

type Journal struct {
	RunID                 string           `json:"run_id"`
	StartedAt             time.Time        `json:"started_at"`
	Status                string           `json:"status"`
	Prod                  bool             `json:"prod"`
	BackupID              string           `json:"backup_id,omitempty"`
	BackupSHA256          string           `json:"backup_sha256,omitempty"`
	BackupCreatedAt       time.Time        `json:"backup_created_at,omitempty"`
	BackupVerifiedAt      time.Time        `json:"backup_verified_at,omitempty"`
	PreviousCompose       string           `json:"previous_compose,omitempty"`
	PreviousComposeSHA256 string           `json:"previous_compose_sha256,omitempty"`
	BeforeRows            map[string]int64 `json:"before_rows,omitempty"`
	AfterRows             map[string]int64 `json:"after_rows,omitempty"`
	Steps                 []Step           `json:"steps"`
}

Journal preserves every fact needed to resume or recover a stack update. Inputs: completed operation evidence. Outputs: atomic project state. Constraints: production classification cannot change during resume.

func Execute

func Execute(ctx context.Context, o Options, b Backend) (*Journal, error)

Execute runs or resumes the ordered stack plan after authorization. Inputs: caller-held operation lock, options and idempotent backend. Outputs: final journal and a coded failure. Constraints: dry runs write nothing.

type Options

type Options struct {
	ProjectDir string
	Prod       bool
	Yes        bool
	DryRun     bool
	Confirm    func(string) bool
}

Options selects the project and authorizes mutations. Inputs: caller-resolved environment and confirmation callback. Outputs: execution policy. Constraints: dry runs never call the backend.

type Runtime

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

Runtime owns the adapters for one consented stack update.

func NewRuntime

func NewRuntime(dir string, cfg *config.Config, stderr io.Writer) *Runtime

NewRuntime prepares adapters without reading or mutating the project.

func (*Runtime) Backup

func (r *Runtime) Backup(ctx context.Context, j *Journal) error

Backup snapshots immutable old images and creates a newly named full dump.

func (*Runtime) CheckPreviousImages

func (r *Runtime) CheckPreviousImages(ctx context.Context, j *Journal) error

CheckPreviousImages proves every pinned previous image still exists locally. Inputs: journal snapshot. Outputs: error naming the first missing image. Constraints: read only (`docker image inspect`); runs before anything is stopped.

func (*Runtime) CountRows

func (r *Runtime) CountRows(ctx context.Context) (map[string]int64, error)

CountRows records exact database counts with the existing backup count oracle.

func (*Runtime) RestartPrevious

func (r *Runtime) RestartPrevious(ctx context.Context, j *Journal) error

RestartPrevious starts only the immutable snapshot and removes services it lacks. Inputs: verified snapshot. Outputs: restart or health error. Constraints: `up -d --remove-orphans` removes containers, never volumes.

func (*Runtime) Restore

func (r *Runtime) Restore(ctx context.Context, j *Journal) error

Restore refuses production independently of caller policy and restores only pg.

func (*Runtime) Run

func (r *Runtime) Run(ctx context.Context, name string, j *Journal) error

Run dispatches one shared-plan stack step; unknown steps fail closed.

func (*Runtime) StopServices

func (r *Runtime) StopServices(ctx context.Context, j *Journal) error

StopServices stops every current app service so no new-image process writes during restore. Inputs: the current project Compose manifest. Outputs: stop error. Constraints: `compose stop` only; postgres stays up, no container or volume is removed.

func (*Runtime) VerifyBackup

func (r *Runtime) VerifyBackup(ctx context.Context, j *Journal) error

VerifyBackup proves identity, freshness and unchanged bytes using backup.Verify.

type Step

type Step struct {
	Name       string `json:"name"`
	Result     string `json:"result"`
	DurationMS int64  `json:"duration_ms"`
}

Step records one execution result for human and JSON output. Inputs: plan name and measured execution. Outputs: resumable step state. Constraints: names and order are checked when loading a journal.

Jump to

Keyboard shortcuts

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