provision

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package provision orchestrates container provisioning steps via zmx. After SSH bootstrap (handled by rc.local), the Runner SSHes into the container as root, installs zmx, and executes named provisioning steps using zmx run. Each step runs in its own pty session, enabling structured status tracking (zmx list), output capture (zmx history), and interactive debugging on failure (zmx attach).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Script

func Script(steps []Step) string

Script generates a self-contained provisioning shell script that installs zmx and runs the given steps concurrently. The script is designed to be written to the container rootfs and invoked from rc.local via nohup.

func StepNames

func StepNames(steps []Step) []string

StepNames returns the names of the given steps.

Types

type Executor added in v0.4.0

type Executor interface {
	// Exec runs a command and returns its exit code.
	Exec(ctx context.Context, command []string) (int, error)
	// Output runs a command and returns its stdout.
	Output(ctx context.Context, command []string) ([]byte, error)
}

Executor runs commands on a remote host.

type MockExecutor added in v0.4.0

type MockExecutor struct {
	ExecFunc   func(ctx context.Context, command []string) (int, error)
	OutputFunc func(ctx context.Context, command []string) ([]byte, error)
}

MockExecutor is a test double for Executor.

func (*MockExecutor) Exec added in v0.4.0

func (m *MockExecutor) Exec(ctx context.Context, command []string) (int, error)

func (*MockExecutor) Output added in v0.4.0

func (m *MockExecutor) Output(ctx context.Context, command []string) ([]byte, error)

type Runner

type Runner struct {
	Host    string
	User    string // typically "root"
	KeyPath string
	Log     io.Writer
	// contains filtered or unexported fields
}

Runner executes and monitors zmx provisioning steps over SSH.

func NewRunner added in v0.4.0

func NewRunner(host, user, keyPath, knownHostsPath string) *Runner

NewRunner creates a Runner that executes commands over SSH.

func NewRunnerWith added in v0.4.0

func NewRunnerWith(exec Executor) *Runner

NewRunnerWith creates a Runner using the provided Executor. This is intended for testing.

func (*Runner) HasProvisionScript

func (r *Runner) HasProvisionScript(ctx context.Context) bool

HasProvisionScript checks if the provision script was written to the container.

func (*Runner) History

func (r *Runner) History(ctx context.Context, name string) (string, error)

History returns the scrollback output of a completed zmx session.

func (*Runner) IsProvisioned

func (r *Runner) IsProvisioned(ctx context.Context) bool

IsProvisioned checks if the provision sentinel file exists.

func (*Runner) List

func (r *Runner) List(ctx context.Context) (string, error)

List runs zmx list and returns the raw output. The caller can display this directly or parse it for structured status information.

func (*Runner) PollStatus

func (r *Runner) PollStatus(ctx context.Context, names []string) (string, bool)

PollStatus checks zmx list and returns a human-readable status string and whether all expected steps are done. Returns ("", false) if zmx isn't ready yet or the list fails.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, step Step) error

Run starts a provisioning step via zmx run. The command returns immediately; the step executes in the background inside its own pty session.

func (*Runner) Wait

func (r *Runner) Wait(ctx context.Context, names ...string) error

Wait blocks until all named zmx sessions complete.

func (*Runner) WaitProvisioned

func (r *Runner) WaitProvisioned(ctx context.Context, setStatus func(string))

WaitProvisioned polls until provisioning completes, calling setStatus with zmx step progress along the way. Returns immediately if no provisioning is expected or already complete.

type Session

type Session struct {
	Name     string
	EndedAt  string // unix timestamp or empty if still running
	ExitCode string // exit code or empty if still running
}

Session holds parsed fields from a zmx list output line.

func ParseSessions

func ParseSessions(raw string) []Session

ParseSessions parses zmx list output into sessions.

type Step

type Step struct {
	Name     string // zmx session name (e.g., "px-egress")
	Script   string // shell command to execute inside zmx
	Finalize string // optional: runs after ALL steps complete (not tracked by zmx)
}

Step defines a named provisioning task to run via zmx.

func Steps

func Steps(egress string, devtools bool) []Step

Steps returns the provisioning steps to execute based on configuration. All steps run concurrently via zmx. Steps with a Finalize script have that script executed after ALL steps complete — this allows egress lockdown to be deferred until devtools finishes downloading.

Jump to

Keyboard shortcuts

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