instructions

package
v1.1.10 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasStage

func HasStage(s []Stage, name string) (int, bool)

HasStage looks for the presence of a given stage name from a list of stages.

func IsCurrentStage

func IsCurrentStage(s []Stage, name string) bool

IsCurrentStage returns true if the provided stage name is the name of the current stage, and false otherwise.

func Parse

func Parse(ast *parser.Node) (stages []Stage, metaArgs []ArgCommand, err error)

Parse a Dockerfile into a collection of buildable stages. metaArgs is a collection of ARG instructions that occur before the first FROM.

func ParseInstruction

func ParseInstruction(node *parser.Node) (v interface{}, err error)

ParseInstruction converts an AST to a typed instruction (either a command or a build stage beginning when encountering a `FROM` statement)

Types

type AddCommand

type AddCommand struct {
	SourcesAndDest
	Chown      string
	Chmod      string
	Link       bool
	KeepGitDir bool // whether to keep .git dir, only meaningful for git sources
	Checksum   string
	// contains filtered or unexported fields
}

AddCommand adds files from the provided sources to the target destination.

ADD foo /path

ADD supports tarball and remote URL handling, which may not always be desired - if you do not wish to have this automatic handling, use COPY.

func (*AddCommand) Expand

func (c *AddCommand) Expand(expander SingleWordExpander) error

func (*AddCommand) Location

func (c *AddCommand) Location() []parser.Range

Location of the command in source

func (*AddCommand) Name

func (c *AddCommand) Name() string

Name of the command

func (*AddCommand) String

func (c *AddCommand) String() string

type ArgCommand

type ArgCommand struct {
	Args []KeyValuePairOptional
	// contains filtered or unexported fields
}

ArgCommand adds the specified variable to the list of variables that can be passed to the builder using the --build-arg flag for expansion and substitution.

ARG name[=value]

func (*ArgCommand) Expand

func (c *ArgCommand) Expand(expander SingleWordExpander) error

func (*ArgCommand) Location

func (c *ArgCommand) Location() []parser.Range

Location of the command in source

func (*ArgCommand) Name

func (c *ArgCommand) Name() string

Name of the command

func (*ArgCommand) String

func (c *ArgCommand) String() string

type BFlags

type BFlags struct {
	Args []string // actual flags/args from cmd line

	Err error
	// contains filtered or unexported fields
}

BFlags contains all flags information for the builder

func NewBFlags

func NewBFlags() *BFlags

NewBFlags returns the new BFlags struct

func NewBFlagsWithArgs

func NewBFlagsWithArgs(args []string) *BFlags

NewBFlagsWithArgs returns the new BFlags struct with Args set to args

func (*BFlags) AddBool

func (bf *BFlags) AddBool(name string, def bool) *Flag

AddBool adds a bool flag to BFlags Note, any error will be generated when Parse() is called (see Parse).

func (*BFlags) AddString

func (bf *BFlags) AddString(name string, def string) *Flag

AddString adds a string flag to BFlags Note, any error will be generated when Parse() is called (see Parse).

func (*BFlags) AddStrings

func (bf *BFlags) AddStrings(name string) *Flag

AddStrings adds a string flag to BFlags that can match multiple values

func (*BFlags) Parse

func (bf *BFlags) Parse() error

Parse parses and checks if the BFlags is valid. Any error noticed during the AddXXX() funcs will be generated/returned here. We do this because an error during AddXXX() is more like a compile time error so it doesn't matter too much when we stop our processing as long as we do stop it, so this allows the code around AddXXX() to be just:

defFlag := AddString("description", "")

w/o needing to add an if-statement around each one.

func (*BFlags) Used

func (bf *BFlags) Used() []string

Used returns a slice of flag names that are set

type CmdCommand

type CmdCommand struct {
	ShellDependantCmdLine
	// contains filtered or unexported fields
}

CmdCommand sets the default command to run in the container on start.

CMD "echo hi"       # sh -c "echo hi"

or

CMD ["echo", "hi"]  # echo hi

func (*CmdCommand) Location

func (c *CmdCommand) Location() []parser.Range

Location of the command in source

func (*CmdCommand) Name

func (c *CmdCommand) Name() string

Name of the command

func (*CmdCommand) String

func (c *CmdCommand) String() string

type Command

type Command interface {
	Name() string
	Location() []parser.Range
}

Command interface is implemented by every possible command in a Dockerfile.

The interface only exposes the minimal common elements shared between every command, while more detailed information per-command can be extracted using runtime type analysis, e.g. type-switches.

func ParseCommand

func ParseCommand(node *parser.Node) (Command, error)

