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

deployer

package
v1.4.5 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDeployInProgress = errors.New("a deploy is already running for this app, try again when it finishes")

ErrDeployInProgress is returned for an action that cannot run because a deploy (or rollback, restart, pull) of the same app is still running.

View Source
var StabilizeTimeout = func() time.Duration {
	if v := os.Getenv("SIMPLEDEPLOY_STABILIZE_TIMEOUT"); v != "" {
		if d, err := time.ParseDuration(v); err == nil {
			return d
		}
	}
	return 30 * time.Second
}()

StabilizeTimeout is the max time we wait for containers to settle after `docker compose up -d` returns. Configurable for tests; also overridable at process start via SIMPLEDEPLOY_STABILIZE_TIMEOUT (e.g. "5s" for e2e).

Functions

func RunStreaming

func RunStreaming(ctx context.Context, dl *DeployLog, name string, args ...string) (stdout, stderr string, err error)

RunStreaming runs a command, streaming output lines to the DeployLog while also buffering full stdout/stderr for the return value.

Types

type AuditEmitter

type AuditEmitter interface {
	RecordDeploy(ctx context.Context, e DeployAuditEvent)
}

AuditEmitter records deploy outcomes. Concrete impl is a thin adapter in cmd/simpledeploy/main.go that converts to audit.RecordReq. Defined here as an interface so internal/deployer does not import internal/audit.

type CommandRunner

type CommandRunner interface {
	Run(ctx context.Context, name string, args ...string) (stdout, stderr string, err error)
}

type ComposeError added in v1.4.5

type ComposeError struct {
	Op     string // "compose up", "compose pull", ...
	Detail string
	Err    error
}

ComposeError is a failed docker compose command. Detail is the end of its error output, which says why it failed (image pull denied, port in use, ...), with registry credentials removed. It is what the deploy failure shows in the activity feed and the logs; the full output stays in the deploy log and deploy events.

func (*ComposeError) Error added in v1.4.5

func (e *ComposeError) Error() string

func (*ComposeError) Unwrap added in v1.4.5

func (e *ComposeError) Unwrap() error

type DeployAuditEvent

type DeployAuditEvent struct {
	AppID            int64 // 0 when unknown (deployer layer has no DB access)
	AppSlug          string
	Action           string // "deploy_succeeded", "deploy_failed", "rollback"
	Version          int
	ComposeVersionID *int64
	Error            string
}

DeployAuditEvent is the payload passed to AuditEmitter.RecordDeploy.

type DeployLog

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

func (*DeployLog) Close

func (dl *DeployLog) Close(action string)

func (*DeployLog) CloseWith

func (dl *DeployLog) CloseWith(action, status string, services []ServiceState)

CloseWith closes the log with extra status info captured by a post-deploy stabilization check. status is "success", "unstable", or "failed". services may be nil when no stabilization ran (e.g. compose itself failed).

func (*DeployLog) Send

func (dl *DeployLog) Send(line OutputLine)

func (*DeployLog) Subscribe

func (dl *DeployLog) Subscribe() (<-chan OutputLine, func())

type DeployResult

type DeployResult struct {
	Output  string
	Err     error
	Skipped bool // true when another deploy for the same slug was already in flight
	// Status is the post-stabilization outcome: "success", "unstable", or
	// "failed". "" when no stabilization ran (Skipped or composeErr present
	// before the check).
	Status   string
	Services []ServiceState
}

type Deployer

type Deployer struct {
	Tracker *Tracker
	// contains filtered or unexported fields
}

func New

func New(runner CommandRunner) (*Deployer, error)

func (*Deployer) Cancel

func (d *Deployer) Cancel(ctx context.Context, app *compose.AppConfig) error

func (*Deployer) Deploy

func (d *Deployer) Deploy(ctx context.Context, app *compose.AppConfig, auths ...RegistryAuth) (result DeployResult)

func (*Deployer) Pull

func (d *Deployer) Pull(ctx context.Context, app *compose.AppConfig, auths []RegistryAuth) DeployResult

func (*Deployer) Restart

func (d *Deployer) Restart(ctx context.Context, app *compose.AppConfig) DeployResult

func (*Deployer) RollbackDeploy

func (d *Deployer) RollbackDeploy(ctx context.Context, app *compose.AppConfig, version int, composeVersionID *int64, auths ...RegistryAuth) (result DeployResult)

