Documentation
¶
Overview ¶
Package sandbox owns the ephemeral LXC lifecycle: clone template, start, run, destroy.
Target kind 'sandbox' puts the Proxmox TEMPLATE vmid in `host`. Every attempt gets its own linked clone; the container IS the isolation, so no git worktree is needed and bypassPermissions is safe. Host-side pct commands run through the target's (local) executor so mock mode can script the whole lifecycle.
Index ¶
- Variables
- func Destroy(ctx context.Context, host executor.Executor, vmid string, log *slog.Logger)
- func Hash(data []byte) string
- func IsPluginProvider(p string) bool
- func IsRepoURL(repoPath string) bool
- func Provision(ctx context.Context, host executor.Executor, templateVMID string, ...) (string, error)
- type Config
- type CreateRequest
- type Docker
- func (d *Docker) Attach(id, inner string) ([]string, error)
- func (d *Docker) Can(op string) bool
- func (d *Docker) Create(ctx context.Context, req CreateRequest) (string, error)
- func (d *Docker) Destroy(ctx context.Context, id string) error
- func (d *Docker) Exec(id string) executor.Executor
- func (d *Docker) Name() string
- func (d *Docker) Resume(ctx context.Context, id string) error
- func (d *Docker) Suspend(ctx context.Context, id string) error
- type Hooks
- type Provider
- type Proxmox
- func (p *Proxmox) Attach(id, inner string) ([]string, error)
- func (p *Proxmox) Can(op string) bool
- func (p *Proxmox) Create(ctx context.Context, req CreateRequest) (string, error)
- func (p *Proxmox) Destroy(ctx context.Context, id string) error
- func (p *Proxmox) Exec(id string) executor.Executor
- func (p *Proxmox) Name() string
- func (p *Proxmox) Resume(ctx context.Context, id string) error
- func (p *Proxmox) Suspend(ctx context.Context, id string) error
- type Script
- func (s *Script) Attach(id, inner string) ([]string, error)
- func (s *Script) Can(op string) bool
- func (s *Script) Create(ctx context.Context, req CreateRequest) (string, error)
- func (s *Script) Destroy(ctx context.Context, id string) error
- func (s *Script) Exec(id string) executor.Executor
- func (s *Script) Name() string
- func (s *Script) Resume(ctx context.Context, id string) error
- func (s *Script) Suspend(ctx context.Context, id string) error
Constants ¶
This section is empty.
Variables ¶
var PluginHooks func(ref string) ([]byte, error)
PluginHooks returns a plugin sandbox provider's hooks file for a config path "plugin:<id>/<provider>" (internal/plugins); set at startup.
Functions ¶
func IsPluginProvider ¶ added in v2.6.0
IsPluginProvider reports whether a hooks path names a plugin's provider.
Types ¶
type Config ¶ added in v2.6.0
type Config struct {
// Provider is "proxmox" (the default: host holds the template vmid),
// "docker" or "script".
Provider string `json:"provider,omitempty"`
// Docker: Image to run, the Machine (a target name) whose docker CLI to
// use ("" = this server), an optional DockerHost (-H) and extra run args.
Image string `json:"image,omitempty"`
Machine string `json:"machine,omitempty"`
DockerHost string `json:"docker_host,omitempty"`
RunArgs []string `json:"run_args,omitempty"`
// Script: path to a lectern.sandbox.yaml on the machine that runs the
// hooks. "{repo}" is the project's repo path. Hooks only run while the
// file matches a hash a person trusted (Trusted, path -> sha256).
ConfigPath string `json:"config_path,omitempty"`
Trusted map[string]string `json:"trusted,omitempty"`
// Env is given to every sandbox this target makes.
Env map[string]string `json:"env,omitempty"`
// OnFinish is what happens when an attempt ends: "destroy" (default),
// "suspend" or "keep".
OnFinish string `json:"on_finish,omitempty"`
}
Config is a sandbox target's sandbox_json.
func ParseConfig ¶ added in v2.6.0
ParseConfig reads targets.sandbox_json; empty means Proxmox.
func (Config) ResolvePath ¶ added in v2.6.0
ResolvePath fills {repo} in the script config path.
type CreateRequest ¶ added in v2.6.0
CreateRequest is what a sandbox is made for.
type Docker ¶ added in v2.6.0
type Docker struct {
Host executor.Executor
Cfg Config
Remote []string // ssh argv prefix to the machine, for terminals; nil = local
}
Docker runs each sandbox as a container, on this server or on any machine Lectern reaches (its docker CLI is driven through that machine's executor).
type Hooks ¶ added in v2.6.0
type Hooks struct {
Create string `yaml:"create"`
Exec string `yaml:"exec"`
Suspend string `yaml:"suspend"`
Resume string `yaml:"resume"`
Destroy string `yaml:"destroy"`
Attach string `yaml:"attach"`
Env map[string]string `yaml:"env"`
}
Hooks is a lectern.sandbox.yaml: shell snippets for each lifecycle step. Every hook sees LECTERN_SANDBOX_ID (except create), LECTERN_ATTEMPT_ID, LECTERN_SANDBOX_NAME and the sandbox env. exec also sees LECTERN_COMMAND and LECTERN_CWD, and must pass stdin through.
func ParseHooks ¶ added in v2.6.0
ParseHooks reads a lectern.sandbox.yaml.
type Provider ¶ added in v2.6.0
type Provider interface {
Name() string
// Create makes a sandbox, starts it and waits until it runs commands.
Create(ctx context.Context, req CreateRequest) (string, error)
// Exec is an executor whose commands run inside the sandbox.
Exec(id string) executor.Executor
Suspend(ctx context.Context, id string) error
Resume(ctx context.Context, id string) error
Destroy(ctx context.Context, id string) error
// Can reports whether an optional operation ("suspend", "resume",
// "attach") is available.
Can(op string) bool
// Attach is the argv that runs inner (already a command line) inside the
// sandbox with a terminal, for the web terminal.
Attach(id string, inner string) ([]string, error)
}
A Provider makes and drives sandboxes of one kind (docs/sandboxes.md): Proxmox linked clones, Docker containers, or anything a user can script. Every provider's commands run through a host executor, so mock mode and a remote Docker machine work the same way as the control plane itself.
type Proxmox ¶ added in v2.6.0
Proxmox is the original provider: a linked clone of a template LXC.
type Script ¶ added in v2.6.0
Script is the bring-your-own provider: Fly, Modal, Vercel, a VM API, anything with a CLI, wired through the hooks file.
func LoadScript ¶ added in v2.6.0
func LoadScript(ctx context.Context, host executor.Executor, cfg Config, repo string) (*Script, error)
LoadScript reads the hooks file through host and refuses it unless its hash is the one a person trusted, so an agent that edits the file cannot get its hooks run on the Lectern server.