provider

package
v0.39.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package provider defines the VMProvider interface that abstracts away the underlying virtualization backend (Podman Machine, Docker Desktop, OrbStack, Lima, Colima, etc.) so that devx networking and provisioning can run on top of whatever hypervisor the developer already has.

The package uses a two-layer architecture:

  • VMProvider handles VM lifecycle (create, start, stop, SSH).
  • ContainerRuntime handles container execution within the VM (run, stop, checkpoint).

The Provider composite binds a VMProvider and ContainerRuntime together so that commands can access both layers through a single value.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Resolve added in v0.34.0

func Resolve(name string) (VMProvider, ContainerRuntime, error)

Resolve picks a provider by name. If name is "auto", it calls Detect() and either auto-selects (if exactly one is available) or returns an error asking the caller to pick interactively.

The interactive prompt itself lives in the cmd layer (not here) so that this package stays independent of TUI libraries.

Types

type ColimaProvider added in v0.34.0

type ColimaProvider struct{}

ColimaProvider implements VMProvider using Colima, which wraps Lima with a simpler CLI and built-in container runtime management. Colima is treated as a "flavor" of Lima — architecturally it's the same VM engine, but with different CLI ergonomics (profiles instead of names).

func (*ColimaProvider) Init added in v0.34.0

func (c *ColimaProvider) Init(name string) error

func (*ColimaProvider) Inspect added in v0.34.0

func (c *ColimaProvider) Inspect(name string) (*MachineInfo, error)

func (*ColimaProvider) IsRunning added in v0.34.0

func (c *ColimaProvider) IsRunning(name string) bool

func (*ColimaProvider) Name added in v0.34.0

func (c *ColimaProvider) Name() string

func (*ColimaProvider) Remove added in v0.34.0

func (c *ColimaProvider) Remove(name string) error

func (*ColimaProvider) Resize added in v0.34.0

func (c *ColimaProvider) Resize(name string, cpus int, memoryMB int) error

func (*ColimaProvider) SSH added in v0.34.0

func (c *ColimaProvider) SSH(machineName, command string) (string, error)

func (*ColimaProvider) SetDefault added in v0.34.0

func (c *ColimaProvider) SetDefault(_ string) error

func (*ColimaProvider) Sleep added in v0.34.0

func (c *ColimaProvider) Sleep(name string) error

func (*ColimaProvider) Start added in v0.34.0

func (c *ColimaProvider) Start(name string) error

func (*ColimaProvider) StopAll added in v0.34.0

func (c *ColimaProvider) StopAll() error

type ContainerRuntime added in v0.34.0

type ContainerRuntime interface {
	// Name returns the runtime CLI name (e.g. "podman", "docker", "nerdctl").
	Name() string

	// RunInteractive executes a container with stdin/stdout/stderr attached.
	// This replaces direct exec.Command calls in cmd/shell.go so that each
	// backend can prepend the correct wrapper (e.g. "limactl shell <vm> nerdctl").
	RunInteractive(args ...string) error

	// Exec runs a container command and returns combined output.
	Exec(args ...string) (string, error)

	// CommandContext returns an *exec.Cmd to run a container command with context.
	CommandContext(ctx context.Context, args ...string) *exec.Cmd

	// SupportsCheckpoint reports whether CRIU checkpoint/restore is available.
	SupportsCheckpoint() bool
}

ContainerRuntime executes container commands within the VM backend. Each VMProvider has a paired ContainerRuntime that knows how to invoke the correct CLI (podman, docker, nerdctl) for that backend.

type DetectedProvider added in v0.34.0

type DetectedProvider struct {
	Name    string // "podman", "lima", "colima", "docker", "orbstack"
	Binary  string // path to the binary
	Version string // detected version string
}

DetectedProvider holds information about a VM backend found on the system.

func Detect added in v0.34.0

func Detect() []DetectedProvider

Detect scans the system for available VM backends and returns them in preference order. Only backends whose CLI binary is found on $PATH are included.

type DockerProvider

type DockerProvider struct{}

DockerProvider implements VMProvider using Docker Desktop / OrbStack. OrbStack is automatically used when it is installed, since it replaces the `docker` CLI transparently.

func (*DockerProvider) Init

func (d *DockerProvider) Init(name string) error

func (*DockerProvider) Inspect

func (d *DockerProvider) Inspect(_ string) (*MachineInfo, error)

