Documentation
¶
Index ¶
- func CollectHeredocPaths(sourceContents []instructions.SourceContent) map[string]bool
- func ExtractHeredocFiles(stages []instructions.Stage) map[string]bool
- func HasHeredocs(result *ParseResult) bool
- func RunCommandString(run *instructions.RunCommand) string
- type HeredocInfo
- type HeredocKind
- type LintWarning
- type ParseResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollectHeredocPaths ¶
func CollectHeredocPaths(sourceContents []instructions.SourceContent) map[string]bool
CollectHeredocPaths extracts heredoc paths from a single COPY/ADD command's SourceContents into the provided map. This is useful for per-command filtering.
func ExtractHeredocFiles ¶
func ExtractHeredocFiles(stages []instructions.Stage) map[string]bool
ExtractHeredocFiles extracts virtual file paths from heredoc COPY/ADD commands. These are inline files created by heredoc syntax (e.g., COPY <<EOF /app/file.txt) that should not be checked against .dockerignore since they don't come from the build context.
func HasHeredocs ¶
func HasHeredocs(result *ParseResult) bool
HasHeredocs returns true if the parse result contains any heredocs.
func RunCommandString ¶
func RunCommandString(run *instructions.RunCommand) string
RunCommandString extracts the command string from a RUN instruction. Handles both shell form (RUN cmd) and exec form (RUN ["cmd", "arg"]).
Types ¶
type HeredocInfo ¶
type HeredocInfo struct {
// Heredoc is the BuildKit heredoc structure.
// Contains Name, Content, Expand, Chomp, and FileDescriptor.
parser.Heredoc
// Kind classifies the heredoc based on its containing instruction.
Kind HeredocKind
// Instruction is the Dockerfile instruction containing this heredoc.
// One of: RUN, COPY, ADD
Instruction string
// Line is the 0-based line number where the instruction starts.
// The heredoc content follows after the instruction line.
Line int
}
HeredocInfo represents a heredoc extracted from a Dockerfile instruction. This provides structured access to heredoc content with type classification.
BuildKit's parser.Heredoc is preserved in full, with additional context about which instruction contains the heredoc.
func ExtractHeredocs ¶
func ExtractHeredocs(result *ParseResult) []HeredocInfo
ExtractHeredocs extracts all heredocs from a parsed Dockerfile. Heredocs are classified by their containing instruction:
- RUN heredocs are scripts (HeredocKindScript)
- COPY/ADD heredocs are inline sources (HeredocKindInlineSource)
This classification is important for context-aware rules that need to distinguish between files from build context vs inline heredoc content.
func (HeredocInfo) IsInlineSource ¶
func (h HeredocInfo) IsInlineSource() bool
IsInlineSource returns true if the heredoc is inline content (COPY/ADD). Inline sources are not affected by .dockerignore and don't require file existence in the build context.
func (HeredocInfo) IsScript ¶
func (h HeredocInfo) IsScript() bool
IsScript returns true if the heredoc is a shell script (RUN).
type HeredocKind ¶
type HeredocKind int
HeredocKind classifies the type of heredoc based on its containing instruction.
const ( // HeredocKindUnknown indicates a heredoc in an unrecognized instruction. // This makes unclassified heredocs explicit rather than silently defaulting. HeredocKindUnknown HeredocKind = iota // HeredocKindScript indicates a heredoc in a RUN instruction. // The content is a shell script to be executed. HeredocKindScript // HeredocKindInlineSource indicates a heredoc in COPY or ADD instruction. // The content is an inline file that does not come from build context. // These are not affected by .dockerignore and don't require file existence. HeredocKindInlineSource )
func (HeredocKind) String ¶
func (k HeredocKind) String() string
String returns the string representation of the HeredocKind.
type LintWarning ¶
type LintWarning struct {
RuleName string
Description string
URL string
Message string
Location []parser.Range
}
LintWarning captures parameters from BuildKit's linter.LintWarnFunc callback. Fields match the callback signature exactly:
func(rulename, description, url, fmtmsg string, location []parser.Range)
BuildKit doesn't export a struct for this, so we provide one. See: github.com/moby/buildkit/frontend/dockerfile/linter.LintWarnFunc
type ParseResult ¶
type ParseResult struct {
// AST is the parsed Dockerfile AST from BuildKit
AST *parser.Result
// Stages contains the parsed build stages with typed instructions
Stages []instructions.Stage
// MetaArgs contains ARG instructions that appear before the first FROM
MetaArgs []instructions.ArgCommand
// Source is the raw source content of the Dockerfile
Source []byte
// Warnings contains lint warnings from BuildKit's built-in linter
Warnings []LintWarning
}
ParseResult contains the parsed Dockerfile information