runner

package
v0.9.6 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package runner is the CI-side driver: it invokes the same terramate scripts a human runs, captures per-stack output, renders + classifies in-process, and reports progress to the control-plane server over the typed events protocol.

This file is the server client. All reporting is best-effort by design — a down or absent server degrades the build to "no live progress", never to failure — except the apply-time gate check (see gate.go), which is fail-closed. An empty server URL disables the client entirely, so local runs and the no-op `run tick` need no server.

Index

Constants

View Source
const (
	EnvServer      = "TFSTACKPLAN_SERVER"      // control-plane base URL ("" = offline, no-op)
	EnvToken       = "TFSTACKPLAN_TOKEN"       // bearer secret for /api/*
	EnvExecution   = "TFSTACKPLAN_EXECUTION"   // execution id this run reports under
	EnvStack       = "TFSTACKPLAN_STACK"       // current stack path (fallback for `run tick --stack`)
	EnvEnvironment = "TFSTACKPLAN_ENVIRONMENT" // deployment environment for the execution
)

Environment variables the orchestrator (`run plan`/`run apply`) sets and the per-stack `run tick` reads, so progress reporting needs no flags threaded through the terramate scripts. Empty TFSTACKPLAN_SERVER disables reporting.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client posts execution lifecycle events to the control-plane server.

func ClientFromEnv

func ClientFromEnv() *Client

ClientFromEnv builds a Client from TFSTACKPLAN_SERVER + TFSTACKPLAN_TOKEN. When the server var is empty the client is disabled (every call is a no-op).

func NewClient

func NewClient(baseURL, secret string) *Client

NewClient builds a client for the server at baseURL (empty disables it) using the given bearer secret. A short timeout keeps a slow/down server from stalling the build.

func (*Client) Enabled

func (c *Client) Enabled() bool

Enabled reports whether a server is configured. When false, every call is a no-op returning nil.

func (*Client) Finalize

func (c *Client) Finalize(ctx context.Context, f events.Finalize) error

Finalize records the terminal plan state (report, gates, moving/failed).

func (*Client) GateCheck

func (c *Client) GateCheck(ctx context.Context, g events.GateCheck) (string, error)

GateCheck is the apply-time, fail-closed gate pre-check. Returns the leased requester SA (when the server reports one) so the caller can impersonate it. No server ⇒ ("", nil) — nothing gates. A 409, any other non-2xx, or an unreachable configured server ⇒ error (apply blocks).

func (*Client) GateRevoke

func (c *Client) GateRevoke(ctx context.Context, g events.GateRevoke) error

GateRevoke asks the server to revoke the grants it requested (best-effort post-apply cleanup).

func (*Client) Init

func (c *Client) Init(ctx context.Context, in events.Init) error

Init registers the execution and its changed subgraph.

func (*Client) LogChunk

func (c *Client) LogChunk(ctx context.Context, lc events.LogChunk) error

LogChunk streams a slice of one stack's output to the server (best-effort).

func (*Client) Phase

func (c *Client) Phase(ctx context.Context, p events.PhaseEvent) error

Phase narrates a lifecycle phase transition.

func (*Client) Update

func (c *Client) Update(ctx context.Context, u events.Update) error

Update ticks a single stack's status.

type LogPump

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

LogPump tails each stack's on-disk log file and posts newly-appended bytes to the server. It is the parallel-safe path to per-stack logs: terramate's combined `script run` stream interleaves stacks with no per-stack attribution, so by convention each stack's script writes its own file (`<root>/<stack>/<file>`, e.g. via `terraform plan ... 2>&1 | tee tfstackplan.log`) and the pump tails it. All posts are best-effort.

func NewLogPump

func NewLogPump(p logPoster, root, file, execID string) *LogPump

NewLogPump builds a pump that posts via p, reading the file named `file` in each stack dir under root, tagging chunks with execID.

func (*LogPump) Start

func (lp *LogPump) Start(stacks []string) (stop func())

Start begins tailing in the background and returns a stop function that does a final flush and waits for the goroutine to exit. The pump runs in a single goroutine, so offsets need no locking.

type ScriptRunOptions

type ScriptRunOptions struct {
	Script   string // the terramate script name (e.g. "plan")
	Changed  bool   // --changed: only changed stacks
	Parallel int    // --parallel N (0 = terramate default)
	Base     string // -B <ref> for change detection
}

ScriptRunOptions controls `terramate script run`.

type Terramate

type Terramate struct {
	Bin string // terramate binary; defaults to "terramate"
	Dir string // project root (process cwd for every invocation)
}

Terramate shells out to the terramate binary. Dir is the project root: it is set as the process working directory (so asdf resolves the project's .tool-versions and terramate operates on that tree) — no --chdir is used.

func (*Terramate) ChangedStacks

func (t *Terramate) ChangedStacks(ctx context.Context, base string) ([]string, error)

ChangedStacks returns the stacks changed relative to base (empty uses terramate's configured default).

func (*Terramate) List

func (t *Terramate) List(ctx context.Context) ([]string, error)

List returns every stack path in the project.

func (*Terramate) RunGraph

func (t *Terramate) RunGraph(ctx context.Context) ([]events.Edge, error)

RunGraph returns the stack dependency edges (From must run before To), derived from `terramate experimental run-graph -l stack.dir`.

func (*Terramate) ScriptRun

func (t *Terramate) ScriptRun(ctx context.Context, w io.Writer, o ScriptRunOptions) error

ScriptRun runs a terramate script across (changed) stacks, streaming combined output to w. It returns terramate's exit error (so a failed stack fails the run).

Jump to

Keyboard shortcuts

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