dockerfile

package
v0.0.0-...-f47f8cc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

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

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

func ComputeFilesHash(src, dest, contextPath string, ignorePatterns []string) (string, error)

ComputeFilesHash computes the SHA-256 hash for files referenced by COPY. It matches the template file hashing behavior:

  1. hash.Update("COPY src dest")
  2. 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

func ParseCommand(rest string) string

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

func ParseEnvValues(rest string, escapeToken rune) ([]string, error)

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

func ReadDockerignore(contextPath string) []string

ReadDockerignore reads .dockerignore rules from the build context directory.

func StripHeredocMarkers

func StripHeredocMarkers(s string) string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL