Documentation
¶
Overview ¶
Package dockerfile provides a lightweight Dockerfile parser.
It parses Dockerfile content into structured instructions and supports escape directives, line continuations, heredoc syntax, and quote-aware value parsing. The parser follows buildkit lexical behavior without depending on buildkit.
This package intentionally avoids SDK-specific types. Callers can convert the generic Instruction values into their own domain models.
Index ¶
- func CollectAndUpload(ctx context.Context, uploadURL, src, contextPath string, ...) error
- func ComputeFilesHash(src, dest, contextPath string, ignorePatterns []string) (string, error)
- func ParseCommand(rest string) string
- func ParseEnvValues(rest string, escapeToken rune) ([]string, error)
- func ReadDockerignore(contextPath string) []string
- func StripHeredocMarkers(s string) string
- type Instruction
- type ParseResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollectAndUpload ¶
func CollectAndUpload(ctx context.Context, uploadURL, src, contextPath string, ignorePatterns []string) error
CollectAndUpload gathers source files, streams a gzip tar archive, and uploads it to the URL. It uses io.Pipe so the full archive does not need to be loaded into memory.
func ComputeFilesHash ¶
ComputeFilesHash computes the SHA-256 hash for files referenced by COPY. It matches the template file hashing behavior:
- hash.Update("COPY src dest")
- for each file sorted by relative POSIX path: hash.Update(relative POSIX path) hash.Update(file mode) hash.Update(file size) hash.Update(file contents)
func ParseCommand ¶
ParseCommand parses CMD or ENTRYPOINT arguments. It supports exec form ["cmd", "arg1", ...] and shell form. Exec-form arguments containing shell metacharacters are single-quoted for bash safety.
func ParseEnvValues ¶
ParseEnvValues parses ENV-style KEY=VALUE pairs with quote handling. It supports double quotes with escapes, single-quoted literals, and unquoted values. It returns a flat key/value slice: ["K1", "V1", "K2", "V2", ...].
func ReadDockerignore ¶
ReadDockerignore reads .dockerignore rules from the build context directory.
func StripHeredocMarkers ¶
StripHeredocMarkers removes <<WORD markers from a string.
Types ¶
type Instruction ¶
type Instruction struct {
// Name is the upper-case instruction name, such as "RUN", "COPY", or "ENV".
Name string
// Args is the raw argument string after the instruction name.
Args string
// Flags contains --flag=value options extracted from the instruction.
Flags map[string]string
// Heredoc contains the heredoc body when the instruction uses heredoc syntax.
Heredoc string
// Line is the 1-based line number in the original Dockerfile.
Line int
}
Instruction represents a parsed Dockerfile instruction.
type ParseResult ¶
type ParseResult struct {
// Instructions is the ordered list of parsed instructions.
Instructions []Instruction
// Warnings contains non-fatal parse issues, such as unknown instructions.
Warnings []string
// EscapeToken is the active escape character, defaulting to '\' and optionally '`'.
EscapeToken rune
}
ParseResult holds the full Dockerfile parse output.
func Parse ¶
func Parse(content string) (*ParseResult, error)
Parse parses Dockerfile content into a ParseResult.