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

builder

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: 27 Imported by: 0

Documentation

Overview

Package builder builds an OCI image from a Containerfile by driving the engine: each step runs in a container made from the previous step's image, which is then committed — RUN executes a WebAssembly program there, COPY and ADD extract a computed layer into it, and metadata instructions (ENV, LABEL, CMD, …) commit an empty layer with the new configuration, so the image's history has one entry per instruction.

The builder reads only the Containerfile and the build context it is given (in memory); it never opens a host path and fetches nothing from the network itself. Steps are cached by parent image, resulting configuration, instruction and input digest.

Index

Constants

View Source
const (
	MaxConfigBytes = 1 << 20
	MaxVarBytes    = 1 << 20
)

MaxConfigBytes bounds an image configuration (the engine reads configs of at most 4 MiB) and, with MaxVarBytes, what ENV and ARG can hold.

View Source
const MaxLayers = 127

MaxLayers keeps a build below the engine's 128-layer bound.

View Source
const Platform = "wasip1/wasm"

Platform is the only platform the engine runs.

Variables

View Source
var DefaultShell = []string{"/bin/sh", "-c"}

DefaultShell runs shell-form RUN, CMD and ENTRYPOINT unless SHELL says otherwise.

Functions

func DefaultCachePath

func DefaultCachePath() (string, error)

DefaultCachePath is where wctr build keeps its cache natively.

Types

type Cache

type Cache interface {
	Get(key string) (string, bool)
	Put(key, imageID string)
}

Cache maps a step's cache key — the parent image, the image config the step produces, the step itself and the digest of its inputs — to the image a previous build committed for it. A hit is used only after the engine confirms the image still exists.

type FileCache

type FileCache struct {
	*MemoryCache
	// contains filtered or unexported fields
}

FileCache is a MemoryCache kept in a JSON file between builds.

func OpenFileCache

func OpenFileCache(path string, max int) *FileCache

OpenFileCache loads path (a missing file is an empty cache; a damaged one is discarded: the cache only ever saves work).

func (*FileCache) Save

func (fc *FileCache) Save() error

Save writes the cache (0600, through a temporary file and a rename).

type MemoryCache

type MemoryCache struct {
	Max int
	// contains filtered or unexported fields
}

MemoryCache is a bounded in-memory Cache (the oldest entries go first).

func NewMemoryCache

func NewMemoryCache(max int) *MemoryCache

NewMemoryCache holds at most max entries (4096 when max <= 0).

func (*MemoryCache) Get

func (c *MemoryCache) Get(key string) (string, bool)

Get implements Cache.

func (*MemoryCache) Put

func (c *MemoryCache) Put(key, id string)

Put implements Cache.

type Options

type Options struct {
	// Containerfile is the file's content; Name is shown in messages.
	Containerfile []byte
	Name          string
	// Context is the build context (nil: empty).
	Context *buildcontext.Context
	// Ignored says the context was filtered by an ignore file.
	Ignored   bool
	BuildArgs map[string]string
	// Target is the stage to build (default: the last).
	Target  string
	Tags    []string
	NoCache bool
	Engine  driver.Engine
	// Cache (nil: a cache for this build only).
	Cache Cache
	// Out receives the plain progress output (nil: discarded).
	Out io.Writer
	// MaxSteps bounds the instructions executed, ONBUILD triggers
	// included (default 1000).
	MaxSteps int
	// Limits bound COPY/ADD layers and --from sources.
	Limits buildcontext.Limits
}

Options of one build.

type Result

type Result struct {
	ImageID  string
	Steps    int
	Cached   int
	Warnings []string
}

Result of a build.

func Build

func Build(ctx context.Context, opt Options) (*Result, error)

Build runs a build and returns the image it made.

Jump to

Keyboard shortcuts

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