RollbackDeploy redeploys app from its current compose file (already written to disk by the caller) and emits a "rollback" audit event. The version and composeVersionID fields are set by the caller via opts.

func (*Deployer) Scale

func (d *Deployer) Scale(ctx context.Context, app *compose.AppConfig, scales map[string]int) error

func (*Deployer) SetAuditEmitter

func (d *Deployer) SetAuditEmitter(a AuditEmitter)

SetAuditEmitter wires in an AuditEmitter so Deploy/RollbackDeploy emit audit rows. Safe to call after construction; nil-safe at emit time.

func (*Deployer) Start

func (d *Deployer) Start(ctx context.Context, projectName string) error

func (*Deployer) Status

func (d *Deployer) Status(ctx context.Context, projectName string) ([]ServiceStatus, error)

func (*Deployer) Stop

func (d *Deployer) Stop(ctx context.Context, projectName string) error

func (*Deployer) Teardown

func (d *Deployer) Teardown(ctx context.Context, projectName string) error

type ExecRunner

type ExecRunner struct{}

func (*ExecRunner) Run

func (r *ExecRunner) Run(ctx context.Context, name string, args ...string) (string, string, error)

type MockRunner

type MockRunner struct {
	Calls []RunCall
	Err   error
	// Respond optionally returns a custom response per call. If nil or returns
	// ok=false, the default empty/Err response is used. Useful for tests that
	// need to script different docker subcommand outputs (e.g. stabilize).
	Respond func(call RunCall) (stdout, stderr string, err error, ok bool)
	// contains filtered or unexported fields
}

func (*MockRunner) HasCall

func (m *MockRunner) HasCall(name string, subArgs ...string) bool

func (*MockRunner) Run

func (m *MockRunner) Run(_ context.Context, name string, args ...string) (string, string, error)

type OutputLine

type OutputLine struct {
	Line     string         `json:"line"`
	Stream   string         `json:"stream"` // "stdout" or "stderr"
	Done     bool           `json:"done"`
	Action   string         `json:"action,omitempty"`   // set on done: "deploy", "pull_failed", etc.
	Status   string         `json:"status,omitempty"`   // set on done: "success", "unstable", "failed"
	Services []ServiceState `json:"services,omitempty"` // set on done when a stabilization check ran
}

type RegistryAuth

type RegistryAuth struct {
	URL      string
	Username string
	Password string
}

type RunCall

type RunCall struct {
	Name string
	Args []string
}

type ServiceState

type ServiceState struct {
	Service      string `json:"service"`
	State        string `json:"state"`         // running, restarting, exited, etc.
	Health       string `json:"health"`        // healthy, unhealthy, starting, "" (no healthcheck)
	RestartCount int    `json:"restart_count"` // delta during the stabilization window
	ExitCode     int    `json:"exit_code"`
}

ServiceState captures the post-deploy state of one compose service for the stabilization summary.

type ServiceStatus

type ServiceStatus struct {
	Service string `json:"service"`
	State   string `json:"state"`
	Health  string `json:"health"`
}

type Tracker

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

func NewTracker

func NewTracker() *Tracker

func (*Tracker) Cancel

func (t *Tracker) Cancel(slug string) error

func (*Tracker) Done

func (t *Tracker) Done(slug string)

func (*Tracker) DoneWithLog

func (t *Tracker) DoneWithLog(slug string, action string)

func (*Tracker) DoneWithLogStatus

func (t *Tracker) DoneWithLogStatus(slug, action, status string, services []ServiceState)

DoneWithLogStatus closes a deploy with stabilization status + per-service detail.

func (*Tracker) IsDeploying

func (t *Tracker) IsDeploying(slug string) bool

func (*Tracker) Subscribe

func (t *Tracker) Subscribe(slug string) (<-chan OutputLine, func(), bool)

func (*Tracker) Track

func (t *Tracker) Track(slug string, cancel context.CancelFunc)

func (*Tracker) TrackWithLog

func (t *Tracker) TrackWithLog(slug string, cancel context.CancelFunc) (*DeployLog, bool)

TrackWithLog registers an in-flight deploy and returns a fresh DeployLog. Returns (nil, false) if a deploy for the same slug is already in flight; the caller must skip its own docker compose invocation to avoid clobbering the existing subscribers and racing compose on the same project.

Jump to

Keyboard shortcuts

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