Documentation
¶
Overview ¶
Package run is the `bitc run` pipeline (spec 6) and the local runner.
Index ¶
- Variables
- func ApplyHookEnv(env []string, kv []KV, bitc []string) []string
- func BaseEnv(in EnvInput) ([]string, error)
- func BitcVars(in EnvInput) []string
- func Debugf(p *Prepared, w io.Writer, format string, a ...any)
- func Main(ctx context.Context, inv Invocation) int
- func TemplateVars(eff *config.Effective, pool *config.Pool, hold *admit.Hold, job string) config.Vars
- func WrapArgv(eff *config.Effective, pool *config.Pool, vars config.Vars, argv []string) ([]string, error)
- func WriteResult(path string, r Result) error
- type EnvInput
- type ExecResult
- type ExecSpec
- type HookCall
- type HookKind
- type Invocation
- type KV
- type Outcome
- type Prepared
- type Result
- type RunArgs
- type Signalled
Constants ¶
This section is empty.
Variables ¶
var NoProviderLeft func(pool string, last error) error
NoProviderLeft maps the last provider failure to 69 or 75 (set by internal/remote).
var RemoteWalk func(ctx context.Context, inv Invocation, p *Prepared, provider string, stderr io.Writer) (Outcome, bool, error)
RemoteWalk runs a remote provider (internal/remote sets it). handled=false means "try the next"; err is then this provider's failure, for the no-provider-left rule.
Functions ¶
func ApplyHookEnv ¶
ApplyHookEnv applies env-hook output, then re-asserts the BITC_* variables.
func BaseEnv ¶
BaseEnv: caller env, minus [defaults].env_unset; env_default for unset keys; env; minus the pool's env_unset; then the BITC_* variables (spec 6.3). Host and repo already merged (5.3).
func Main ¶
func Main(ctx context.Context, inv Invocation) int
Main runs the whole pipeline in the foreground.
func TemplateVars ¶
func TemplateVars(eff *config.Effective, pool *config.Pool, hold *admit.Hold, job string) config.Vars
TemplateVars are [vars] plus {pool} and {job}; with a hold also the host-only variables.
func WrapArgv ¶
func WrapArgv(eff *config.Effective, pool *config.Pool, vars config.Vars, argv []string) ([]string, error)
WrapArgv prefixes the first wrap rule whose when_worktree matches the work tree (spec 6.5). It always returns a new slice, never argv itself, so a caller may change the result without touching argv (and the reverse).
func WriteResult ¶
WriteResult writes r atomically (temp + rename, 0600).
Types ¶
type EnvInput ¶
type EnvInput struct {
Caller []string
Eff *config.Effective
Pool *config.Pool
Hold *admit.Hold
Job string
Vars config.Vars
}
EnvInput is everything the job's environment derives from (spec 6.3).
type ExecResult ¶
type ExecResult struct {
Code int // the command's code, 128+N if it died of signal N, or 128+N after terminate; 124 after the time limit
TimedOut bool // the time limit ended the command (Code is exit.TimedOut)
Interrupted syscall.Signal // the signal bitc received, 0 if none
StartErr error // the command could not start (Code 126 or 127), or bitc could not record it (Code 69)
}
ExecResult is how the command ended.
func Exec ¶
func Exec(ctx context.Context, s ExecSpec) (ExecResult, error)
Exec runs the command as bitc's child and returns how it ended (spec 6.4).
The command is started through an exec gate (gate.go): its process exists, in its own group, but runs nothing until Started has recorded it. Signals bitc receives before the exec has happened are queued and forwarded once it has, so the command sees each of them as without a gate; the grace and max_signal_wait clocks start when the signal is received, not when it is forwarded. SIGKILL is never held.
type ExecSpec ¶
type ExecSpec struct {
Argv []string
Env []string
Dir string
Stdin *os.File
Stdout *os.File
Stderr *os.File
OnSignal string // "terminate" | "forward-and-wait"
Grace time.Duration
Timeout time.Duration // > 0: terminate the command this long after it started (spec 6.4)
MaxSignalWait time.Duration
// Started records the command's process. The command does not run until it returns: an error
// ends the run with code 69 and the command never executes.
Started func(pid, pgid int, leaderStart uint64) error
Pending chan os.Signal // optional: a channel the caller registered; Exec takes it over
NoHangup bool // detached supervisor (spec 7): SIGHUP is neither handled nor forwarded
// OnKill, if set, runs when the command is sent SIGKILL (the grace after a signal or the time
// limit has run out, or a forward-and-wait run gave up). A container's docker CLI dies without
// stopping its container: this is where the container is force-removed.
OnKill func()
}
ExecSpec is one command run under a hold (spec 6.4).
type HookCall ¶
type HookCall struct {
Kind HookKind
Hook config.Hook
Pool string
Vars config.Vars
Env []string
Worktree string
Stderr io.Writer
}
HookCall is one hook invocation.
type Invocation ¶
type Invocation struct {
Flags config.Flags
Args []string
Stdin *os.File
Stdout *os.File
Stderr *os.File
Env []string
Cwd string
// Detached is the supervisor's replay (spec 7): SIGHUP is neither a cancel nor forwarded.
Detached bool
// Pending, if set, is the supervisor's early signal channel; runLocal takes it over.
Pending chan os.Signal
}
Invocation is one `bitc run` call (or the supervisor's replay of one).
type KV ¶
type KV struct{ Name, Value string }
KV is one NAME=VALUE pair from an env hook.
func ParseEnvOutput ¶
ParseEnvOutput parses env-hook output (spec 6.5): one [export ]NAME=VALUE per line, blank and # lines skipped. VALUE concatenates unquoted chars (not blanks, control characters or ' " \ $ ` ; & | < > ( )), '...' literals and "..." with only \" \\ \` \$ escapes. No form admits a control character (< 0x20 or 0x7f). Never evaluated. A CR is a control character, so CRLF output is unparsable.
type Prepared ¶
type Prepared struct {
Args RunArgs
Eff *config.Effective
Pool *config.Pool
Layout state.Layout
Job string
Redact *redact.Set
}
Prepared is what steps 1-4 decided.
type Result ¶
type Result struct {
Origin string `json:"origin"` // "bitc" | "command"
Outcome string `json:"outcome"` // ok | command-failed | starved | refused | config | unavailable | interrupted | lost | internal
ExitCode int `json:"exit_code"`
Reason string `json:"reason,omitempty"`
Pool string `json:"pool"`
Slot int `json:"slot,omitempty"`
Provider string `json:"provider"`
Job string `json:"job"`
Generation int `json:"generation,omitempty"`
HoldStarted string `json:"hold_started,omitempty"`
Units map[string]int `json:"units,omitempty"` // units held per group
WaitMS int64 `json:"wait_ms"`
RunMS int64 `json:"run_ms"`
Head string `json:"head,omitempty"` // git rev-parse HEAD of the run's work tree at hold start
TreeClean *bool `json:"tree_clean,omitempty"` // git status --porcelain was empty then; absent outside a git tree
Cwd string `json:"cwd,omitempty"` // the run's working directory
}
Result is result.json (spec 4).
type RunArgs ¶
type RunArgs struct {
Detach bool
Name string
Log string
Wait string
Units map[string]int // --units G=K (repeatable), group canonical; nil if absent
Timeout string
Local bool
Provider string
Artifacts *[]string
Result string
Pool string
Argv []string
}
RunArgs are the parsed `bitc run` arguments (spec 3.1). Values stay raw; the config layer validates them (5.2).
func ParseRunArgs ¶
ParseRunArgs parses flags (before <pool>), the pool, an optional "--" and the argv.