Help us shape the future of Go! Take the 2026 Go Developer Survey

driver

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package driver is the builder's view of the engine: the operations a build needs (inspect, pull, load, tag, create, archive in and out, run, commit), and Client, which performs them over the engine's API — the subset of the Docker Engine API that wctrd serves, plus the endpoints a builder needs from it (commit, tag, load, container archives).

Index

Constants

View Source
const (
	ExitNotExecutable = 126
	ExitMissing       = 127
)

Exit statuses the engine uses (engine/runtime).

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound reports a missing image or container.

Functions

func StripVersion added in v0.2.1

func StripVersion(base string) string

StripVersion removes a trailing "/vMAJOR.MINOR" (and slashes) from base.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client speaks the engine's API.

func Dial

func Dial(host string) (*Client, error)

Dial connects to "unix:///path/to/socket", wctr's host syntax.

func NewClient

func NewClient(hc *http.Client, base string) *Client

NewClient talks to base through hc: a unix-socket transport natively, the engine's in-process transport in a browser. base may or may not end with an API version ("http://wctr" or "http://wctr/v1.47", which is what the engine's api.Client.HTTP returns): the version is never doubled, and requests always go to this client's API version.

func (*Client) Commit

func (c *Client) Commit(ctx context.Context, spec CommitSpec) (string, error)

Commit implements Engine (POST /commit).

func (*Client) CreateContainer

func (c *Client) CreateContainer(ctx context.Context, spec RunSpec) (string, error)

CreateContainer implements Engine.

func (*Client) GetArchive

func (c *Client) GetArchive(ctx context.Context, id, p string) (io.ReadCloser, error)

GetArchive implements Engine.

func (*Client) InspectImage

func (c *Client) InspectImage(ctx context.Context, ref string) (*Image, error)

InspectImage implements Engine.

func (*Client) LoadImage

func (c *Client) LoadImage(ctx context.Context, layout io.Reader) (string, error)

LoadImage implements Engine (POST /images/load).

func (*Client) PullImage

func (c *Client) PullImage(ctx context.Context, ref string, progress io.Writer) error

PullImage implements Engine.

func (*Client) PutArchive

func (c *Client) PutArchive(ctx context.Context, id, dir string, tar io.Reader) error

PutArchive implements Engine.

func (*Client) RemoveContainer

func (c *Client) RemoveContainer(ctx context.Context, id string) error

RemoveContainer implements Engine.

func (*Client) Run

func (c *Client) Run(ctx context.Context, id string, stdout, stderr io.Writer) (int, error)

Run implements Engine: register the wait, follow the logs, start, and copy the output while the step runs. The log stream is opened before the start (the engine follows a created container until it has run), so nothing is missed, however fast the step, and it ends when the step exits.

func (*Client) StatPath

func (c *Client) StatPath(ctx context.Context, id, p string) (bool, error)

StatPath implements Engine.

func (*Client) TagImage

func (c *Client) TagImage(ctx context.Context, image, repo, tag string) error

TagImage implements Engine.

type CommitSpec

type CommitSpec struct {
	Container string
	// Repo and Tag name the image; empty leaves it addressable by ID only.
	Repo, Tag string
	Comment   string
	Author    string
	// Config replaces the container's configuration in the image.
	Config ImageConfig
}

CommitSpec makes an image of a container.

type Engine

type Engine interface {
	// InspectImage returns ErrNotFound (wrapped) for a missing image.
	InspectImage(ctx context.Context, ref string) (*Image, error)
	// PullImage fetches ref for platform wasip1/wasm.
	PullImage(ctx context.Context, ref string, progress io.Writer) error
	// LoadImage imports an OCI image layout sent as a tar and returns the
	// ID of the image it named (or of its only image).
	LoadImage(ctx context.Context, layout io.Reader) (string, error)
	TagImage(ctx context.Context, image, repo, tag string) error
	CreateContainer(ctx context.Context, spec RunSpec) (string, error)
	// PutArchive extracts a tar into the container at dir.
	PutArchive(ctx context.Context, id, dir string, tar io.Reader) error
	// StatPath reports whether path exists in the container (HEAD on the
	// archive endpoint: no content is sent).
	StatPath(ctx context.Context, id, path string) (bool, error)
	// GetArchive returns a tar of path, its base name as the root entry.
	GetArchive(ctx context.Context, id, path string) (io.ReadCloser, error)
	// Run starts the container, copies its output, and returns its exit
	// status once it exits. A module that cannot be started is reported
	// as its exit status (127 missing, 126 not executable) with the
	// engine's message in err of type *ExitError.
	Run(ctx context.Context, id string, stdout, stderr io.Writer) (int, error)
	Commit(ctx context.Context, spec CommitSpec) (string, error)
	RemoveContainer(ctx context.Context, id string) error
}

Engine is what a build drives.

type ExitError

type ExitError struct {
	Code    int
	Message string
}

ExitError is a step that could not run.

func (*ExitError) Error

func (e *ExitError) Error() string

type HealthConfig

type HealthConfig struct {
	Test          []string `json:"Test,omitempty"`
	Interval      int64    `json:"Interval,omitempty"`
	Timeout       int64    `json:"Timeout,omitempty"`
	StartPeriod   int64    `json:"StartPeriod,omitempty"`
	StartInterval int64    `json:"StartInterval,omitempty"`
	Retries       int      `json:"Retries,omitempty"`
}

HealthConfig is an image's HEALTHCHECK (Docker's image config field). Durations are nanoseconds, as Docker stores them.

type Image

type Image struct {
	ID           string
	OS           string
	Architecture string
	Author       string
	Config       ImageConfig
	// Layers is the number of layers (bounded by the engine).
	Layers int
}

Image is what the builder needs to know of an image.

type ImageConfig

type ImageConfig struct {
	User         string              `json:"User,omitempty"`
	ExposedPorts map[string]struct{} `json:"ExposedPorts,omitempty"`
	Env          []string            `json:"Env,omitempty"`
	Entrypoint   []string            `json:"Entrypoint,omitempty"`
	Cmd          []string            `json:"Cmd,omitempty"`
	Volumes      map[string]struct{} `json:"Volumes,omitempty"`
	WorkingDir   string              `json:"WorkingDir,omitempty"`
	Labels       map[string]string   `json:"Labels,omitempty"`
	StopSignal   string              `json:"StopSignal,omitempty"`
	Shell        []string            `json:"Shell,omitempty"`
	OnBuild      []string            `json:"OnBuild,omitempty"`
	Healthcheck  *HealthConfig       `json:"Healthcheck,omitempty"`
}

ImageConfig is the "config" object of an image config: the OCI fields plus Docker's Shell, OnBuild and Healthcheck.

type RunSpec

type RunSpec struct {
	Image string
	// Entrypoint is the command; the image's Cmd is dropped.
	Entrypoint []string
	// Env is added to the image's (same key: this wins).
	Env        []string
	WorkingDir string
	User       string
	// Network: "" (the engine's default) or "none".
	Network string
}

RunSpec makes a container for one build step.

Jump to

Keyboard shortcuts

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