Documentation
¶
Overview ¶
Package dockerfile provides Dockerfile parsing and rewriting capabilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Rewrite ¶
func Rewrite(df *Dockerfile, opts RewriteOptions) string
Rewrite takes a parsed Dockerfile and produces an optimized version.
Types ¶
type Dockerfile ¶
type Dockerfile struct {
// Instructions is the ordered list of instructions.
Instructions []Instruction
// Stages is the number of build stages.
Stages int
// StageNames maps stage index to its AS alias.
StageNames map[int]string
// Raw is the original file content.
Raw string
}
Dockerfile represents a parsed Dockerfile.
func Parse ¶
func Parse(path string) (*Dockerfile, error)
Parse reads a Dockerfile from the given path and returns a parsed representation.
func ParseContent ¶
func ParseContent(content string) (*Dockerfile, error)
ParseContent parses Dockerfile content from a string.
func (*Dockerfile) GetBaseImage ¶
func (df *Dockerfile) GetBaseImage() string
GetBaseImage returns the base image from the first FROM instruction.
func (*Dockerfile) GetRunInstructions ¶
func (df *Dockerfile) GetRunInstructions() []Instruction
GetRunInstructions returns all RUN instructions.
func (*Dockerfile) IsMultiStage ¶
func (df *Dockerfile) IsMultiStage() bool
IsMultiStage returns true if the Dockerfile has more than one FROM instruction.
type Instruction ¶
type Instruction struct {
// Command is the instruction keyword (FROM, RUN, COPY, etc.).
Command string
// Args is everything after the command keyword.
Args string
// Original is the original raw line(s) from the Dockerfile.
Original string
// LineNumber is the starting line number (1-indexed).
LineNumber int
// Stage is the build stage this instruction belongs to.
Stage int
// StageName is the AS alias of the current stage (if any).
StageName string
}
Instruction represents a single Dockerfile instruction.
type RewriteOptions ¶
type RewriteOptions struct {
// BaseImage overrides the auto-detected base image.
BaseImage string
// MultiStage forces a multi-stage rewrite.
MultiStage bool
// Ecosystems detected in the project.
Ecosystems *ecosystem.DetectResult
// Platform is an optional --platform value (e.g., "linux/amd64").
Platform string
}
RewriteOptions controls how the Dockerfile is rewritten.
Click to show internal directories.
Click to hide internal directories.