Documentation
¶
Overview ¶
Package config loads and merges bitc's TOML files (spec 5). model.go is the effective configuration every other package reads.
Index ¶
- Constants
- Variables
- func CanonName(s string) string
- func Explain(e *Effective, key string) []string
- func FormatDuration(d time.Duration) string
- func GenerateReference() string
- func IsBuiltInType(typ string) bool
- func IsFixedType(typ string) bool
- func LeftoverHint(typ string) string
- func LoopbackLiteral(ep string) bool
- func Match(pattern, name string) (bool, error)
- func ParseDuration(s string) (time.Duration, error)
- func ParseInt(s string) (int64, error)
- func RegisterProviderType(name string, t ProviderType)
- func RemoteLeftovers(e *Effective) []string
- func SecretLikeName(name string) bool
- func SetPlatformForTest(goos string) (restore func())
- func UnconfiguredLeftovers(e *Effective) []string
- func ValidEnvName(s string) bool
- func ValidGlob(pattern string) error
- func ValidPoolName(s string) bool
- func ValidSizeKey(s string) bool
- type Agent
- type Artifact
- type ArtifactLimits
- type Breaker
- type Compat
- type Container
- type Detach
- type Effective
- type Flags
- type Flock
- type Group
- type Hook
- type Hooks
- type Host
- type LoadOptions
- type Micros
- type Mount
- type Part
- type PluginPin
- type Pool
- type PoolRemote
- type Priority
- type Provider
- type ProviderType
- type RefuseRule
- type RemoteLimits
- type RepoGrant
- type RepoRemote
- type RunFlags
- type Service
- type Size
- type Step
- type Template
- type Test
- type Tool
- type Transport
- type Vars
- type WrapRule
Constants ¶
const ( TransportGitPush = "git-push" TransportUpload = "upload" DefaultMaxBundle = Size(1 << 30) MaxBundleLimit = Size(8 << 30) )
The transport kinds, and the bounds of transport.max_bundle.
const BuiltinKnownHosts = `` /* 827-byte string literal not displayed */
BuiltinKnownHosts are GitHub's published SSH host keys (spec 8.4), updated per release. Verify with: printf '%s\n' "$BuiltinKnownHosts" | ssh-keygen -lf -
const ExperimentalRemoteCleanup = "To clean up resources left by an earlier version, set the flag and run bitc sweep."
ExperimentalRemoteCleanup follows the refusal for sweep, doctor --remote and a host that an earlier version left remote reservations or ledger lines on.
const ExperimentalRemoteRefusal = "remote providers are experimental in this release and off by default; " +
"their spend accounting is still under review (see https://github.com/Exploded-views/bitc#known-issues). " +
"To use them anyway, set [host] experimental_remote = true."
ExperimentalRemoteRefusal is the config problem for a remote provider without [host] experimental_remote = true (README "Known issues").
const ModulePath = "github.com/Exploded-views/bitc"
ModulePath is this module's path, the one a module_dir tree must declare.
const SpritesRefusal = "Sprites jobs are refused in this release: the network policy bitc sets is now " +
"correct (it ends in a deny-all rule), but enabling Sprites jobs is still tracked in " +
"https://github.com/Exploded-views/bitc/issues/6. `bitc sweep` can still clean up Sprites left by " +
"0.1.0 (see https://github.com/Exploded-views/bitc#known-issues)."
SpritesRefusal is the config problem for any [providers.sprites] table or a pool naming sprites on every path but a cleanup: Sprites jobs are refused in this release, with or without experimental_remote, until enabling them (#6) is done; the network policy itself is already correct. A cleanup (sweep, doctor --remote: LoadOptions.Cleanup) gets the provider as CleanupOnly instead.
Variables ¶
var ( HostOnlyVars = map[string]bool{"slot": true, "slots": true, "hold": true, "state_dir": true, "worktree": true, "cwd": true} RemoteOnlyVars = map[string]bool{"week": true, "sha256": true} )
HostOnlyVars exist only on the host; RemoteOnlyVars only in a remote job (spec 5.7).
var Architectures = []string{"amd64", "arm64"}
Architectures are the linux architectures bitc delivers an agent for (spec 8.4 step 1).
var Runtimes = []string{"docker"}
Runtimes are the container runtimes bitc drives. OrbStack and Docker Desktop provide the docker CLI.
Functions ¶
func Explain ¶
Explain lists effective values with their source (spec 3). Credentials print <redacted>.
func FormatDuration ¶ added in v0.1.4
FormatDuration is d in the spec's duration grammar (5.2), largest units first: 90m is "1h30m". A duration that is not whole milliseconds is rounded up to the next one.
func GenerateReference ¶
func GenerateReference() string
GenerateReference renders docs/config-reference.md from the schema's struct tags (spec 5.4).
func IsBuiltInType ¶
IsBuiltInType reports whether typ names a built-in provider (registered or reserved).
func IsFixedType ¶
IsFixedType reports whether typ is a registered fixed-capacity provider type.
func LeftoverHint ¶ added in v0.1.1
LeftoverHint is doctor's warn detail and sweep's hint for a type in UnconfiguredLeftovers.
func LoopbackLiteral ¶
LoopbackLiteral reports whether an endpoint (a host, host:port or URL) is a loopback IP literal.
func Match ¶
Match is path.Match per "/" segment, where a "**" segment matches zero or more segments. name is a canonical absolute path.
func ParseDuration ¶
ParseDuration accepts <int><unit>[<int><unit>...] with units ms s m h d (spec 5.2).
func ParseInt ¶
ParseInt accepts 0 or [1-9][0-9]* (spec 5.2; no leading zero, sign, unit or fraction).
func RegisterProviderType ¶
func RegisterProviderType(name string, t ProviderType)
RegisterProviderType adds or replaces a provider type (called from provider packages' init).
func RemoteLeftovers ¶ added in v0.1.1
RemoteLeftovers lists, sorted, the provider types whose remote/<type>/reservations.json in the accounting dir lists a job: a run that never finished (bitc was killed, the host lost power), whose resource may still exist and cost money until a sweep with that provider configured removes it. The ledger is not used: it is append-only, so its lines only say that remote jobs ran once, and a sweep closes no launch. It only reads, never creates the dir, and never blocks.
func SecretLikeName ¶
SecretLikeName reports whether a variable or key name looks like a secret (spec 8.4).
func SetPlatformForTest ¶ added in v0.1.3
func SetPlatformForTest(goos string) (restore func())
SetPlatformForTest makes Load check configs against goos (a test seam for other packages' tests; the in-package tests set platformGOOS directly). Test-only: never call it from product code. It returns the restore function.
func UnconfiguredLeftovers ¶ added in v0.1.1
UnconfiguredLeftovers is RemoteLeftovers without the types the host configures (a sweep of those removes what is left): what doctor and sweep point out on their own.
func ValidEnvName ¶
ValidEnvName accepts ^[A-Za-z_][A-Za-z0-9_]*$ not starting BITC_ (spec 5.2).
func ValidPoolName ¶
func ValidSizeKey ¶
Types ¶
type Agent ¶
type Agent struct {
Source string // "release" | "url" | "build"
URL string
Path string
Commit string // build: the pinned commit of the job repo (40 hex)
Image string // build: the pod image, <name>@sha256:<64 hex>
SHA256 string // build: the sha256 the built binary must have
// Paths maps an architecture to the local file whose sha256 is sent (source = "url"); the
// legacy Path is folded into Paths["amd64"] at load.
Paths map[string]string
// ModuleDir is a bitc source tree the host builds the agent from (source = "build" without
// commit, image and sha256; providers delta C.4 item 3).
ModuleDir string
}
type ArtifactLimits ¶
type Container ¶ added in v0.1.6
type Container struct {
Image string
Runtime string // "docker"
Mounts []Mount // extra bind mounts, after the work tree's
CPUs string // the value for --cpus ("" = no limit)
Memory Size // the value for --memory in bytes (0 = no limit)
}
Container is pools.<p>.container: a local pool that runs the admitted command in a container (docs/containers.md). Host file only.
type Effective ¶
type Effective struct {
HostFile string // "" if no host file exists
RepoFile string // "" if no repo file applies
Worktree string // canonical work-tree top (5.1)
WT8 string // 8 hex of sha256(Worktree)
Cwd string // canonical cwd
LogicalCwd string // $PWD when it names Cwd, else Cwd
Host Host
Pools map[string]*Pool // canonical name -> pool
Groups map[string]Group
Priority Priority
Detach Detach
RemoteLimits RemoteLimits
Providers map[string]*Provider // provider type -> section
Repos []RepoGrant
Grant *RepoGrant // first [[repos]] entry matching Worktree, or nil
Remote *RepoRemote // the repo's [remote] table, or nil
Vars Vars // merged [vars], host wins
Compat *Compat
Test *Test
EnvProvider string // BITC_PROVIDER ("" or "local")
EnvArtifacts *[]string // BITC_ARTIFACTS (nil if unset)
GlobalFlags Flags // the global flags Load was given
LogLevel string // BITC_LOG: "info" (default), "debug" or "quiet" (1.2b sets it; -v raises info to debug, 1.7)
Sources map[string]string // effective key -> "default" | file path | "env BITC_X" | "flag --x"
Secrets []string // credential values loaded, for redaction
DefaultPool *Pool // template for ad-hoc pools when Host.UnknownPools == "default"
Warnings []string // non-fatal config notes, one line each; `config check` prints them to stderr
// contains filtered or unexported fields
}
Effective is the merged, validated configuration for one invocation.
func Load ¶
func Load(o LoadOptions) (*Effective, error)
Load reads built-in defaults, the host file, one repo file and BITC_* env (spec 5.1-5.6). File problems are 78 (all listed); malformed BITC_* values are 64.
func (*Effective) ApplyRunFlags ¶
ApplyRunFlags records `run` narrowing flags; Resolve applies them to the pool (5.3).
type Flags ¶
type Flags struct {
ConfigFile string // --config
StateDir string // --state-dir
Verbose int // -v (repeatable)
JSON bool // --json
}
Flags are bitc's global flags (spec 3).
type Flock ¶ added in v0.1.6
type Flock struct {
Lock string // flock(1) target of bare callers
Gate string // turnstile taken before Lock
Slot string // slot file template, "{n}" is the slot number
// Exclusive: the pool holds Gate and Lock exclusive and takes no slot file (a bench); default
// false, a normal pool.
Exclusive bool
}
Flock names the files of a shell pool built on one lock file (spec 12.2).
type Host ¶
type Host struct {
StateDir string
Poll time.Duration
MemoryFloor Size
ReservationWindow time.Duration
UnknownPools string // "refuse" | "default"
Grace time.Duration
MaxSignalWait time.Duration
HistoryMax Size
Retention time.Duration
// ExperimentalRemote: [host] experimental_remote, the opt-in remote providers need. Host file
// only: no repo key and no BITC_* variable sets it.
ExperimentalRemote bool
}
type LoadOptions ¶
type LoadOptions struct {
Flags Flags
Env []string // the caller's environment, KEY=VALUE
Cwd string // os.Getwd() of the caller
RepoFile string // `config check --repo FILE`: use FILE as the repo file
// Cleanup: the caller is sweep or doctor --remote, so a refusal for remote providers says how
// to clean up what an earlier version left.
Cleanup bool
}
LoadOptions are Load's inputs.
type Micros ¶
type Micros int64
Micros is US dollars in micro-dollars.
func ParseMoney ¶
ParseMoney accepts a TOML number >= 0 with at most 4 decimals (spec 5.2).
type Mount ¶ added in v0.1.6
Mount is one bind mount: Source on the host at Target in the container.
type Part ¶
Part is one piece of a template: a literal, or {Var}, {Var+Arg} or {Var-Arg}. {sha256:<path>} is Var "sha256" with Arg <path> and Op ":".
func ParseTemplate ¶
ParseTemplate splits raw into parts; {{ and }} are literal braces.
type PluginPin ¶
type PluginPin struct {
Path string
SHA256 string
EnvPass []string
SecretFiles map[string]string // name -> file (home expanded), 0600 and owned by the user
}
PluginPin is the host-only plugin table of a provider section (A.2): an absolute path and a sha256, env names passed through, and secret files read at spawn and sent on fd 3.
type Pool ¶
type Pool struct {
Name string
AdHoc bool
Slots int
Wait time.Duration
Timeout time.Duration // 0: no limit on a local run
Memory Size // 0: no memory admission
Groups map[string]int // group -> units consumed
GroupsMax map[string]int // group -> most units a run may ask for with --units (absent: the group's units)
Providers []string // effective list, host order
DefaultsEnvUnset []string // [defaults].env_unset (both layers): applied first
EnvDefault map[string]Template
Env map[string]Template
EnvUnset []string // pool env_unset (both layers): applied after Env
Refuse []RefuseRule
OnSignal string // "terminate" | "forward-and-wait"
Hooks Hooks
RemoteSize map[string]string // provider type -> size key
RemoteTimeout time.Duration
Remote *PoolRemote // repo [pools.<p>.remote], nil if absent
Container *Container // host [pools.<p>.container]: run local commands in a container, nil if absent
}
type PoolRemote ¶
type Provider ¶
type Provider struct {
Type string
Fixed bool // fixed capacity: slots, no API key (providers delta C.3)
// CleanupOnly: jobs of this type are refused in this release (sprites); a cleanup (sweep,
// doctor --remote) may only list, owner-check and delete its resources, through the type's
// provider.Factory.NewCleaner, never New.
CleanupOnly bool
NamePrefix string
APIKey string // never printed
APIKeyFile string
DailyUSD Micros
MaxLive int
LaunchWait time.Duration
StartTimeout time.Duration
Breaker Breaker
Transport Transport
Agent Agent
Artifacts ArtifactLimits
// FallbackUntil is the effective fallback boundary, "resource" or "attach" (spec 8.2): the
// host key fallback_until, never later than the type's declaration (FallbackCap).
FallbackUntil string
FallbackCap string
// SendEnv is the effective caller-env level, "none", "forwarded" or "forced" (providers delta
// S.2); SendEnvSource is "default" or "host". MultiJob: the type's resources serve more than
// one job (S.4).
SendEnv string
SendEnvSource string
MultiJob bool
Raw map[string]any // provider-specific keys, decoded by the provider (8.5)
Endpoints []string // hosts the provider talks to (8.1), for the [test] gate
// Plugin is set for a plugin type (spec 8.5, providers delta A.2): the pinned executable.
// Sizes then holds the required host price per size (A.7.1) and SizesRaw the sizes table as
// decoded, both passed to the plugin's configure.
Plugin *PluginPin
Sizes map[string]Micros
SizesRaw map[string]any
}
type ProviderType ¶
type ProviderType struct {
Endpoints func(raw map[string]any) ([]string, error)
TestOnly bool // accepted only with a [test] table (the fake provider)
// FallbackCap is the latest fallback boundary the type declares ("resource" or "attach", spec
// 8.2) for these provider-specific keys; nil means "resource".
FallbackCap func(raw map[string]any) string
// DefaultResource: fallback_until defaults to "resource" whatever FallbackCap says (a plugin
// is trusted to attach only after the host opts in, spec 8.2).
DefaultResource bool
// SendEnv is the type's default caller-env level for these provider-specific keys ("none",
// "forwarded" or "forced"); nil means "forwarded" (a plugin). MultiJob reports whether its
// resources serve more than one job (providers delta S.4); nil means false.
SendEnv func(raw map[string]any) string
MultiJob func(raw map[string]any) bool
// Validate checks the provider-specific keys once the core keys are decoded; each message is
// the text after `providers.<type>.` (a 78 at load).
Validate func(core *Provider) []string
// Fixed: a fixed-capacity type (ssh, providers delta C.3). It has no API key, daily_usd is
// the type's own rule (Validate), and max_live defaults to MaxLiveDefault of its keys.
Fixed bool
MaxLiveDefault func(raw map[string]any) int
}
ProviderType is what core needs from a provider before M2: its endpoints, for the [test] gate. Provider packages register their types from init.
type RefuseRule ¶
type RemoteLimits ¶
type RepoRemote ¶
type RunFlags ¶
type RunFlags struct {
Wait string // --wait raw value, "" if absent
Timeout string // --timeout raw value, "" if absent
Local bool // --local
Provider string // --provider P
Artifacts *[]string // --artifacts a,b (nil if absent)
Units map[string]int // --units G=K, group canonical (nil if absent)
}
RunFlags are the narrowing flags of `bitc run` (spec 3.1, 5.3).
type Size ¶
type Size int64
Size is a byte count ("<int><KiB|MiB|GiB|TiB>").
type Template ¶
type Template struct{ Raw string }
Template is a string with {name} substitutions (spec 5.7).
type Test ¶
type Test struct {
ProcfsRoot string
TimeScale float64 // (0, 1]; 0 means 1
HTTPResults bool
AgentURL string
AccountingDir string
// FixedSecrets makes the job's B, K and M fixed values (see remote.jobSecrets), so a suite that
// cannot see them in the clear can still look for them in what a plugin or fake recorded.
FixedSecrets bool
// SSHExec = "local" makes the ssh provider run the executable SSHGate (with SSHRoot as the
// fake host's state) instead of the system ssh client (providers delta C.11, sshfake).
SSHExec, SSHGate, SSHRoot string
// SSHSshd names the program doctor runs in place of `sshd -T` for the tunnel account check
// (providers delta C.6.3), so a test needs no root and no sshd.
SSHSshd string
// AllowSprites: [test] allow_sprites, the sprites refusal's test-only bypass (spritesRefused).
AllowSprites bool
}
type Tool ¶
type Tool struct{ Name, Arch, URL, SHA256 string }
Tool is a sha256-pinned download; Arch is "amd64" or "arm64" (default "amd64").
type Transport ¶
type Transport struct {
Remote string
RefPrefix string
KnownHosts string // OpenSSH known_hosts text
// Kind is TransportGitPush (the default) or TransportUpload (ssh only: the commit goes to
// the host as a git bundle on the gate session). MaxBundle bounds that bundle.
Kind string
MaxBundle Size
}