Documentation
¶
Overview ¶
Package whoosh is the public plugin SDK: it lets an out-of-tree module author a whoosh plugin (and lets the built-in plugins use the very same contract) without importing whoosh's internal packages. The binary entrypoint lives in a separate package (github.com/yousysadmin/whoosh/entrypoint) so importing the SDK does not pull in the CLI.
The types here are aliases of whoosh's internal types, so a plugin written against this package is the exact same contract the built-in plugins use, both register into the same registry. To scaffold a plugin, copy the standalone example module under examples/plugins/hello, and build with `whoosh build`.
The two-phase plugin contract ¶
A plugin contributes in two moments, on two surfaces:
- Configure time (Plugin.Configure): the config is not resolved yet, so only the Registry is available - reg.AddAction registers named actions, reg.AddStartup registers a startup hook. A typical Configure just validates/decodes the PluginSpec params and defers everything else to a startup closure.
- Startup time (the StartupFunc): the resolved *DeployFile is passed in and may be mutated - cfg.AddTask, cfg.AddHookBefore/After, cfg.AddHookFuncBefore/After, cfg.AddPhase, cfg.AddImport, or appending to cfg.Hosts (inventory). These methods are startup-time only, there is no config to mutate at Configure time.
A plugin's Version() (the Versioner interface) is self-declared and unrelated to the whoosh binary's version.
Index ¶
- Constants
- func AddSecret(s string)
- func DecodeParams(params map[string]any, target any) error
- func DecodeParamsStrict(params map[string]any, target any) error
- func IsRegistered(name string) bool
- func Masking(s string) string
- func MergeParams(base, over map[string]any) map[string]any
- func Or[T any](p *T, fallback T) T
- func OrZero[T comparable](v, fallback T) T
- func Register(name string, f Factory)
- func RegisterDefault(name string, f Factory)
- func Registered() []string
- func WithHostCommandCapturer(ctx context.Context, c HostCommandCapturer) context.Context
- func WithHostCommandRunner(ctx context.Context, r HostCommandRunner) context.Context
- func WithHostFileWriter(ctx context.Context, w HostFileWriter) context.Context
- type ActionFunc
- type Command
- type CommandFunc
- type Commander
- type CustomPhase
- type DeployFile
- type Factory
- type HookFunc
- type Hooks
- type Host
- type HostCommandCapturer
- type HostCommandRunner
- type HostFileWriter
- type Plugin
- type PluginActionSpec
- type PluginSpec
- type Registry
- type Script
- type StartupFunc
- type Task
- type Versioner
Constants ¶
const ( PhaseStarting = ast.PhaseStarting PhaseCheck = ast.PhaseCheck PhaseInit = ast.PhaseInit PhaseStarted = ast.PhaseStarted PhaseUpdating = ast.PhaseUpdating PhaseSymlink = ast.PhaseSymlink PhaseUpdated = ast.PhaseUpdated PhasePublishing = ast.PhasePublishing PhasePublished = ast.PhasePublished PhaseFinishing = ast.PhaseFinishing PhaseFinished = ast.PhaseFinished PhaseFailed = ast.PhaseFailed PhaseRollback = ast.PhaseRollback )
Built-in deploy phase names, in lifecycle order - the hook anchors a plugin targets with cfg.AddHookBefore/After, cfg.AddHookFuncBefore/After, or as a cfg.AddPhase anchor. Re-exported so a plugin never hardcodes the strings. PhaseFailed (after-only, fires on a failed deployment) and PhaseRollback (wraps the rollback swap) are hook points outside the lifecycle order.
const HostSourceConfig = ast.HostSourceConfig
HostSourceConfig is the Host.Source value for a host declared in the Deployfile, an inventory plugin sets its own source string (conventionally its feature name, e.g. "aws:ec2:inventory") on the hosts it appends.
Variables ¶
This section is empty.
Functions ¶
func AddSecret ¶
func AddSecret(s string)
AddSecret registers a literal value so whoosh redacts it from all output (echoed commands, command output, logs, dry-run plans). Use it for any secret a plugin fetches. Re-exports the internal masking registry.
func DecodeParams ¶
DecodeParams maps an untyped params map into a typed struct via a YAML round trip, so a plugin can use ordinary structs with YAML tags. Unknown keys are ignored - use DecodeParamsStrict when the struct defines the whole params surface.
func DecodeParamsStrict ¶ added in v1.7.0
DecodeParamsStrict is DecodeParams with unknown keys rejected, so a misspelled param errors at load instead of silently applying the default.
func IsRegistered ¶
IsRegistered reports whether a plugin with this name is compiled in.
func Masking ¶
Masking returns s with every registered secret and known secret pattern masked - the same transform whoosh applies to its output. Useful in a plugin's tests to assert a value passed to AddSecret is masked.
func MergeParams ¶ added in v1.7.0
MergeParams returns base with over layered on top (over wins) - the standard way to layer a task's `with:` over a plugin's action defaults. Nested map[string]any values merge recursively, every other value (scalars, slices) is replaced wholesale. A nil base yields a copy of over. Inputs are not mutated, and nested maps are copied rather than aliased, so writing into the result never edits the plugin's shared defaults.
func Or ¶ added in v1.7.0
func Or[T any](p *T, fallback T) T
Or returns *p when set, else fallback - the default for an optional pointer param (*bool, *int32, ...) left unset.
func OrZero ¶ added in v1.7.0
func OrZero[T comparable](v, fallback T) T
OrZero returns v when non-zero, else fallback - the default for an optional scalar param where the zero value ("" or 0) means unset.
func Register ¶
Register makes a plugin available under name. Call it from a plugin package's init(), duplicate names panic.
func RegisterDefault ¶
RegisterDefault is like Register but also marks the plugin always-on: it loads in every stage unless a Deployfile lists it disabled (enabled: false, or only/except excluding the stage). For zero-config convenience plugins.
func Registered ¶
func Registered() []string
Registered returns the names of every plugin compiled into this binary, sorted. Mirrors what the `whoosh plugins` command prints.
func WithHostCommandCapturer ¶ added in v1.6.0
func WithHostCommandCapturer(ctx context.Context, c HostCommandCapturer) context.Context
WithHostCommandCapturer returns ctx carrying c (the executor sets this before an action runs). Plugin authors rarely call this, use HostCommandCapturerFrom.
func WithHostCommandRunner ¶ added in v1.2.0
func WithHostCommandRunner(ctx context.Context, r HostCommandRunner) context.Context
WithHostCommandRunner returns ctx carrying r (the executor sets this before an action runs). Plugin authors rarely call this, use HostCommandRunnerFrom.
func WithHostFileWriter ¶
func WithHostFileWriter(ctx context.Context, w HostFileWriter) context.Context
WithHostFileWriter returns ctx carrying w (the executor sets this before an action runs). Plugin authors rarely call this, use HostFileWriterFrom.
Types ¶
type ActionFunc ¶
type ActionFunc = plugins.ActionFunc
ActionFunc is a named action invoked by a task's `action:`/`with:`.
type Command ¶
Command is a CLI subcommand a plugin contributes (`whoosh <stage> <Name>`), declared via the Commander interface.
type CommandFunc ¶
type CommandFunc = plugins.CommandFunc
CommandFunc runs a plugin Command with the resolved config, the registry, the console writer, and the command's positional args.
type Commander ¶
Commander is the optional interface a plugin implements to contribute CLI commands, Commands() is queried (on a bare instance) to register them.
type CustomPhase ¶
type CustomPhase = ast.CustomPhase
CustomPhase is a named phase a plugin can splice into the deployment lifecycle before/after a built-in phase via DeployFile.AddPhase.
type DeployFile ¶
type DeployFile = ast.DeployFile
DeployFile is the resolved config a StartupFunc receives (and may mutate, e.g. cfg.AddTask / cfg.AddHookAfter / cfg.AddPhase / cfg.AddImport).
type HookFunc ¶
HookFunc is a plugin function run before/after a deployment phase with the deploy's console writer, registered via DeployFile.AddHookFuncBefore/After. It lets a plugin emit operator-side output (or run code) at a phase without contributing a task. Runs only during the deploy lifecycle.
type HostCommandCapturer ¶ added in v1.6.0
type HostCommandCapturer = plugins.HostCommandCapturer
HostCommandCapturer runs a shell command on the first host an action task targets and returns its trimmed stdout.
func HostCommandCapturerFrom ¶ added in v1.6.0
func HostCommandCapturerFrom(ctx context.Context) HostCommandCapturer
HostCommandCapturerFrom returns the HostCommandCapturer carried by an action's ctx, or nil if none (e.g. an action invoked outside the executor).
type HostCommandRunner ¶ added in v1.2.0
type HostCommandRunner = plugins.HostCommandRunner
HostCommandRunner runs a shell command on an action task's hosts.
func HostCommandRunnerFrom ¶ added in v1.2.0
func HostCommandRunnerFrom(ctx context.Context) HostCommandRunner
HostCommandRunnerFrom returns the HostCommandRunner carried by an action's ctx, or nil if none (e.g. an action invoked outside the executor).
type HostFileWriter ¶
type HostFileWriter = plugins.HostFileWriter
HostFileWriter renders a generated file onto an action task's hosts.
func HostFileWriterFrom ¶
func HostFileWriterFrom(ctx context.Context) HostFileWriter
HostFileWriterFrom returns the HostFileWriter carried by an action's ctx, or nil if none (e.g. an action invoked outside the executor).
type PluginActionSpec ¶
type PluginActionSpec = ast.PluginActionSpec
PluginActionSpec is one entry of PluginSpec.Actions.
type PluginSpec ¶
type PluginSpec = ast.PluginSpec
PluginSpec is the plugin's Deployfile entry (params + per-action config).
type Registry ¶
Registry is the shared space a plugin registers its actions/startup into.
func Load ¶
func Load(specs []PluginSpec) (*Registry, error)
Load configures every declared plugins and returns the populated registry. Mainly for tests: build a registry, then invoke an action via reg.Action(name).
type StartupFunc ¶
type StartupFunc = plugins.StartupFunc
StartupFunc runs once at load and may mutate the resolved config.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
gen-schema
command
|
|
|
whoosh-core
command
|
|
|
Package entrypoint is the whoosh binary entrypoint, kept separate from the SDK.
|
Package entrypoint is the whoosh binary entrypoint, kept separate from the SDK. |
|
internal
|
|
|
cli
Package cli wires up the whoosh command-line interface.
|
Package cli wires up the whoosh command-line interface. |
|
cli/builder
Package builder implements the `whoosh build` subcommand: it composes a custom whoosh binary that bundles the plugins you choose - including your own private or third-party plugin modules.
|
Package builder implements the `whoosh build` subcommand: it composes a custom whoosh binary that bundles the plugins you choose - including your own private or third-party plugin modules. |
|
deploy
Package deploy orchestrates the release lifecycle: it builds a timestamped release from git on every host, links shared files/dirs into it, atomically swaps the current symlink, and prunes old releases.
|
Package deploy orchestrates the release lifecycle: it builds a timestamped release from git on every host, links shared files/dirs into it, atomically swaps the current symlink, and prunes old releases. |
|
deploy/hooks
Package hooks runs the user-defined tasks wired to deploy phases.
|
Package hooks runs the user-defined tasks wired to deploy phases. |
|
deploy/scm
Package scm builds the shell commands that fetch source onto a target host.
|
Package scm builds the shell commands that fetch source onto a target host. |
|
deployfile
Package deployfile loads and merges the Deployfile configuration that drives a deployment: a shared Deployfile.yml plus a per-stage deploy/<stage>.yml.
|
Package deployfile loads and merges the Deployfile configuration that drives a deployment: a shared Deployfile.yml plus a per-stage deploy/<stage>.yml. |
|
deployfile/ast
Package ast is the Deployfile data model: the structs the YAML unmarshals into, plus the pure transforms over them (Merge, ApplyDefaults, Validate, the version gate, AsMap, and the host filters).
|
Package ast is the Deployfile data model: the structs the YAML unmarshals into, plus the pure transforms over them (Merge, ApplyDefaults, Validate, the version gate, AsMap, and the host filters). |
|
errors
Package errors defines whoosh's typed errors and their process exit codes.
|
Package errors defines whoosh's typed errors and their process exit codes. |
|
executor
Package executor runs Deployfile tasks: it resolves task dependencies, renders each command against the deploy context, and executes it either locally or across the hosts matching the task's roles (reusing SSH connections).
|
Package executor runs Deployfile tasks: it resolves task dependencies, renders each command against the deploy context, and executes it either locally or across the hosts matching the task's roles (reusing SSH connections). |
|
logger
Package logger builds slog handlers: a logger that fans out across one or more sinks (New, via slog.NewMultiHandler).
|
Package logger builds slog handlers: a logger that fans out across one or more sinks (New, via slog.NewMultiHandler). |
|
masking
Package masking scrubs secrets from text before it reaches the console or logs.
|
Package masking scrubs secrets from text before it reaches the console or logs. |
|
operator
Package operator resolves the identity of the person (or CI job) running whoosh, used for the deploy lock info, the revisions log, and the {{.deployer}} / $DEPLOYER template context.
|
Package operator resolves the identity of the person (or CI job) running whoosh, used for the deploy lock info, the revisions log, and the {{.deployer}} / $DEPLOYER template context. |
|
paths
Package paths computes the on-target directory layout for a deployment.
|
Package paths computes the on-target directory layout for a deployment. |
|
plugins
Package plugins is whoosh's plugins framework.
|
Package plugins is whoosh's plugins framework. |
|
runner
Package runner executes commands across a set of targets, independent of transport.
|
Package runner executes commands across a set of targets, independent of transport. |
|
shtmpl
Package shtmpl renders the embedded shell-command templates used by the deploy, scm, and executor packages.
|
Package shtmpl renders the embedded shell-command templates used by the deploy, scm, and executor packages. |
|
transport/local
Package local provides a command transport that runs on the operator's own machine via /bin/sh -c, with no SSH connection.
|
Package local provides a command transport that runs on the operator's own machine via /bin/sh -c, with no SSH connection. |
|
varstmpl
Package varstmpl renders command strings and scripts from Deployfile tasks.
|
Package varstmpl renders command strings and scripts from Deployfile tasks. |
|
plugins
|
|
|
core
Package core blank-imports the plugins whoosh ships with ("owned" plugins).
|
Package core blank-imports the plugins whoosh ships with ("owned" plugins). |
|
core/print_hosts_table
Package print_hosts_table is a zero-config standard plugins that prints the resolved inventory (the hosts table) at the start of every deploy.
|
Package print_hosts_table is a zero-config standard plugins that prints the resolved inventory (the hosts table) at the start of every deploy. |
|
core/systemd
Package systemd is the standard `systemd` plugin: it manages systemd units on the deploy hosts through six actions - systemd:start, systemd:stop, systemd:restart, systemd:enable, systemd:disable, and systemd:daemon-reload.
|
Package systemd is the standard `systemd` plugin: it manages systemd units on the deploy hosts through six actions - systemd:start, systemd:stop, systemd:restart, systemd:enable, systemd:disable, and systemd:daemon-reload. |
|
aws
module
|
|
|
rbenv
module
|
|
|
slack
module
|
|
|
transport
|
|
|
ssh
Package ssh provides the SSH transport for whoosh: dialing target hosts, running commands with streamed output, and fanning a command out across a set of hosts in parallel.
|
Package ssh provides the SSH transport for whoosh: dialing target hosts, running commands with streamed output, and fanning a command out across a set of hosts in parallel. |