remote

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 42 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package remote runs a job on a remote provider (spec 8.2-8.4) with the shared rails.

Index

Constants

This section is empty.

Variables

View Source
var (
	OnLaunch      func(j *Job)
	OnBegin       func(j *Job)
	OnEnd         func(j *Job, outcome string) // a code, "75", "fallback" (nothing created) or "interrupted"
	OnFailure     func(j *Job)                 // a 75 after BEGIN (never an interrupt)
	OnUnavailable func(j *Job, why string)     // a provider-side ErrUnavailable: one pause record
)

Ledger and breaker hooks (set by internal/remote/rails); nil means no-op.

View Source
var (
	// Preflight returns *provider.ErrIneligible (or ErrUnavailable for credentials).
	Preflight = func(ctx context.Context, j *Job) error { return j.Prov.Preflight(ctx, j.Spec) }
	// Rails checks breaker, launch lock, cap and max_live; release runs at the end.
	Rails = func(ctx context.Context, j *Job) (release func(), err error) { return func() {}, nil }
	// Transport makes the commit reachable (git push); cleanup deletes the ref.
	Transport = func(ctx context.Context, j *Job) (cleanup func(), err error) { return func() {}, nil }
	// RunJob launches, watches and completes; began reports whether the command started.
	RunJob = basicRun
)

Stages; later tasks replace the defaults (2.1b Preflight, 2.4 Rails, 2.5 Transport, 2.6a RunJob).

View Source
var (
	LedgerToday  func(dir string, now time.Time) config.Micros
	BreakerState func(dir string, b config.Breaker, now time.Time) (why string, paused bool)
)

Set by internal/remote/rails, which imports this package (so these are hooks, not imports).

View Source
var (
	OrphanNames func(dir string) map[string]bool
	DropOrphan  func(dir, name string)
)

OrphanNames and DropOrphan are set by internal/remote/rails: the names whose only reservation in dir is an orphan (a resource discarded before attach and not confirmed gone, spec 8.3), and the removal of one.

View Source
var CloneURLCheck func(j *Job) error

CloneURLCheck is set by the transport: a usable clone URL whose host is in known hosts. The preflight calls it when it is set.

View Source
var FetchAgent = func(url string) ([]byte, error) {
	if !strings.HasPrefix(url, "https://") {
		return nil, errors.New("not an https url")
	}
	c := &http.Client{Timeout: 5 * time.Minute}
	resp, err := c.Get(url)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("%s: %s", url, resp.Status)
	}
	return io.ReadAll(io.LimitReader(resp.Body, 256<<20))
}

FetchAgent downloads a release agent (a variable so tests never touch the network). The size is bounded by the caller's hash check, not trusted.

View Source
var FetchChecksums = func(url string) ([]byte, error) {
	if !strings.HasPrefix(url, "https://") {
		return nil, errors.New("not an https url")
	}
	c := &http.Client{Timeout: 30 * time.Second}
	resp, err := c.Get(url)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("%s: %s", url, resp.Status)
	}
	return io.ReadAll(io.LimitReader(resp.Body, 1<<20))
}

FetchChecksums downloads a release's checksums.txt over https (a variable so tests never touch the network; the conformance suite passes its own).

View Source
var LiveReservations func(dir string) map[string]bool

LiveReservations is set by internal/remote/rails: the names with a non-orphan reservation in dir (the sweep prunes dead ones first).

View Source
var PruneReservations func(dir string, dry bool) []string

PruneReservations is set by internal/remote/rails: it drops reservations whose process is gone (or that expired) from dir under the launch lock and returns their names; with dry it only reports them.

Functions

func AgentSpecFor

func AgentSpecFor(j *provider.JobSpec) agent.Spec

AgentSpecFor converts the host's job into the pod's spec.

func CallerEnvNames

func CallerEnvNames(p *run.Prepared, caller []string) (forced, plain []string)

CallerEnvNames splits the job's forwarded names (providers delta S.1): the names in the repo's forward_env, in the host's forward_env_allow and set in the caller's environment (an empty value counts as set), into forced ones (listed in forward_env_force; a secret-like name must be, or load refused it) and plain ones. Both lists are sorted; no value is read.

func CheckModuleDir

func CheckModuleDir(dir string) (string, error)

CheckModuleDir verifies that dir is a git work tree with no uncommitted or untracked changes and returns its HEAD (providers delta C.4 item 3).

func CheckPlugins

func CheckPlugins(ctx context.Context, e *config.Effective, stderr io.Writer) error

CheckPlugins starts every configured plugin once, as `bitc config check` does (providers delta A.3.1, A.8): a configuration error (hello, configure, the [test] endpoint gate) is 78 with the host-file line, a plugin that cannot start is 69.

func CloseProvider

func CloseProvider(p provider.Provider)

CloseProvider stops a provider that holds a process.

func Doctor

func Doctor(e *config.Effective, out io.Writer) (failed, unusable bool)