ParseCommand converts an AST to a typed Command

type CopyCommand

type CopyCommand struct {
	SourcesAndDest
	From    string
	Chown   string
	Chmod   string
	Link    bool
	Parents bool // parents preserves directory structure
	// contains filtered or unexported fields
}

CopyCommand copies files from the provided sources to the target destination.

COPY foo /path

Same as 'ADD' but without the magic additional tarball and remote URL handling.

func (*CopyCommand) Expand

func (c *CopyCommand) Expand(expander SingleWordExpander) error

func (*CopyCommand) Location

func (c *CopyCommand) Location() []parser.Range

Location of the command in source

func (*CopyCommand) Name

func (c *CopyCommand) Name() string

Name of the command

func (*CopyCommand) String

func (c *CopyCommand) String() string

type EntrypointCommand

type EntrypointCommand struct {
	ShellDependantCmdLine
	// contains filtered or unexported fields
}

EntrypointCommand sets the default entrypoint of the container to use the provided command.

ENTRYPOINT /usr/sbin/nginx

Entrypoint uses the default shell if not in JSON format.

func (*EntrypointCommand) Location

func (c *EntrypointCommand) Location() []parser.Range

Location of the command in source

func (*EntrypointCommand) Name

func (c *EntrypointCommand) Name() string

Name of the command

func (*EntrypointCommand) String

func (c *EntrypointCommand) String() string

type EnvCommand

type EnvCommand struct {
	Env KeyValuePairs
	// contains filtered or unexported fields
}

EnvCommand allows setting an variable in the container's environment.

ENV key1 value1 [keyN valueN...]

func (*EnvCommand) Expand

func (c *EnvCommand) Expand(expander SingleWordExpander) error

func (*EnvCommand) Location

func (c *EnvCommand) Location() []parser.Range

Location of the command in source

func (*EnvCommand) Name

func (c *EnvCommand) Name() string

Name of the command

func (*EnvCommand) String

func (c *EnvCommand) String() string

type ExposeCommand

type ExposeCommand struct {
	Ports []string
	// contains filtered or unexported fields
}

ExposeCommand marks a container port that can be exposed at runtime.

EXPOSE 6667/tcp 7000/tcp

func (*ExposeCommand) Location

func (c *ExposeCommand) Location() []parser.Range

Location of the command in source

func (*ExposeCommand) Name

func (c *ExposeCommand) Name() string

Name of the command

func (*ExposeCommand) String

func (c *ExposeCommand) String() string

type Flag

type Flag struct {
	Value        string
	StringValues []string
	// contains filtered or unexported fields
}

Flag contains all information for a flag

func (*Flag) IsTrue

func (fl *Flag) IsTrue() bool

IsTrue checks if a bool flag is true

func (*Flag) IsUsed

func (fl *Flag) IsUsed() bool

IsUsed checks if the flag is used

type FlagType

type FlagType int

FlagType is the type of the build flag

type HealthCheckCommand

type HealthCheckCommand struct {
	Health *container.HealthConfig
	// contains filtered or unexported fields
}

HealthCheckCommand sets the default healthcheck command to run in the container.

HEALTHCHECK <health-config>

func (*HealthCheckCommand) Location

func (c *HealthCheckCommand) Location() []parser.Range

Location of the command in source

func (*HealthCheckCommand) Name

func (c *HealthCheckCommand) Name() string

Name of the command

func (*HealthCheckCommand) String

func (c *HealthCheckCommand) String() string

type KeyValuePair

type KeyValuePair struct {
	Key   string
	Value string
}

KeyValuePair represents an arbitrary named value.

This is useful for commands containing key-value maps that want to preserve the order of insertion, instead of map[string]string which does not.

func (*KeyValuePair) String

func (kvp *KeyValuePair) String() string

type KeyValuePairOptional

type KeyValuePairOptional struct {
	Key     string
	Value   *string
	Comment string
}

KeyValuePairOptional is identical to KeyValuePair, but allows for optional values.

func (*KeyValuePairOptional) String

func (kvpo *KeyValuePairOptional) String() string

func (*KeyValuePairOptional) ValueString

func (kvpo *KeyValuePairOptional) ValueString() string

type KeyValuePairs

type KeyValuePairs []KeyValuePair

KeyValuePairs is a slice of KeyValuePair

type LabelCommand

type LabelCommand struct {
	Labels KeyValuePairs
	// contains filtered or unexported fields
}

LabelCommand sets an image label in the output

LABEL some json data describing the image

func NewLabelCommand

func NewLabelCommand(k string, v string, NoExp bool) *LabelCommand

NewLabelCommand creates a new 'LABEL' command

