Documentation
¶
Index ¶
- Variables
- func RunStreaming(ctx context.Context, dl *DeployLog, name string, args ...string) (stdout, stderr string, err error)
- type AuditEmitter
- type CommandRunner
- type DeployAuditEvent
- type DeployLog
- type DeployResult
- type Deployer
- func (d *Deployer) Cancel(ctx context.Context, app *compose.AppConfig) error
- func (d *Deployer) Deploy(ctx context.Context, app *compose.AppConfig, auths ...RegistryAuth) (result DeployResult)
- func (d *Deployer) Pull(ctx context.Context, app *compose.AppConfig, auths []RegistryAuth) DeployResult
- func (d *Deployer) Restart(ctx context.Context, app *compose.AppConfig) DeployResult
- func (d *Deployer) RollbackDeploy(ctx context.Context, app *compose.AppConfig, version int, ...) (result DeployResult)
- func (d *Deployer) Scale(ctx context.Context, app *compose.AppConfig, scales map[string]int) error
- func (d *Deployer) SetAuditEmitter(a AuditEmitter)
- func (d *Deployer) Start(ctx context.Context, projectName string) error
- func (d *Deployer) Status(ctx context.Context, projectName string) ([]ServiceStatus, error)
- func (d *Deployer) Stop(ctx context.Context, projectName string) error
- func (d *Deployer) Teardown(ctx context.Context, projectName string) error
- type ExecRunner
- type MockRunner
- type OutputLine
- type RegistryAuth
- type RunCall
- type ServiceState
- type ServiceStatus
- type Tracker
- func (t *Tracker) Cancel(slug string) error
- func (t *Tracker) Done(slug string)
- func (t *Tracker) DoneWithLog(slug string, action string)
- func (t *Tracker) DoneWithLogStatus(slug, action, status string, services []ServiceState)
- func (t *Tracker) IsDeploying(slug string) bool
- func (t *Tracker) Subscribe(slug string) (<-chan OutputLine, func(), bool)
- func (t *Tracker) Track(slug string, cancel context.CancelFunc)
- func (t *Tracker) TrackWithLog(slug string, cancel context.CancelFunc) (*DeployLog, bool)
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 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) 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) 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) 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) 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.
type ExecRunner ¶
type ExecRunner struct{}
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
}
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 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 Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
func NewTracker ¶
func NewTracker() *Tracker
func (*Tracker) DoneWithLog ¶
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 (*Tracker) Subscribe ¶
func (t *Tracker) Subscribe(slug string) (<-chan OutputLine, func(), bool)
func (*Tracker) TrackWithLog ¶
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.