Documentation
¶
Overview ¶
Package envsetup sets the machine up by the hub's environment list (docs/hub/environment.md, «Machine setup»): the forges' CLIs logged in, repositories cloned, scripts run in order.
It is the runtime's, not the agent's. The machine agent runs sandboxed by systemd (the home read-only, its own data folder the only place to write) and must not run a program of anyone's choosing; the runtime runs as the person, holds the person's safe and is where the person's own commands run anyway. The two meet in the link's folder, in files that survive a restart of either:
agent → runtime environment.json the list the agent holds (hash, items)
environment-requests/<id>.json a run the hub asked for (hubproto.EnvRunRequest)
runtime → agent environment-setup.json the hash worked on, each item's status, the ledger of «once» scripts
environment-runs/<id>.json a run as it stands, rewritten as steps move (hubproto.EnvRun)
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrSetupOff = errors.New("setup is off on this machine")
ErrSetupOff is Ask's answer when the policy does not let the list set the machine up.
var ErrTimeout = errors.New("timeout")
ErrTimeout: the program did not end in time; it was asked to stop, then killed.
Functions ¶
Types ¶
type Apps ¶
type Apps interface {
// Install puts the app in dir on the machine as the environment item's, with the installation's values the hub
// gave (${install:<name>}); changed is false when the same version from the same files is already there. missing
// are the values the app asks for and the hub has none of: the app is there but not configured. keep are the app
// items of the list: an app whose item left it is taken over by the item that brings it now. version is the
// manifest's version now on the machine, which the run tells the hub («Окружение» shows it).
Install(dir, itemID string, locked bool, install map[string]string, keep []string) (id, version string, changed bool, missing []string, err error)
// Has: the item's app is installed.
Has(itemID string) bool
// Prune takes off the environment's apps whose item is not among keep.
Prune(keep []string) ([]string, error)
}
Apps is the runtime's app registry as the setup sees it.
type Cmd ¶
type Cmd struct {
Name string
Args []string
Dir string
// Env is the whole environment of the program; nothing is inherited.
Env []string
Stdin string
// Out gets stdout and stderr, interleaved as written.
Out io.Writer
Timeout time.Duration
// Bind is a folder of this machine a sandboxed program must still see and write (its working folder under /tmp).
Bind string
}
Cmd is one program to run.
type ExecFunc ¶
ExecFunc runs c and answers its exit code. An error is a program that did not run to its end: not found (exec.ErrNotFound), ErrTimeout, or the context's.
type Providers ¶
type Providers interface {
// Apply puts the item's provider into the registry or brings it in line with the source; changed is false when it
// was there as it is. waiting are the secrets of the person's safe the source names that the person has not put
// or not allowed for the provider's server yet (they are asked, and the provider is kept without them); shared
// are the vault: references to the organization's secrets it names.
Apply(itemID, name string, source json.RawMessage) (changed bool, waiting, shared []string, err error)
// Has: the item's provider is in the registry.
Has(itemID string) bool
// Prune takes off the environment's providers whose item is not among keep.
Prune(keep []string) ([]string, error)
}
source is what any setup kind's source may hold (docs/hub/environment.md). Providers is the runtime's registry of model providers as the setup sees it.
type Runner ¶
type Runner struct {
// LinkDir is the folder of a hub link (the agent's data folder, or <data>/hub for an observe link).
LinkDir string
// Home is the person's home: where repositories go and what scripts get as HOME.
Home string
Secrets Secrets
// Apps installs the environment's apps (items of kind app) in the runtime's app registry; nil: this runtime does
// not, and such a step fails saying so.
Apps Apps
// Providers keeps the environment's model providers (items of kind provider) in the runtime's registry; nil: this
// runtime does not, and such a step fails saying so.
Providers Providers
// The rest is for tests; the zero value is the real thing.
Exec ExecFunc
Fetch func(ctx context.Context, url string) ([]byte, error)
Now func() time.Time
Getenv func(string) string
// Version is the runtime's, for the heartbeat.
Version string
// Free says how many bytes are free on the disk of path; nil asks the system.
Free func(path string) (uint64, error)
// Poll is how often the link folder is looked at (3 s).
Poll time.Duration
// Log is the runtime's log: level, message, key/value pairs.
Log func(level, msg string, kv ...string)
// OnUpdate is told when the hub asks for an update run («Применить на машинах»): the runtime asks the base package
// for a look of its own then. nil: nothing.
OnUpdate func()
// contains filtered or unexported fields
}
Runner does the setup for one link folder.
func (*Runner) Ask ¶
Ask puts a run of the held list in the queue, the way a request of the hub is put: the person pressed «Повторить» on the card. It is an apply run (the hub keeps an apply run it did not ask for), so what is done stays done and what is not is done again now. A run already waiting is answered with its id.
func (*Runner) Recover ¶
func (r *Runner) Recover()
Recover ends what a crash left running: a run file that still says running is an error, «прервано перезапуском». The list is worked on again by the next Tick (its hash was never written), and the ledger tells what need not be redone.
func (*Runner) Run ¶
Run looks at the link folder until ctx ends: a list the setup has not worked on gets an apply run, a request of the hub gets its run. One run goes at a time; the next waits. It returns when ctx ends (a run in progress is stopped).
type Secrets ¶
type Secrets interface {
// Has says whether the safe holds a secret of this name.
Has(name string) bool
// Reveal gives the values of names; an error if any is missing.
Reveal(names []string) (map[string]string, error)
// Ask opens the safe's ask on the person's page: «положите <name> в сейф», with the reason. One open ask per name.
Ask(name, why string) error
}
Secrets is the person's safe as setup sees it. The values never leave a step's environment (and the masked log).
type View ¶
type View struct {
// Allowed: the policy lets the list set this machine up. Off, the card says nothing.
Allowed bool `json:"allowed"`
Hash string `json:"hash"`
Items []ViewItem `json:"items"`
// Done: the list's current version was worked on and every item is ok.
Done bool `json:"done"`
// Run is the run in progress, else the latest one; nil before any.
Run *hubproto.EnvRun `json:"run,omitempty"`
}
View is the card's data.
type ViewItem ¶
type ViewItem struct {
ItemID string `json:"itemId"`
Kind string `json:"kind"`
Name string `json:"name"`
Status string `json:"status"` // ok, error, pending, running; pending also before the first run
Message string `json:"message,omitempty"`
// Secret is the safe's name a pending item waits for, when it waits for one.
Secret string `json:"secret,omitempty"`
}
ViewItem is one setup item as the card shows it.