func (*DockerProvider) IsRunning

func (d *DockerProvider) IsRunning(_ string) bool

func (*DockerProvider) Name

func (d *DockerProvider) Name() string

func (*DockerProvider) Remove

func (d *DockerProvider) Remove(name string) error

func (*DockerProvider) Resize added in v0.6.0

func (d *DockerProvider) Resize(_ string, _, _ int) error

func (*DockerProvider) SSH

func (d *DockerProvider) SSH(machineName, command string) (string, error)

func (*DockerProvider) SetDefault

func (d *DockerProvider) SetDefault(_ string) error

func (*DockerProvider) Sleep added in v0.6.0

func (d *DockerProvider) Sleep(_ string) error

func (*DockerProvider) Start

func (d *DockerProvider) Start(_ string) error

func (*DockerProvider) StopAll

func (d *DockerProvider) StopAll() error

type DockerRuntime added in v0.34.0

type DockerRuntime struct{}

DockerRuntime executes containers via the native `docker` CLI.

func (*DockerRuntime) CommandContext added in v0.34.0

func (r *DockerRuntime) CommandContext(ctx context.Context, args ...string) *exec.Cmd

func (*DockerRuntime) Exec added in v0.34.0

func (r *DockerRuntime) Exec(args ...string) (string, error)

func (*DockerRuntime) Name added in v0.34.0

func (r *DockerRuntime) Name() string

func (*DockerRuntime) RunInteractive added in v0.34.0

func (r *DockerRuntime) RunInteractive(args ...string) error

func (*DockerRuntime) SupportsCheckpoint added in v0.34.0

func (r *DockerRuntime) SupportsCheckpoint() bool

type LimaProvider added in v0.34.0

type LimaProvider struct{}

LimaProvider implements VMProvider using Lima (limactl). Lima creates lightweight Linux VMs using macOS Virtualization.framework (or QEMU) with VirtioFS file sharing.

func (*LimaProvider) Init added in v0.34.0

func (l *LimaProvider) Init(name string) error

func (*LimaProvider) Inspect added in v0.34.0

func (l *LimaProvider) Inspect(name string) (*MachineInfo, error)

func (*LimaProvider) IsRunning added in v0.34.0

func (l *LimaProvider) IsRunning(name string) bool

func (*LimaProvider) Name added in v0.34.0

func (l *LimaProvider) Name() string

func (*LimaProvider) Remove added in v0.34.0

func (l *LimaProvider) Remove(name string) error

func (*LimaProvider) Resize added in v0.34.0

func (l *LimaProvider) Resize(name string, cpus int, memoryMB int) error

func (*LimaProvider) SSH added in v0.34.0

func (l *LimaProvider) SSH(machineName, command string) (string, error)

func (*LimaProvider) SetDefault added in v0.34.0

func (l *LimaProvider) SetDefault(_ string) error

func (*LimaProvider) Sleep added in v0.34.0

func (l *LimaProvider) Sleep(name string) error

func (*LimaProvider) Start added in v0.34.0

func (l *LimaProvider) Start(name string) error

func (*LimaProvider) StopAll added in v0.34.0

func (l *LimaProvider) StopAll() error

type MachineInfo

type MachineInfo struct {
	Name  string
	State string
}

MachineInfo is the backend-agnostic representation of a VM.

type MultipleProvidersError added in v0.34.0

type MultipleProvidersError struct {
	Available []DetectedProvider
}

MultipleProvidersError is returned when auto-detection finds more than one provider and the caller needs to prompt the user to choose.

func (*MultipleProvidersError) Error added in v0.34.0

func (e *MultipleProvidersError) Error() string

type NerdctlRuntime added in v0.34.0

type NerdctlRuntime struct {
	// ShellCmd is the command prefix to enter the VM shell.
	// For Lima: []string{"limactl", "shell", "<vmname>"}
	// For Colima: []string{"colima", "ssh", "--profile", "<profile>", "--"}
	ShellCmd []string
}

NerdctlRuntime executes containers via `nerdctl` inside a Lima/Colima VM. Commands are proxied through the VM shell (e.g. "limactl shell <vm> nerdctl ...").

func (*NerdctlRuntime) CommandContext added in v0.34.0

func (r *NerdctlRuntime) CommandContext(ctx context.Context, args ...string) *exec.Cmd

