dockerfile

package
v3.10.0-rc.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package dockerfile has utilities that complement Docker's official Dockerfile parser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Env

func Env(m []KeyValue) (string, error)

Env builds an ENV Dockerfile instruction from the mapping m. Keys and values are serialized as JSON strings to ensure compatibility with the Dockerfile parser.

func FindAll

func FindAll(node *parser.Node, cmd string) []int

FindAll returns the indices of all children of node such that node.Children[i].Value == cmd. Valid values for cmd are defined in the package github.com/docker/docker/builder/dockerfile/command.

func From

func From(image string) (string, error)

From builds a FROM Dockerfile instruction referring the base image image.

func InsertInstructions

func InsertInstructions(node *parser.Node, pos int, instructions string) error

InsertInstructions inserts instructions starting from the pos-th child of node, moving other children as necessary. The instructions should be valid Dockerfile instructions. InsertInstructions mutates node in-place, and the final state of node is equivalent to what parser.Parse would return if the original Dockerfile represented by node contained the instructions at the specified position pos. If the returned error is non-nil, node is guaranteed to be unchanged.

func Label

func Label(m []KeyValue) (string, error)

Label builds a LABEL Dockerfile instruction from the mapping m. Keys and values are serialized as JSON strings to ensure compatibility with the Dockerfile parser.

func LastBaseImage

func LastBaseImage(node *parser.Node) string

LastBaseImage takes a Dockerfile root node and returns the base image declared in the last FROM instruction.

func LastExposedPorts

func LastExposedPorts(node *parser.Node) []string

LastExposedPorts takes a Dockerfile root node and returns a list of ports exposed in the last image built by the Dockerfile, i.e., only the EXPOSE instructions after the last FROM instruction are considered.

It also evaluates the following scenarios 1) env variable - evaluate from ENV and ARG with default value 2) port range - adding the lowest port from range

Types

type KeyValue

type KeyValue struct {
	Key   string
	Value string
}

A KeyValue can be used to build ordered lists of key-value pairs.

type ShellLex

type ShellLex struct {
	// contains filtered or unexported fields
}

ShellLex performs shell word splitting and variable expansion.

ShellLex takes a string and an array of env variables and process all quotes (" and ') as well as $xxx and ${xxx} env variable tokens. Tries to mimic bash shell process. It doesn't support all flavors of ${xx:...} formats but new ones can be added by adding code to the "special ${} format processing" section

func NewShellLex

func NewShellLex(escapeToken rune) *ShellLex

NewShellLex creates a new ShellLex which uses escapeToken to escape quotes.

func (*ShellLex) ProcessWord

func (s *ShellLex) ProcessWord(word string, env []string) (string, error)

ProcessWord will use the 'env' list of environment variables, and replace any env var references in 'word'.

func (*ShellLex) ProcessWords

func (s *ShellLex) ProcessWords(word string, env []string) ([]string, error)

ProcessWords will use the 'env' list of environment variables, and replace any env var references in 'word' then it will also return a slice of strings which represents the 'word' split up based on spaces - taking into account quotes. Note that this splitting is done **after** the env var substitutions are done. Note, each one is trimmed to remove leading and trailing spaces (unless they are quoted", but ProcessWord retains spaces between words.

Jump to

Keyboard shortcuts

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