Documentation
¶
Overview ¶
Package runtime is the container runtime driver (Section 3.1): a small client for the Docker Engine API, which Docker Engine and Podman (its Docker-compatible socket) both serve. It creates, labels, starts, stops and reclaims the node and PostgreSQL containers the emulator runs, plus the networks and volumes they use.
Index ¶
- Constants
- Variables
- type Attachment
- type Client
- func (c *Client) AttachSelf(ctx context.Context, network string) error
- func (c *Client) Connect(ctx context.Context, network, container, ip string, aliases ...string) error
- func (c *Client) CopyFrom(ctx context.Context, id, file string) ([]byte, error)
- func (c *Client) CopyTo(ctx context.Context, id, dir string, files []File) error
- func (c *Client) CreateContainer(ctx context.Context, s ContainerSpec) (string, error)
- func (c *Client) CreateNetwork(ctx context.Context, s NetworkSpec) (string, error)
- func (c *Client) CreateVolume(ctx context.Context, name string, labels map[string]string) error
- func (c *Client) Disconnect(ctx context.Context, network, container string) error
- func (c *Client) EnsureImage(ctx context.Context, ref string, offline bool) error
- func (c *Client) Exec(ctx context.Context, id string, cmd []string, stdin []byte) (ExecResult, error)
- func (c *Client) ImageExists(ctx context.Context, ref string) (bool, error)
- func (c *Client) Info(ctx context.Context) (Info, error)
- func (c *Client) InspectContainer(ctx context.Context, id string) (Container, error)
- func (c *Client) InspectNetwork(ctx context.Context, name string) (Network, error)
- func (c *Client) ListContainers(ctx context.Context, labels map[string]string) ([]Container, error)
- func (c *Client) ListNetworks(ctx context.Context, labels map[string]string) ([]Network, error)
- func (c *Client) ListVolumes(ctx context.Context, labels map[string]string) ([]string, error)
- func (c *Client) Logs(ctx context.Context, id string, tail int) (string, error)
- func (c *Client) RemoveContainer(ctx context.Context, id string, force bool) error
- func (c *Client) RemoveNetwork(ctx context.Context, name string) error
- func (c *Client) RemoveVolume(ctx context.Context, name string) error
- func (c *Client) RestartContainer(ctx context.Context, id string, timeout time.Duration) error
- func (c *Client) SaveImages(ctx context.Context, refs []string, w io.Writer) error
- func (c *Client) Self() string
- func (c *Client) SelfIP(ctx context.Context, network string) (string, error)
- func (c *Client) StartContainer(ctx context.Context, id string) error
- func (c *Client) StopContainer(ctx context.Context, id string, timeout time.Duration) error
- type Container
- type ContainerSpec
- type ExecResult
- type File
- type Info
- type Manager
- func (m *Manager) Cleanup(ctx context.Context, all bool) error
- func (m *Manager) Labels(service, resource, role string) map[string]string
- func (m *Manager) Name(parts ...string) string
- func (m *Manager) Reclaim(ctx context.Context) error
- func (m *Manager) WaitRunning(ctx context.Context, id string) error
- type Mount
- type Network
- type NetworkSpec
- type Port
Constants ¶
const ( LabelInstance = "gcpemu.instance" // instance ID LabelService = "gcpemu.service" // owning service, e.g. "sql" LabelResource = "gcpemu.resource" // owning resource name LabelRole = "gcpemu.role" // e.g. "server", "node", "nat" )
Labels applied to everything the emulator creates.
const SelfEnv = "GCPEMU_SELF_CONTAINER"
SelfEnv names the emulator's own container explicitly.
Variables ¶
var ErrNotFound = errors.New("runtime: not found")
ErrNotFound is returned when a container, network, volume or image is absent.
Functions ¶
This section is empty.
Types ¶
type Attachment ¶
Attachment connects the container to a network at creation.
type Client ¶
type Client struct {
// Endpoint is the socket or URL in use.
Endpoint string
// contains filtered or unexported fields
}
Client talks to a Docker-compatible Engine API endpoint.
func Detect ¶
Detect finds a runtime socket: $DOCKER_HOST, then the default Docker socket, then rootless and rootful Podman sockets.
func (*Client) AttachSelf ¶ added in v0.3.0
AttachSelf connects the emulator's container to network; it is a no-op on the host and when already connected.
func (*Client) Connect ¶
func (c *Client) Connect(ctx context.Context, network, container, ip string, aliases ...string) error
Connect attaches a container to a network with an optional static IP.
func (*Client) CopyTo ¶
CopyTo writes files into dir inside the container (which may be created but not started).
func (*Client) CreateContainer ¶
CreateContainer creates (but does not start) a container.
func (*Client) CreateNetwork ¶
CreateNetwork creates a bridge network and returns its ID. Inside a container the emulator joins it (AttachSelf).
func (*Client) CreateVolume ¶
CreateVolume creates (or returns the existing) named volume.
func (*Client) Disconnect ¶
Disconnect detaches a container from a network.
func (*Client) EnsureImage ¶
EnsureImage pulls ref unless it is already present.
func (*Client) Exec ¶
func (c *Client) Exec(ctx context.Context, id string, cmd []string, stdin []byte) (ExecResult, error)
Exec runs cmd in a running container and waits for it.
func (*Client) ImageExists ¶
ImageExists reports whether ref is present locally.
func (*Client) InspectContainer ¶
InspectContainer returns container state.
func (*Client) InspectNetwork ¶
InspectNetwork returns a network by name or ID.
func (*Client) ListContainers ¶
ListContainers returns all containers (running or not) carrying all labels.
func (*Client) ListNetworks ¶
ListNetworks returns networks carrying all the given labels.
func (*Client) ListVolumes ¶
ListVolumes returns names of volumes carrying all the given labels.
func (*Client) RemoveContainer ¶
RemoveContainer deletes a container (with anonymous volumes); a missing container is not an error.
func (*Client) RemoveNetwork ¶
RemoveNetwork deletes a network; a missing network is not an error.
func (*Client) RemoveVolume ¶
RemoveVolume deletes a volume; a missing volume is not an error.
func (*Client) RestartContainer ¶
RestartContainer restarts a container.
func (*Client) SaveImages ¶
SaveImages writes a `docker save`-format tarball of the given local images to w (GKE preloads node images from the host cache with it).
func (*Client) Self ¶ added in v0.3.0
Self returns the emulator's own container ID, or "" when it runs on the host (or on the host network).
func (*Client) SelfIP ¶ added in v0.3.0
SelfIP returns the emulator's address on network ("" on the host).
func (*Client) StartContainer ¶
StartContainer starts a created or stopped container.
type Container ¶
type Container struct {
ID string
Name string
Image string
Labels map[string]string
Running bool
Status string // created, running, exited, ...
// ExitCode of the last run.
ExitCode int
// IPs maps network name to IPv4 address.
IPs map[string]string
// Ports maps "5432/tcp" to the published host address.
Ports map[string]string
}
Container is an inspected container.
type ContainerSpec ¶
type ContainerSpec struct {
Name string
Image string
Entrypoint []string
Cmd []string
Env []string
Labels map[string]string
Hostname string
Privileged bool
CapAdd []string
Sysctls map[string]string
// Networks: the first is used at create time, the rest are connected
// before start.
Networks []Attachment
Ports []Port
Mounts []Mount
// Tmpfs maps paths to mount options.
Tmpfs map[string]string
// CgroupnsHost runs in the host cgroup namespace (needed by some
// nested-container setups).
CgroupnsHost bool
// Memory limit in bytes (0 = unlimited).
Memory int64
// Init runs a tiny init as PID 1 to reap zombies.
Init bool
}
ContainerSpec describes a container to create.
type ExecResult ¶
ExecResult is the outcome of Exec.
type File ¶
type File struct {
Name string // path relative to the destination directory
Mode int64
Data []byte
// Path, if set, is read from the local filesystem instead of Data.
Path string
}
File is a file to copy into a container.
type Info ¶
type Info struct {
Name string // "docker" or "podman"
Version string
Arch string // GOARCH-style
Rootless bool
}
Info describes the connected runtime.
type Manager ¶
type Manager struct {
*Client
Info Info
InstanceID string
Instance string
Offline bool
// Ephemeral instances also delete volumes and networks on cleanup.
Ephemeral bool
Log *slog.Logger
}
Manager scopes runtime objects to one emulator instance: it names and labels them, and reclaims orphans left by a crashed run (FR-CORE-006).
func (*Manager) Cleanup ¶
Cleanup removes all of the instance's containers; with all=true also its networks and volumes.
type Mount ¶
type Mount struct {
Type string // "volume", "bind" or "tmpfs"
Source string
Target string
ReadOnly bool
}
Mount is a volume, bind or tmpfs mount.
type Network ¶
type Network struct {
ID string
Name string
Subnet string
Gateway string
Internal bool
Labels map[string]string
// Bridge is the host interface name, when the runtime reports it.
Bridge string
}
Network is an inspected network.
type NetworkSpec ¶
type NetworkSpec struct {
Name string
Subnet string // CIDR
Gateway string // optional; defaults to the first host address
Internal bool // no external connectivity
Labels map[string]string
// MTU sets com.docker.network.driver.mtu when non-zero.
MTU int
// Options are extra driver options (e.g. com.docker.network.bridge.*).
Options map[string]string
}
NetworkSpec describes a bridge network.