func (*NerdctlRuntime) Exec added in v0.34.0

func (r *NerdctlRuntime) Exec(args ...string) (string, error)

func (*NerdctlRuntime) Name added in v0.34.0

func (r *NerdctlRuntime) Name() string

func (*NerdctlRuntime) RunInteractive added in v0.34.0

func (r *NerdctlRuntime) RunInteractive(args ...string) error

func (*NerdctlRuntime) SupportsCheckpoint added in v0.34.0

func (r *NerdctlRuntime) SupportsCheckpoint() bool

type PodmanProvider

type PodmanProvider struct{}

PodmanProvider implements VMProvider using Podman Machine.

func (*PodmanProvider) Init

func (p *PodmanProvider) Init(name string) error

func (*PodmanProvider) Inspect

func (p *PodmanProvider) Inspect(name string) (*MachineInfo, error)

func (*PodmanProvider) IsRunning

func (p *PodmanProvider) IsRunning(name string) bool

func (*PodmanProvider) Name

func (p *PodmanProvider) Name() string

func (*PodmanProvider) Remove

func (p *PodmanProvider) Remove(name string) error

func (*PodmanProvider) Resize added in v0.6.0

func (p *PodmanProvider) Resize(name string, cpus int, memoryMB int) error

func (*PodmanProvider) SSH

func (p *PodmanProvider) SSH(machineName, command string) (string, error)

func (*PodmanProvider) SetDefault

func (p *PodmanProvider) SetDefault(name string) error

func (*PodmanProvider) Sleep added in v0.6.0

func (p *PodmanProvider) Sleep(name string) error

func (*PodmanProvider) Start

func (p *PodmanProvider) Start(name string) error

func (*PodmanProvider) StopAll

func (p *PodmanProvider) StopAll() error

type PodmanRuntime added in v0.34.0

type PodmanRuntime struct{}

PodmanRuntime executes containers via the native `podman` CLI.

func (*PodmanRuntime) CommandContext added in v0.34.0

func (r *PodmanRuntime) CommandContext(ctx context.Context, args ...string) *exec.Cmd

func (*PodmanRuntime) Exec added in v0.34.0

func (r *PodmanRuntime) Exec(args ...string) (string, error)

func (*PodmanRuntime) Name added in v0.34.0

func (r *PodmanRuntime) Name() string

func (*PodmanRuntime) RunInteractive added in v0.34.0

func (r *PodmanRuntime) RunInteractive(args ...string) error

func (*PodmanRuntime) SupportsCheckpoint added in v0.34.0

func (r *PodmanRuntime) SupportsCheckpoint() bool

type Provider added in v0.34.0

type Provider struct {
	VM      VMProvider
	Runtime ContainerRuntime
}

Provider is the composite that binds a VM backend and its container runtime. Commands that need both VM lifecycle and container execution use this type.

func GetProvider added in v0.34.0

func GetProvider(name string) (*Provider, error)

GetProvider returns the full Provider composite (VM + Runtime) for a name. This is the preferred API for new code that needs container runtime access.

type VMProvider

type VMProvider interface {
	// Name returns the human-readable provider name (e.g. "podman", "lima").
	Name() string

	// Init provisions a new VM with the given name.
	Init(name string) error

	// Start starts a named VM.
	Start(name string) error

	// StopAll stops all running VMs managed by this provider.
	StopAll() error

	// Remove force-removes a VM by name.
	Remove(name string) error

	// Sleep suspends the VM to save memory/battery.
	Sleep(name string) error

	// Resize modifies the VM's hardware limits (cpus, memory).
	Resize(name string, cpus int, memoryMB int) error

	// SetDefault sets the active connection context to the named VM.
	SetDefault(name string) error

	// SSH executes a shell command inside the named VM and returns stdout.
	SSH(machineName, command string) (string, error)

	// IsRunning checks if the named VM is in the "running" state.
	IsRunning(name string) bool

	// Inspect returns structured info about a machine.
	Inspect(name string) (*MachineInfo, error)
}

VMProvider is the contract every VM backend must fulfil. It handles the VM lifecycle: provisioning, starting, stopping, and SSH.

func Get

func Get(name string) (VMProvider, error)

Get returns a VMProvider for the given name. Supported values: "podman" (default), "docker", "orbstack", "lima", "colima". An empty string or "auto" triggers auto-detection.

Jump to

Keyboard shortcuts

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