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

builder

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package builder provides container image building.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompressGzip

func CompressGzip(data []byte) ([]byte, error)

CompressGzip compresses data using gzip.

func CreateTar

func CreateTar(dir string, writer io.Writer) error

CreateTar creates a tar archive from a directory.

func DetectBuildKit

func DetectBuildKit() string

DetectBuildKit searches for a BuildKit daemon. Returns the address if found, empty string otherwise.

func ExtractTar

func ExtractTar(r io.Reader, dest string) error

ExtractTar extracts a tar archive (optionally gzip-compressed) to dest directory.

func GenerateKey

func GenerateKey(instType string, args []string, env map[string]string) string

GenerateKey generates a cache key from instruction and context.

func GenerateKeyFromReader

func GenerateKeyFromReader(r io.Reader) (string, error)

GenerateKeyFromReader generates a cache key from a reader.

func ListSupportedInstructions

func ListSupportedInstructions() []string

ListSupportedInstructions returns all supported Dokifile instructions.

func StartBuildKitDaemon

func StartBuildKitDaemon(ctx context.Context) (string, error)

StartBuildKitDaemon starts a BuildKit daemon if not already running. This is useful for environments where BuildKit is not pre-installed.

func Validate

func Validate(content []byte) error

Validate checks if a Dokifile is valid.

Types

type BuildCache

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

BuildCache provides content-addressable layer caching for builds. Each layer is identified by its content hash, allowing reuse across builds.

func NewBuildCache

func NewBuildCache(root string, maxSize int64) *BuildCache

NewBuildCache creates a new build cache.

func (*BuildCache) Delete

func (c *BuildCache) Delete(key string)

Delete removes a cached layer.

func (*BuildCache) Get

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

Get retrieves a cached layer by its key. Returns the layer path and true if found, or "" and false if not.

func (*BuildCache) GetBytes

func (c *BuildCache) GetBytes(key string) ([]byte, bool)

GetBytes retrieves cached content as bytes.

func (*BuildCache) Has

func (c *BuildCache) Has(key string) bool

Has checks if a key exists in the cache.

func (*BuildCache) Purge

func (c *BuildCache) Purge() error

Purge removes all cached layers.

func (*BuildCache) Put

func (c *BuildCache) Put(key string, layerPath string) error

Put stores a layer in the cache.

func (*BuildCache) PutBytes

func (c *BuildCache) PutBytes(key string, data []byte) error

PutBytes stores byte content in the cache.

func (*BuildCache) Stats

func (c *BuildCache) Stats() CacheStats

Stats returns cache statistics.

type BuildConfig

type BuildConfig struct {
	Context     string
	Dokifile    string
	Tags        []string
	BuildArgs   map[string]string
	Labels      map[string]string
	NoCache     bool
	Pull        bool
	Target      string
	Platform    string
	NetworkMode string
	ExtraHosts  []string
	Output      string
	Secrets     map[string]string
	SSH         []string
	ContextTar  string
}

BuildConfig holds configuration for a build.

type BuildKitBuildConfig

type BuildKitBuildConfig struct {
	*BuildConfig

	// BuildKitAddr is the BuildKit daemon address.
	// If empty, falls back to local build.
	BuildKitAddr string

	// ExportCache is the cache export destination.
	ExportCache string

	// ImportCache is the cache import source.
	ImportCache string

	// LLB is the raw LLB definition (advanced).
	LLB []byte
}

BuildKitBuildConfig extends BuildConfig with BuildKit-specific options.

type BuildKitClient

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

BuildKitClient communicates with a BuildKit daemon for advanced builds. BuildKit provides:

  • Parallel stage execution
  • Content-addressable layer caching
  • Advanced mount types (cache, secret, ssh)
  • Multi-platform builds
  • Build graph optimization

func NewBuildKitClient

func NewBuildKitClient(addr string) *BuildKitClient

NewBuildKitClient creates a new BuildKit client.

func (*BuildKitClient) Build

func (c *BuildKitClient) Build(ctx context.Context, cfg *BuildConfig) error

Build sends a build request to the BuildKit daemon. This is the "delegation" path: instead of building locally, we ask BuildKit to do it (which is faster and supports more features).

func (*BuildKitClient) IsAvailable

func (c *BuildKitClient) IsAvailable() bool

IsAvailable checks if a BuildKit daemon is reachable.

func (*BuildKitClient) Solve

func (c *BuildKitClient) Solve(_ context.Context, _ []byte) error

Solve sends a solve request to BuildKit. This is the advanced API for custom build graphs.

func (*BuildKitClient) Status

func (c *BuildKitClient) Status() (map[string]interface{}, error)

Status returns the BuildKit daemon status.

type BuildKitProgressWriter

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

BuildKitProgressWriter parses BuildKit progress output and reports it.

func NewBuildKitProgressWriter

func NewBuildKitProgressWriter(log *slog.Logger) *BuildKitProgressWriter

func (*BuildKitProgressWriter) Write

func (w *BuildKitProgressWriter) Write(p []byte) (n int, err error)

type BuildProgressWriter

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

BuildProgressWriter is an io.Writer that captures build output and reports progress.

func NewBuildProgressWriter

func NewBuildProgressWriter(tracker *ProgressTracker) *BuildProgressWriter

NewBuildProgressWriter creates a new build progress writer.

func (*BuildProgressWriter) Write

func (w *BuildProgressWriter) Write(p []byte) (n int, err error)

type Builder

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

Builder builds OCI images from Dokifiles.

func NewBuilder