Doctor is `bitc doctor --remote` (spec 3.3).

func FullPreflight

func FullPreflight(ctx context.Context, j *Job) error

FullPreflight runs the network-free checks in spec order, then the provider's own.

func LastSweep

func LastSweep(dir string) (time.Time, bool)

LastSweep is when a sweep last listed this provider's resources successfully (not a dry run).

func NewProvider

func NewProvider(ctx context.Context, typ string, core *config.Provider, e *config.Effective, rt provider.Runtime) (provider.Provider, error)

NewProvider builds a section's provider and starts it when it needs a process (a plugin).

func NoProviderLeft

func NoProviderLeft(pool string, last error) error

NoProviderLeft: 69 if the last failure was ErrUnavailable or ErrIneligible, else 75 (8.2).

func Orchestrate

func Orchestrate(parent context.Context, j *Job) (code int, began bool, err error)

Orchestrate runs one remote job end to end (spec 8.4 "Host side", 8.3 cleanup). A TestOnly provider (the in-process fake) has no agent and no result.json: it keeps basicRun.

func RemoteEnv

func RemoteEnv(p *run.Prepared, caller []string) ([]string, error)

RemoteEnv builds the remote env from empty (spec 8.4).

func ResolveAgent

func ResolveAgent(e *config.Effective, core *config.Provider) (string, string, error)

ResolveAgent returns the agent URL and sha256 for linux/amd64 (spec 8.4 step 1); a build source has no URL. A source that is delivered as bytes (module_dir) has none either, so it is ineligible for a provider that fetches by URL.

func ResolveAgentFile

func ResolveAgentFile(e *config.Effective, core *config.Provider, arch string) (sha, path string, err error)

ResolveAgentFile returns the sha256 and the local path of the agent binary for arch whose bytes a fixed-capacity provider sends over its session (providers delta C.4 item 4), whatever the source: a url source's paths[arch], a module_dir build, a release asset (downloaded once into the account's agents directory and checked against checksums.txt), or, under [test] agent_url, this binary. Nothing is fetched by the host itself.

func ResolveAgentFor

func ResolveAgentFor(e *config.Effective, core *config.Provider, arch string) (string, string, error)

ResolveAgentFor is ResolveAgent for one architecture.

func ResolveRelease

func ResolveRelease(ver, arch string, fetch func(url string) ([]byte, error)) (url, sha string, err error)

ResolveRelease returns the URL and sha256 of the release agent for arch: the asset bitc_<ver>_linux_<arch>, with its sha read from the release's checksums.txt. A failed fetch is transient (nothing was created); a missing line makes the job ineligible.

func SelectArch

func SelectArch(providerArch, poolArch []string) (string, error)