func (*LabelCommand) Expand

func (c *LabelCommand) Expand(expander SingleWordExpander) error

func (*LabelCommand) Location

func (c *LabelCommand) Location() []parser.Range

Location of the command in source

func (*LabelCommand) Name

func (c *LabelCommand) Name() string

Name of the command

func (*LabelCommand) String

func (c *LabelCommand) String() string

type MaintainerCommand

type MaintainerCommand struct {
	Maintainer string
	// contains filtered or unexported fields
}

MaintainerCommand (deprecated) allows specifying a maintainer details for the image.

MAINTAINER maintainer_name

func (*MaintainerCommand) Location

func (c *MaintainerCommand) Location() []parser.Range

Location of the command in source

func (*MaintainerCommand) Name

func (c *MaintainerCommand) Name() string

Name of the command

func (*MaintainerCommand) String

func (c *MaintainerCommand) String() string

type Mount

type Mount struct {
	Type         MountType
	From         string
	Source       string
	Target       string
	ReadOnly     bool
	SizeLimit    int64
	CacheID      string
	CacheSharing ShareMode
	Required     bool
	Mode         *uint64
	UID          *uint64
	GID          *uint64
}

func GetMounts

func GetMounts(cmd *RunCommand) []*Mount

type MountType

type MountType string
const (
	MountTypeBind   MountType = "bind"
	MountTypeCache  MountType = "cache"
	MountTypeTmpfs  MountType = "tmpfs"
	MountTypeSecret MountType = "secret"
	MountTypeSSH    MountType = "ssh"
)

type NetworkMode

type NetworkMode = string
const (
	NetworkDefault NetworkMode = "default"
	NetworkNone    NetworkMode = "none"
	NetworkHost    NetworkMode = "host"
)

func GetNetwork

func GetNetwork(cmd *RunCommand) NetworkMode

type OnbuildCommand

type OnbuildCommand struct {
	Expression string
	// contains filtered or unexported fields
}

OnbuildCommand allows specifying a command to be run on builds the use the resulting build image as a base image.

ONBUILD <some other command>

func (*OnbuildCommand) Location

func (c *OnbuildCommand) Location() []parser.Range

Location of the command in source

func (*OnbuildCommand) Name

func (c *OnbuildCommand) Name() string

Name of the command

func (*OnbuildCommand) String

func (c *OnbuildCommand) String() string

type PlatformSpecific

type PlatformSpecific interface {
	CheckPlatform(platform string) error
}

PlatformSpecific adds platform checks to a command

type RunCommand

type RunCommand struct {
	ShellDependantCmdLine
	FlagsUsed []string
	// contains filtered or unexported fields
}

RunCommand runs a command.

RUN "echo hi"       # sh -c "echo hi"

or

RUN ["echo", "hi"]  # echo hi

func (*RunCommand) Expand

func (c *RunCommand) Expand(expander SingleWordExpander) error

func (*RunCommand) Location

func (c *RunCommand) Location() []parser.Range

Location of the command in source

func (*RunCommand) Name

func (c *RunCommand) Name() string

Name of the command

func (*RunCommand) String

func (c *RunCommand) String() string

type ShareMode

type ShareMode string
const (
	MountSharingShared  ShareMode = "shared"
	MountSharingPrivate ShareMode = "private"
	MountSharingLocked  ShareMode = "locked"
)

type ShellCommand

type ShellCommand struct {
	Shell strslice.StrSlice
	// contains filtered or unexported fields
}

ShellCommand sets a custom shell to use.

SHELL bash -e -c

func (*ShellCommand) Location

func (c *ShellCommand) Location() []parser.Range

Location of the command in source

func (*ShellCommand) Name

func (c *ShellCommand) Name() string

Name of the command

func (*ShellCommand) String

func (c *ShellCommand) String() string

type ShellDependantCmdLine

type ShellDependantCmdLine struct {
	CmdLine      strslice.StrSlice
	Files        []ShellInlineFile
	PrependShell bool
}

ShellDependantCmdLine represents a cmdline optionally prepended with the shell

type ShellInlineFile

type ShellInlineFile struct {
	Name  string
	Data  string
	Chomp bool
}

ShellInlineFile represents an inline file created for a shell command

type SingleWordExpander

type SingleWordExpander func(word string) (string, error)

SingleWordExpander is a provider for variable expansion where a single word corresponds to a single output.

type SourceContent

type SourceContent struct {
	Path   string // path to the file
	Data   string // string content from the file
	Expand bool   // whether to expand file contents
}

SourceContent represents an anonymous file object

type SourcesAndDest

