Documentation
¶
Overview ¶
Package builder provides container image building.
Index ¶
- func CompressGzip(data []byte) ([]byte, error)
- func CreateTar(dir string, writer io.Writer) error
- func DetectBuildKit() string
- func ExtractTar(r io.Reader, dest string) error
- func GenerateKey(instType string, args []string, env map[string]string) string
- func GenerateKeyFromReader(r io.Reader) (string, error)
- func ListSupportedInstructions() []string
- func StartBuildKitDaemon(ctx context.Context) (string, error)
- func Validate(content []byte) error
- type BuildCache
- func (c *BuildCache) Delete(key string)
- func (c *BuildCache) Get(key string) (string, bool)
- func (c *BuildCache) GetBytes(key string) ([]byte, bool)
- func (c *BuildCache) Has(key string) bool
- func (c *BuildCache) Purge() error
- func (c *BuildCache) Put(key string, layerPath string) error
- func (c *BuildCache) PutBytes(key string, data []byte) error
- func (c *BuildCache) Stats() CacheStats
- type BuildConfig
- type BuildKitBuildConfig
- type BuildKitClient
- type BuildKitProgressWriter
- type BuildProgressWriter
- type Builder
- func (b *Builder) Build(cfg *BuildConfig) error
- func (b *Builder) BuildWithBuildKit(ctx context.Context, cfg *BuildKitBuildConfig) error
- func (b *Builder) ExecuteBuildContext(contextDir, tarPath, _ string) error
- func (b *Builder) ExecuteStage(stage *Stage, contextDir, rootDir string) error
- func (b *Builder) GetBuildWriter() io.Writer
- func (b *Builder) WithCache(cache *BuildCache) *Builder
- func (b *Builder) WithLog(log *slog.Logger) *Builder
- func (b *Builder) WithProgress(tracker *ProgressTracker) *Builder
- type CacheEntry
- type CacheStats
- type Dockerignore
- type DokifileParser
- type Instruction
- type ProgressCallback
- type ProgressEvent
- type ProgressTracker
- type Stage
- type StepTimer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompressGzip ¶
CompressGzip compresses data using gzip.
func DetectBuildKit ¶
func DetectBuildKit() string
DetectBuildKit searches for a BuildKit daemon. Returns the address if found, empty string otherwise.
func ExtractTar ¶
ExtractTar extracts a tar archive (optionally gzip-compressed) to dest directory.
func GenerateKey ¶
GenerateKey generates a cache key from instruction and context.
func GenerateKeyFromReader ¶
GenerateKeyFromReader generates a cache key from a reader.
func ListSupportedInstructions ¶
func ListSupportedInstructions() []string
ListSupportedInstructions returns all supported Dokifile instructions.
func StartBuildKitDaemon ¶
StartBuildKitDaemon starts a BuildKit daemon if not already running. This is useful for environments where BuildKit is not pre-installed.
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) 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) Put ¶
func (c *BuildCache) Put(key string, layerPath string) error
Put stores a layer in the cache.
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
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.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder builds OCI images from Dokifiles.
func NewBuilder ¶
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 ¶
ExecuteBuildContext extracts a build context and sets it up.
func (*Builder) ExecuteStage ¶
ExecuteStage runs all instructions in a build stage.
func (*Builder) GetBuildWriter ¶
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) 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 ¶
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.