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

builder

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package builder is the top-level orchestrator. It loads a devcontainer.json, resolves devcontainer features, downloads the VS Code server when asked, and builds the image with BuildKit: an upstream Dockerfile through the dockerfile.v0 frontend, with the devcontainer overlays authored directly in LLB on top.

The wrapper Dockerfile is always written to the work directory for inspection and for the `generate` subcommand; it is not what BuildKit builds.

--- relationships:

references: [CONTRIBUTING]

---

relationships:

references: [dockerfileuser, metadata, oci]

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	Resolver   *features.Resolver
	Downloader *vscode.Downloader
}

Builder is reusable across builds.

func New

func New() *Builder

New constructs a Builder with default helpers.

func (*Builder) BaseMetadata

func (b *Builder) BaseMetadata(ctx context.Context, dc *spec.DevContainer, opts Options) ([]metadata.Entry, error)

BaseMetadata reads the inherited metadata for the already-loaded config. Dockerfile configs follow the selected target's base-image ancestry. Image configs come from opts.Docker (or the default Engine client) when present locally for the requested platform, otherwise from the resolver's OCI registry client. SkipImageMetaResolve disables registry lookup. It does not build or pull image layers, and does not reload the devcontainer configuration.

func (*Builder) Build

func (b *Builder) Build(ctx context.Context, opts Options) (*Result, error)

Build executes a full devcontainer build.

func (*Builder) Generate

func (b *Builder) Generate(ctx context.Context, opts Options) (*Result, error)

Generate runs every step of Build except the BuildKit solve. It is the dry-run companion to Build, useful for inspecting the generated Dockerfile or for callers that want to drive a build themselves.

When the spec uses an upstream Dockerfile (rather than spec.image), this method does NOT pre-build it — instead, the wrapper Dockerfile's FROM line is left as a placeholder string. Callers that want to resolve that themselves should use Build directly.

type Options

type Options struct {
	// Spec supplies an already loaded configuration. When set, Build and Generate
	// use this snapshot instead of reading SpecPath or discovering another file.
	// The caller must keep it immutable for the duration of the call. Path retains
	// the original configuration location for relative build and feature paths.
	Spec *spec.DevContainer
	// SpecPath is an explicit path to a devcontainer.json. When empty,
	// Workspace is searched for the conventional locations.
	SpecPath string
	// Workspace is the workspace folder the spec was authored for. It
	// is used as the default build context root and to discover the
	// spec when SpecPath is empty.
	Workspace string
	// FeatureBaseDir overrides the directory used to resolve relative
	// local feature references. Empty means the devcontainer.json
	// directory.
	FeatureBaseDir string
	// FeatureLockfile is the invocation's lockfile snapshot. The caller publishes
	// it after the complete command succeeds, including up's lifecycle work.
	FeatureLockfile *features.LockfileState

	// Tags applied to the produced image.
	Tags []string
	// Platforms (e.g., "linux/amd64", "linux/arm64"). The BuildKit
	// engine builds a manifest-list image when more than one is given.
	// --load is incompatible with multi-platform.
	Platforms []string
	// BuildKitAddress selects a separate BuildKit. Empty falls back to
	// BUILDKIT_HOST, then to the Docker daemon's built-in BuildKit.
	BuildKitAddress string
	// Docker is the Engine API client used to reach the daemon. When
	// nil, one is created from the standard DOCKER_* environment.
	Docker *dockerclient.Client
	// RegistryAuth supplies the registry credentials of the call: the
	// BuildKit session and push, OCI feature downloads, and base image
	// configuration reads. When nil, BuildKit reads the docker CLI's
	// configuration (registryauth.FromEnvironment), and feature downloads
	// and image configuration reads use the Builder's Resolver.OCI client.
	RegistryAuth buildkit.RegistryAuth
	// BuildArgs / Labels.
	BuildArgs map[string]string
	Labels    map[string]string
	// CacheFrom / CacheTo cache specs in `docker build` form, e.g.
	// "type=registry,ref=...".
	CacheFrom []string
	CacheTo   []string

	// Push uploads the result to the registry described by Tags.
	Push bool
	// Load loads the result into the Docker daemon's image store.
	Load bool
	// NoCache disables the build cache.
	NoCache bool
	// Pull always re-pulls referenced images.
	Pull bool
	// Progress one of "auto" | "plain" | "tty" | "rawjson".
	Progress string
	// Output is a buildx exporter specification or a local destination path.
	Output string
	// OutputWriter receives archive output when dest is "-" or omitted.
	OutputWriter io.Writer
	// OutputDir, when non-empty, requests filesystem export to this
	// path.
	OutputDir string

	// SkipFeatures disables feature resolution and installation.
	SkipFeatures bool
	// SkipFeatureAutoMapping disables upstream's legacy feature ID mapping.
	SkipFeatureAutoMapping bool
	// Metadata controls only newly persisted feature/config contributions.
	Metadata metadata.CollectOptions
	// OmitSyntaxDirective ignores authored Dockerfile syntax directives and
	// omits the directive from the generated inspection Dockerfile.
	OmitSyntaxDirective bool
	// InstallVSCodeServer stages the VS Code server into the image.
	// Off by default: editors that attach install their own server.
	InstallVSCodeServer bool
	// SkipImageMetaResolve disables the registry roundtrip that
	// inherits ENV/USER/WORKDIR and metadata from the base image.
	// A locally supplied Docker image is still inspected for metadata labels.
	SkipImageMetaResolve bool

	// VSCode controls server resolution. Zero value = stable, current
	// platform, latest commit.
	VSCode vscode.Spec

	// WorkDir is where intermediate artifacts (the generated build
	// context) are written. When empty, a directory under os.TempDir()
	// is used.
	WorkDir string
	// UserDataFolder contains private staging folders when WorkDir is unset.
	UserDataFolder string
	// KeepWorkDir keeps the working directory for inspection after the
	// build. Default removes it.
	KeepWorkDir bool

	// Logger receives informational messages.
	Logger func(format string, args ...any)
	// Stdout / Stderr are forwarded to the build engine.
	Stdout io.Writer
	Stderr io.Writer
}

Options drive a single Build invocation.

type Result

type Result struct {
	// FinalDockerfile is the path to the inspection-only wrapper
	// Dockerfile.
	FinalDockerfile string
	// ContextDir is the on-disk build context (features + vscode
	// tarball staging directory).
	ContextDir string
	// VSCodeServer reports details on the staged server, if any.
	VSCodeServer *vscode.Result
	// Features is the resolved feature list in install order.
	Features []features.Resolved
}

Result describes the outcome of a successful build.

Jump to

Keyboard shortcuts

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