SelectArch picks the architecture a job runs on: the first entry of the pool's arch list that the provider can run (providers delta C.4 item 1). A provider that lists none runs amd64 only. With no overlap the job is ineligible: `arch <provider's> not allowed by pool (arch = [...])`.

func SendEnvCheck

func SendEnvCheck(typ string, level provider.EnvLevel, multiJob bool, forced, plain []string) error

SendEnvCheck is the caller-env preflight check (providers delta S.3): the job needs "none" with no forwarded name, "forced" with at least one forced name, else "forwarded"; a provider whose effective level is lower, or a multi-job one (S.4, which never takes a forced name, whatever its setting), cannot take it. Nothing is stripped to make a job fit; the note names the names, never a value.

func StatusSection

func StatusSection(e *config.Effective) any

StatusSection is status's remote part: resources by owner and today's spend.

func StdinIdle

func StdinIdle(f *os.File) (bool, string)

StdinIdle: /dev/null, a TTY, an empty regular file, or a pipe/socket with nothing readable on a zero-timeout poll(2) may go remote (spec 8.4).

func Sweep

func Sweep(ctx context.Context, e *config.Effective, dry bool, only string, foreign bool, out io.Writer) error

Sweep is the remote part of `bitc sweep` (spec 8.3). It always returns; problems are noted.

func ToolsForArch

func ToolsForArch(tools []config.Tool, arch string) ([]config.Tool, error)

ToolsForArch keeps the tool entries for arch. A tool name with no entry for arch makes the job ineligible: `tool node has no arm64 entry` (providers delta C.9 item 3).

func Walk

func Walk(ctx context.Context, inv run.Invocation, p *run.Prepared, typ string, stderr io.Writer) (run.Outcome, bool, error)

Walk tries one remote provider (spec 8.2). handled=false means "try the next provider"; err is this provider's failure for the no-provider-left rule.

Types

type AgentSource

type AgentSource struct {
	URL, SHA256 string
	Build       *provider.AgentBuild // Ref is filled in by the transport
	Path        string               // a local file whose bytes are delivered (source url paths, source build with module_dir)
	Commit      string               // module_dir build: the source tree's HEAD
	Arch        string
}

AgentSource is where the pod gets its agent (spec 8.4 step 1): a URL to download, or Build, a pinned commit the pod builds itself. SHA256 is what the agent binary must hash to.

func BuildAgent

func BuildAgent(e *config.Effective, core *config.Provider, arch string, run Runner) (AgentSource, error)

BuildAgent builds the agent for arch from the module_dir tree (providers delta C.4 item 3): CGO_ENABLED=0 GOOS=linux GOARCH=<arch> go build -trimpath -ldflags=-buildid= ./cmd/bitc, into <account>/agents/<arch>/<sha256>, once per architecture and tree state (HEAD of a clean tree). A nil run uses the go on PATH.

func ResolveAgentSource

func ResolveAgentSource(e *config.Effective, core *config.Provider) (AgentSource, error)

ResolveAgentSource resolves the provider's agent source for linux/amd64.

func ResolveAgentSourceFor

func ResolveAgentSourceFor(e *config.Effective, core *config.Provider, arch string) (AgentSource, error)

ResolveAgentSourceFor resolves the agent source for one architecture (providers delta C.4): a url source expands {arch} and hashes paths[arch]; the release source takes bitc_<ver>_linux_<arch> and its sha from checksums.txt; a build source with module_dir names the tree to build (the build itself is BuildAgent); a build source with commit, image and sha256 is built by the pod.

func (AgentSource) String

func (a AgentSource) String() string

String is the doctor line: the URL, or "build <commit12> on <image>".

type Interrupted

type Interrupted struct{ Sig syscall.Signal }

Interrupted is a signal during a remote job: cleanup ran, exit 128+N (spec 8.3). RunJob returns it; Walk records "interrupted" and never counts it as a breaker failure.

func (Interrupted) Error

func (i Interrupted) Error() string

type Job

type Job struct {
	Inv     run.Invocation
	P       *run.Prepared
	Type    string
	Core    *config.Provider
	Prov    provider.Provider
	Spec    *provider.JobSpec
	Stdout  io.Writer
	Stderr  io.Writer
	Red     *redact.Set
	Handle  *provider.Handle // set once Launch succeeded
	Cleanup []func()         // run in reverse on every exit path (spec 8.3)

	Estimate config.Micros // set by Rails
	RailsDir string        // ACCOUNT/remote/<type>, set by Rails
	// Retried: this job's one retry (spec 8.3) is spent, by a create retry or by Walk's pre-attach retry.
	Retried bool
	Created time.Time // when Launch succeeded (a resource exists and bills); zero if none
	Began   time.Time // when BEGIN was seen
	// Release drops this attempt's reservation (idempotent); Orphan keeps it as an orphan instead
	// (spec 8.3): both set by Rails, nil before it ran.
	Release func()
	Orphan  func()
	// DeleteRef deletes the job ref once; it runs at BEGIN and, at the latest, at the end.
	DeleteRef func()
	// KeepSignals (set by Walk) makes RunJob leave its signal registration in place and hand the
	// stop to StopSignals, which Walk calls after all cleanup (a signal during cleanup is absorbed).
	KeepSignals bool
	StopSignals func()
	// contains filtered or unexported fields
}

Job is one remote attempt.

func (*Job) Info

func (j *Job) Info(format string, a ...any)

Info prints "bitc: <provider>: <msg>" unless BITC_LOG=quiet (informational lines only).

func (*Job) Note

func (j *Job) Note(format string, a ...any)

Note prints "bitc: <provider>: <msg>".

type PreAttachDiscard

type PreAttachDiscard struct {
	ID        string
	Inner     error // ErrTransient, ErrUnavailable or ErrIneligible
	Confirmed bool  // the resource is confirmed gone
}

PreAttachDiscard is what RunJob returns when Launch made a resource, failed before any job input reached it, and the effective boundary is "attach" (spec 8.2): the resource was torn down (Confirmed) or left for the sweep, and Walk decides on a retry or the next provider.

func (*PreAttachDiscard) Error

func (d *PreAttachDiscard) Error() string

func (*PreAttachDiscard) Unwrap

func (d *PreAttachDiscard) Unwrap() error

type Runner

type Runner func(dir string, env []string, argv ...string) ([]byte, error)

Runner runs argv in dir with extra env (added to the process env); BuildAgent's seam for tests.

Directories

Path Synopsis
Package artifacts brings a remote job's declared paths back into the work tree (spec 8.4).
Package artifacts brings a remote job's declared paths back into the work tree (spec 8.4).
Package gitref holds the git helpers of the git-push transport (spec 8.4): clone URL derivation, known hosts, and job-ref sweeping.
Package gitref holds the git helpers of the git-push transport (spec 8.4): clone URL derivation, known hosts, and job-ref sweeping.
Package rails is the shared remote safety rails (spec 8.3).
Package rails is the shared remote safety rails (spec 8.3).
Package transport is the git-push code transport stage (spec 8.4).
Package transport is the git-push code transport stage (spec 8.4).

Jump to

Keyboard shortcuts

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