dockerfile

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureFinalStageName

func EnsureFinalStageName(content, defaultName string) (string, string, error)

EnsureFinalStageName adds "AS <name>" to the last FROM if it doesn't have one. Returns (stageName, modifiedContent, error). If the stage already has a name, modifiedContent is empty.

func RemoveSyntaxVersion

func RemoveSyntaxVersion(content string) string

RemoveSyntaxVersion strips the # syntax=... directive from Dockerfile content.

Types

type Dockerfile

type Dockerfile struct {
	// Raw is the original Dockerfile content.
	Raw string

	// Preamble holds ARG instructions before the first FROM.
	Preamble *Preamble

	// Stages is the ordered list of build stages.
	Stages []*Stage

	// StagesByTarget maps stage names to stages for quick lookup.
	StagesByTarget map[string]*Stage
}

Dockerfile represents a parsed Dockerfile.

func Parse

func Parse(content string) (*Dockerfile, error)

Parse parses Dockerfile content into a structured Dockerfile.

func (*Dockerfile) FindBaseImage

func (d *Dockerfile) FindBaseImage(buildArgs map[string]string, target string) string

FindBaseImage resolves the base image for the given target stage, expanding ARG variables and following stage references. If target is empty, the last stage is used.

func (*Dockerfile) FindUserStatement

func (d *Dockerfile) FindUserStatement(buildArgs, baseImageEnv map[string]string, target string) string

FindUserStatement returns the last USER instruction in the target stage chain, resolving ARG/ENV variables. Returns empty string if no USER found.

type Preamble

type Preamble struct {
	Args []instructions.KeyValuePairOptional
}

Preamble holds instructions before the first FROM (typically ARG).

type Stage

type Stage struct {
	// Image is the base image (FROM value).
	Image string

	// Target is the stage name (AS value), empty if unnamed.
	Target string

	// Envs are ENV instructions in this stage.
	Envs []instructions.KeyValuePair

	// Args are ARG instructions in this stage.
	Args []instructions.KeyValuePairOptional

	// Users are USER instructions in this stage.
	Users []string

	// Commands is the list of parsed instructions in this stage.
	Commands []instructions.Command
}

Stage represents a single build stage (FROM ... to next FROM or EOF).

Jump to

Keyboard shortcuts

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