type SourcesAndDest struct {
	DestPath       string          // destination to write output
	SourcePaths    []string        // file path sources
	SourceContents []SourceContent // anonymous file sources
}

SourcesAndDest represent a collection of sources and a destination

func (*SourcesAndDest) Expand

func (s *SourcesAndDest) Expand(expander SingleWordExpander) error

func (*SourcesAndDest) ExpandRaw

func (s *SourcesAndDest) ExpandRaw(expander SingleWordExpander) error

type Stage

type Stage struct {
	Name     string    // name of the stage
	Commands []Command // commands contained within the stage
	BaseName string    // name of the base stage or source
	Platform string    // platform of base source to use

	Comment string // doc-comment directly above the stage

	SourceCode string         // contents of the defining FROM command
	Location   []parser.Range // location of the defining FROM command
}

Stage represents a bundled collection of commands.

Each stage begins with a FROM command (which is consumed into the Stage), indicating the source or stage to derive from, and ends either at the end-of-the file, or the start of the next stage.

Stages can be named, and can be additionally configured to use a specific platform, in the case of a multi-arch base image.

func CurrentStage

func CurrentStage(s []Stage) (*Stage, error)

CurrentStage returns the last stage from a list of stages.

func (*Stage) AddCommand

func (s *Stage) AddCommand(cmd Command)

AddCommand appends a command to the stage.

type StopSignalCommand

type StopSignalCommand struct {
	Signal string
	// contains filtered or unexported fields
}

StopSignalCommand sets the signal that will be used to kill the container.

STOPSIGNAL signal

func (*StopSignalCommand) CheckPlatform

func (c *StopSignalCommand) CheckPlatform(platform string) error

CheckPlatform checks that the command is supported in the target platform

func (*StopSignalCommand) Expand

func (c *StopSignalCommand) Expand(expander SingleWordExpander) error

func (*StopSignalCommand) Location

func (c *StopSignalCommand) Location() []parser.Range

Location of the command in source

func (*StopSignalCommand) Name

func (c *StopSignalCommand) Name() string

Name of the command

func (*StopSignalCommand) String

func (c *StopSignalCommand) String() string

type SupportsSingleWordExpansion

type SupportsSingleWordExpansion interface {
	Expand(expander SingleWordExpander) error
}

SupportsSingleWordExpansion interface allows a command to support variable.

type SupportsSingleWordExpansionRaw

type SupportsSingleWordExpansionRaw interface {
	ExpandRaw(expander SingleWordExpander) error
}

SupportsSingleWordExpansionRaw interface allows a command to support variable expansion, while ensuring that minimal transformations are applied during expansion, so that quotes and other special characters are preserved.

type UnknownInstructionError

type UnknownInstructionError struct {
	Line        int
	Instruction string
}

UnknownInstructionError represents an error occurring when a command is unresolvable

func (*UnknownInstructionError) Error

func (e *UnknownInstructionError) Error() string

type UserCommand

type UserCommand struct {
	User string
	// contains filtered or unexported fields
}

UserCommand sets the user for the rest of the stage, and when starting the container at run-time.

USER user

func (*UserCommand) Expand

func (c *UserCommand) Expand(expander SingleWordExpander) error

func (*UserCommand) Location

func (c *UserCommand) Location() []parser.Range

Location of the command in source

func (*UserCommand) Name

func (c *UserCommand) Name() string

Name of the command

func (*UserCommand) String

func (c *UserCommand) String() string

type VolumeCommand

type VolumeCommand struct {
	Volumes []string
	// contains filtered or unexported fields
}

VolumeCommand exposes the specified volume for use in the build environment.

VOLUME /foo

func (*VolumeCommand) Expand

func (c *VolumeCommand) Expand(expander SingleWordExpander) error

func (*VolumeCommand) Location

func (c *VolumeCommand) Location() []parser.Range

Location of the command in source

func (*VolumeCommand) Name

func (c *VolumeCommand) Name() string

Name of the command

func (*VolumeCommand) String

func (c *VolumeCommand) String() string

type WorkdirCommand

type WorkdirCommand struct {
	Path string
	// contains filtered or unexported fields
}

WorkdirCommand sets the current working directory for all future commands in the stage

WORKDIR /tmp

func (*WorkdirCommand) Expand

func (c *WorkdirCommand) Expand(expander SingleWordExpander) error

func (*WorkdirCommand) Location

func (c *WorkdirCommand) Location() []parser.Range

Location of the command in source

func (*WorkdirCommand) Name

func (c *WorkdirCommand) Name() string

Name of the command

func (*WorkdirCommand) String

func (c *WorkdirCommand) String() string

Jump to

Keyboard shortcuts

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