func NewBuilder(store *image.Store) *Builder

NewBuilder creates a new image builder.

func (*Builder) Build

func (b *Builder) Build(cfg *BuildConfig) error

Build executes a build from a Dokifile.

func (*Builder) BuildWithBuildKit

func (b *Builder) BuildWithBuildKit(ctx context.Context, cfg *BuildKitBuildConfig) error

BuildWithBuildKit builds using BuildKit if available, falls back to local.

func (*Builder) ExecuteBuildContext

func (b *Builder) ExecuteBuildContext(contextDir, tarPath, _ string) error

ExecuteBuildContext extracts a build context and sets it up.

func (*Builder) ExecuteStage

func (b *Builder) ExecuteStage(stage *Stage, contextDir, rootDir string) error

ExecuteStage runs all instructions in a build stage.

func (*Builder) GetBuildWriter

func (b *Builder) GetBuildWriter() io.Writer

GetBuildWriter returns an io.Writer for build output.

func (*Builder) WithCache

func (b *Builder) WithCache(cache *BuildCache) *Builder

WithCache sets the build cache for the builder.

func (*Builder) WithLog

func (b *Builder) WithLog(log *slog.Logger) *Builder

WithLog sets the logger for the builder.

func (*Builder) WithProgress

func (b *Builder) WithProgress(tracker *ProgressTracker) *Builder

WithProgress sets the progress tracker for the builder.

type CacheEntry

type CacheEntry struct {
	Key       string    `json:"key"`
	Digest    string    `json:"digest"`
	Size      int64     `json:"size"`
	CreatedAt time.Time `json:"created_at"`
	LastUsed  time.Time `json:"last_used"`
	HitCount  int64     `json:"hit_count"`
	LayerPath string    `json:"layer_path"`
}

CacheEntry represents a cached build layer.

type CacheStats

type CacheStats struct {
	Entries   int     `json:"entries"`
	TotalSize int64   `json:"total_size"`
	Hits      int64   `json:"hits"`
	Misses    int64   `json:"misses"`
	HitRate   float64 `json:"hit_rate"`
}

CacheStats returns cache statistics.

type Dockerignore

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

Dockerignore represents parsed .dockerignore rules.

func ParseDockerignore

func ParseDockerignore(path string) (*Dockerignore, error)

ParseDockerignore parses a .dockerignore file.

func (*Dockerignore) Matches

func (d *Dockerignore) Matches(path string) bool

Matches checks if a path matches any .dockerignore pattern.

type DokifileParser

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

DokifileParser parses a Dokifile (Dockerfile-compatible).

func NewDokifileParser

func NewDokifileParser() *DokifileParser

NewDokifileParser creates a new Dokifile parser.

func (*DokifileParser) GetDirective

func (p *DokifileParser) GetDirective(key string) string

func (*DokifileParser) GetGlobalArgs added in v0.9.3

func (p *DokifileParser) GetGlobalArgs() map[string]string

func (*DokifileParser) GetStages

func (p *DokifileParser) GetStages() []*Stage

GetStages returns all parsed stages.

func (*DokifileParser) Parse

func (p *DokifileParser) Parse(content []byte) error

Parse parses a Dokifile.

type Instruction

type Instruction struct {
	Type    string
	Args    []string
	Raw     string
	LineNum int
}

Instruction represents a single instruction in a Dokifile.

type ProgressCallback

type ProgressCallback func(event ProgressEvent)

ProgressCallback is called for each progress event.

type ProgressEvent

type ProgressEvent struct {
	ID      string        `json:"id"`
	Type    string        `json:"type"` // "step", "output", "error", "complete"
	Message string        `json:"message"`
	Stage   string        `json:"stage,omitempty"`
	Step    int           `json:"step,omitempty"`
	Total   int           `json:"total,omitempty"`
	Elapsed time.Duration `json:"elapsed,omitempty"`
}

ProgressEvent represents a build progress event.

type ProgressTracker

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

ProgressTracker tracks build progress and reports it.

func NewProgressTracker

func NewProgressTracker(log *slog.Logger, callback ProgressCallback) *ProgressTracker

NewProgressTracker creates a new progress tracker.

func NewProgressTrackerWithWriter

func NewProgressTrackerWithWriter(w io.Writer) *ProgressTracker

NewProgressTrackerWithWriter creates a progress tracker that writes to a writer.

func (*ProgressTracker) Complete

func (p *ProgressTracker) Complete(message string)

Complete marks the build as complete.

func (*ProgressTracker) Error

func (p *ProgressTracker) Error(message string)

Error logs a build error.

func (*ProgressTracker) Output

func (p *ProgressTracker) Output(message string)

Output logs build output.

func (*ProgressTracker) SetStage

func (p *ProgressTracker) SetStage(name string, totalSteps int)

SetStage sets the current build stage.

func (*ProgressTracker) Step

func (p *ProgressTracker) Step(message string)

Step advances to the next step.

type Stage

type Stage struct {
	Name         string
	From         string
	FromStage    string
	Platform     string
	Instructions []Instruction
	Metadata     map[string]string
	ImageConfig  *image.ImageConfig
	Layers       []string
}

Stage represents a build stage in a Dokifile.

type StepTimer

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

StepTimer tracks the duration of a build step.

func NewStepTimer

func NewStepTimer(name string, tracker *ProgressTracker) *StepTimer

NewStepTimer creates a new step timer.

func (*StepTimer) Stop

func (t *StepTimer) Stop()

Stop stops the timer and reports the duration.

Jump to

Keyboard shortcuts

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