context

package
v0.25.3 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package context provides build context awareness for Dockerfile linting. It handles .dockerignore parsing and file existence checking.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadDockerignore

func LoadDockerignore(contextDir string) ([]string, error)

LoadDockerignore reads ignore patterns from the first existing ignore file (.dockerignore preferred, then .containerignore). Returns nil if no ignore file exists. An empty ignore file is valid and means "ignore no files" - we don't fall through to the next file in that case.

Types

type BuildContext

type BuildContext struct {
	// ContextDir is the absolute path to the build context directory.
	ContextDir string

	// DockerfilePath is the absolute path to the Dockerfile being linted.
	DockerfilePath string
	// contains filtered or unexported fields
}

BuildContext provides build-time context for context-aware rules. It manages .dockerignore patterns and file existence checking.

func New

func New(contextDir, dockerfilePath string, opts ...Option) (*BuildContext, error)

New creates a new BuildContext for the given context directory. The dockerfilePath is used for relative path calculations.

func (*BuildContext) AddHeredocFile

func (ctx *BuildContext) AddHeredocFile(path string)

AddHeredocFile marks a path as a virtual heredoc file.

func (*BuildContext) FileExists

func (ctx *BuildContext) FileExists(path string) bool

FileExists checks if a file exists in the build context. The path should be relative to the build context. Returns false for directories (only regular files return true).

func (*BuildContext) HasIgnoreExclusions added in v0.20.0

func (ctx *BuildContext) HasIgnoreExclusions() bool

HasIgnoreExclusions returns true if .dockerignore contains negated patterns (lines starting with !). When exclusions exist, static copy-source validation is unreliable because a directory may be excluded but a file inside it re-included.

func (*BuildContext) HasIgnoreFile

func (ctx *BuildContext) HasIgnoreFile() bool

HasIgnoreFile returns true if a .dockerignore file exists.

func (*BuildContext) IsHeredocFile

func (ctx *BuildContext) IsHeredocFile(path string) bool

IsHeredocFile checks if a path is a virtual heredoc file. Heredoc files are created inline in the Dockerfile and should not be checked against .dockerignore.

func (*BuildContext) IsIgnored

func (ctx *BuildContext) IsIgnored(path string) (bool, error)

IsIgnored checks if a path would be ignored by .dockerignore. The path should be relative to the build context.

func (*BuildContext) Patterns

func (ctx *BuildContext) Patterns() []string

Patterns returns the .dockerignore patterns (for debugging).

type Option

type Option func(*BuildContext)

Option configures a BuildContext.

func WithHeredocFiles

func WithHeredocFiles(files map[string]bool) Option

WithHeredocFiles sets the virtual heredoc files. These files are created by heredoc syntax in COPY/ADD commands and should not trigger copy-ignored-file warnings.

Jump to

Keyboard shortcuts

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