Documentation
¶
Overview ¶
Package parser reads a Containerfile (a Dockerfile: same syntax) into a list of instructions, following the grammar of the Dockerfile reference and of BuildKit's frontend/dockerfile/parser: parser directives (syntax, escape, check) before anything else, comments, line continuation with the escape token, and per-instruction argument forms (JSON array or shell string, whitespace lists, key=value pairs, ONBUILD sub-instructions, HEALTHCHECK types). It does no variable expansion: that is package expand's, at build time.
BuildKit's parser itself is not imported: it would add 34 packages and 6.1 MB to a js/wasm build (measured in docs/REFERENCES.md), and the builder runs in the browser playground too.
The input is untrusted: its size, line length and instruction count are bounded.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultLimits = Limits{MaxBytes: 1 << 20, MaxLineBytes: 256 << 10, MaxInstructions: 4096}
DefaultLimits are generous for any real Containerfile.
var ErrTooLarge = errors.New("containerfile too large")
ErrTooLarge reports input beyond the limits.
Functions ¶
This section is empty.
Types ¶
type Limits ¶
type Limits struct {
MaxBytes int64 // whole file
MaxLineBytes int // one physical line
MaxInstructions int
}
Limits bound what Parse accepts.
type Node ¶
type Node struct {
// Cmd is the instruction, lowercased ("from", "run", ...).
Cmd string
// Original is the logical line as written (continuations joined).
Original string
// Flags are the leading --name[=value] words, unexpanded.
Flags []string
// Args are the arguments, in BuildKit's AST order: a JSON array's
// elements; a shell-form string as one element; whitespace-separated
// words; for ENV and LABEL, triplets key, value, separator ("=" or ""
// for the legacy "ENV key value" form); for ARG, the raw words; for
// HEALTHCHECK, the type then its command.
Args []string
// JSON reports the exec (JSON array) form.
JSON bool
// Sub is ONBUILD's instruction.
Sub *Node
// StartLine and EndLine are 1-based.
StartLine, EndLine int
}
Node is one instruction.
type Result ¶
type Result struct {
Nodes []*Node
// Escape is the escape token: '\\' or '`'.
Escape rune
// Directives found at the top ("syntax", "escape", "check").
Directives map[string]string
// Warnings are non-fatal findings (empty continuation lines).
Warnings []string
}
Result is a parsed file.