build

package
v0.0.0-...-da7d6d0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2018 License: Apache-2.0 Imports: 44 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// NoBaseImageSpecifier defines the empty image name, used in the FROM instruction
	NoBaseImageSpecifier = "scratch"

	// MountVolumeImage used for MOUNT volume containers
	MountVolumeImage = "grammarly/scratch:latest"

	// RsyncImage used for EXPORT volume containers
	RsyncImage = "grammarly/rsync-static:1"

	// ExportsPath is the path within EXPORT volume containers
	ExportsPath = "/.rocker_exports"

	// DefaultPathEnv is a system PATH variable to be used in Env substitutions
	// if path is not set by ENV command
	DefaultPathEnv = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
)

Functions

func CanonicalTarNameForPath

func CanonicalTarNameForPath(p string) (string, error)

CanonicalTarNameForPath returns platform-specific filepath to canonical posix-style path for tar archival. p is relative path.

func CompareConfigs

func CompareConfigs(a, b docker.Config) bool

CompareConfigs compares two Config struct. Does not compare the "Image" nor "Hostname" fields If OpenStdin is set, then it differs

func NewColoredContainerFormatter

func NewColoredContainerFormatter() log.Formatter

NewColoredContainerFormatter Returns Formatter that makes your messages outputed without any log-related data. Also, this formatter will make all messages colored (RED for now). Usefull when you want all stderr messages from container to become more noticible

func NewMonochromeContainerFormatter

func NewMonochromeContainerFormatter() log.Formatter

NewMonochromeContainerFormatter Returns Formatter that makes your messages outputed without any log-related data.

func ReadDockerignore

func ReadDockerignore(r io.Reader) ([]string, error)

ReadDockerignore reads and parses .dockerignore file from io.Reader

func ReadDockerignoreFile

func ReadDockerignoreFile(file string) ([]string, error)

ReadDockerignoreFile reads and parses .dockerignore file

Types

type Build

type Build struct {
	ProducedSize int64
	VirtualSize  int64
	// contains filtered or unexported fields
}

Build is the main object that processes build

func New

func New(client Client, rockerfile *Rockerfile, cache Cache, cfg Config) *Build

New creates the new build object

func (*Build) GetImageID

func (b *Build) GetImageID() string

GetImageID returns last image ID produced by the build

func (*Build) GetState

func (b *Build) GetState() State

GetState returns current build state object

func (*Build) Run

func (b *Build) Run(plan Plan) (err error)

Run runs the build following the given Plan

type Cache

type Cache interface {
	Get(s State) (s2 *State, err error)
	Put(s State) error
	Del(s State) error
}

Cache interface describes a cache backend

type CacheFS

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

CacheFS implements file based cache backend

func NewCacheFS

func NewCacheFS(root string) *CacheFS

NewCacheFS creates a file based cache backend

func (*CacheFS) Del

func (c *CacheFS) Del(s State) error

Del deletes cache

func (*CacheFS) Get

func (c *CacheFS) Get(s State) (res *State, err error)

Get fetches cache

func (*CacheFS) Put

func (c *CacheFS) Put(s State) error

Put stores cache

type Client

type Client interface {
	InspectImage(name string) (*docker.Image, error)
	PullImage(name string) error
	ListImages() (images []*imagename.ImageName, err error)
	ListImageTags(name string) (images []*imagename.ImageName, err error)
	RemoveImage(imageID string) error
	TagImage(imageID, imageName string) error
	PushImage(imageName string) (digest string, err error)
	EnsureImage(imageName string) error
	CreateContainer(state State) (id string, err error)
	RunContainer(containerID string, attachStdin bool) error
	CommitContainer(state *State) (img *docker.Image, err error)
	RemoveContainer(containerID string) error
	UploadToContainer(containerID string, stream io.Reader, path string) error
	EnsureContainer(containerName string, config *docker.Config, hostConfig *docker.HostConfig, purpose string) (containerID string, err error)
	InspectContainer(containerName string) (*docker.Container, error)
	ResolveHostPath(path string) (resultPath string, err error)
}

Client interface

type Command

type Command interface {
	// Execute does the command execution and returns modified state.
	// Note that here we use State not by reference because we want
	// it to be immutable. In future, it may encoded/decoded from json
	// and passed to the external command implementations.
	Execute(b *Build) (State, error)

	// Returns true if the command should be executed
	ShouldRun(b *Build) (bool, error)

	// String returns the human readable string representation of the command
	String() string
}

Command interface describes and command that is executed by build

func NewCommand

func NewCommand(cfg ConfigCommand) (cmd Command)

NewCommand make a new command according to the configuration given

type CommandAdd

type CommandAdd struct {
	CommandBase
}

CommandAdd implements ADD For now it is an alias of COPY, but later will add urls and archives to it

func (*CommandAdd) Execute

func (c *CommandAdd) Execute(b *Build) (State, error)

Execute runs the command

func (*CommandAdd) ReplaceEnv

func (c *CommandAdd) ReplaceEnv(env []string) error

ReplaceEnv implements EnvReplacableCommand interface

type CommandArg

type CommandArg struct {
	CommandBase
}

CommandArg implements ARG

func (*CommandArg) Execute

func (c *CommandArg) Execute(b *Build) (s State, err error)

Execute runs the command

type CommandAttach

type CommandAttach struct {
	CommandBase
}

CommandAttach implements ATTACH

func (*CommandAttach) Execute

func (c *CommandAttach) Execute(b *Build) (s State, err error)

Execute runs the command

type CommandBase

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

CommandBase implements base command that includes ConfigCommand and always run without a precondition

func (*CommandBase) ShouldRun

func (c *CommandBase) ShouldRun(b *Build) (bool, error)

ShouldRun returns true if the command should be executed

func (*CommandBase) String

func (c *CommandBase) String() string

String returns the human readable string representation of the command

type CommandCleanup

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

CommandCleanup cleans the builder state before the next FROM

func (*CommandCleanup) Execute

func (c *CommandCleanup) Execute(b *Build) (State, error)

Execute runs the command

func (*CommandCleanup) ShouldRun

func (c *CommandCleanup) ShouldRun(b *Build) (bool, error)

ShouldRun returns true if the command should be executed

func (*CommandCleanup) String

func (c *CommandCleanup) String() string

String returns the human readable string representation of the command

type CommandCmd

type CommandCmd struct {
	CommandBase
}

CommandCmd implements CMD

func (*CommandCmd) Execute

func (c *CommandCmd) Execute(b *Build) (s State, err error)

Execute runs the command

type CommandCommit

type CommandCommit struct{}

CommandCommit commits collected changes

func (*CommandCommit) Execute

func (c *CommandCommit) Execute(b *Build) (s State, err error)

Execute runs the command

func (*CommandCommit) ShouldRun

func (c *CommandCommit) ShouldRun(b *Build) (bool, error)

ShouldRun returns true if the command should be executed

func (*CommandCommit) String

func (c *CommandCommit) String() string

String returns the human readable string representation of the command

type CommandCopy

type CommandCopy struct {
	CommandBase
}

CommandCopy implements COPY

func (*CommandCopy) Execute

func (c *CommandCopy) Execute(b *Build) (State, error)

Execute runs the command

func (*CommandCopy) ReplaceEnv

func (c *CommandCopy) ReplaceEnv(env []string) error

ReplaceEnv implements EnvReplacableCommand interface

type CommandEntrypoint

type CommandEntrypoint struct {
	CommandBase
}

CommandEntrypoint implements ENTRYPOINT

func (*CommandEntrypoint) Execute

func (c *CommandEntrypoint) Execute(b *Build) (s State, err error)

Execute runs the command

type CommandEnv

type CommandEnv struct {
	CommandBase
}

CommandEnv implements ENV

func (*CommandEnv) Execute

func (c *CommandEnv) Execute(b *Build) (s State, err error)

Execute runs the command

func (*CommandEnv) ReplaceEnv

func (c *CommandEnv) ReplaceEnv(env []string) error

ReplaceEnv implements EnvReplacableCommand interface

type CommandExport

type CommandExport struct {
	CommandBase
}

CommandExport implements EXPORT

func (*CommandExport) Execute

func (c *CommandExport) Execute(b *Build) (s State, err error)

Execute runs the command

type CommandExpose

type CommandExpose struct {
	CommandBase
}

CommandExpose implements EXPOSE

func (*CommandExpose) Execute

func (c *CommandExpose) Execute(b *Build) (s State, err error)

Execute runs the command

func (*CommandExpose) ReplaceEnv

func (c *CommandExpose) ReplaceEnv(env []string) error

ReplaceEnv implements EnvReplacableCommand interface

type CommandFrom

type CommandFrom struct {
	CommandBase
}

CommandFrom implements FROM

func (*CommandFrom) Execute

func (c *CommandFrom) Execute(b *Build) (s State, err error)

Execute runs the command

type CommandImport

type CommandImport struct {
	CommandBase
}

CommandImport implements IMPORT

func (*CommandImport) Execute

func (c *CommandImport) Execute(b *Build) (s State, err error)

Execute runs the command

type CommandLabel

type CommandLabel struct {
	CommandBase
}

CommandLabel implements LABEL

func (*CommandLabel) Execute

func (c *CommandLabel) Execute(b *Build) (s State, err error)

Execute runs the command

func (*CommandLabel) ReplaceEnv

func (c *CommandLabel) ReplaceEnv(env []string) error

ReplaceEnv implements EnvReplacableCommand interface

type CommandMaintainer

type CommandMaintainer struct {
	CommandBase
}

CommandMaintainer implements CMD

func (*CommandMaintainer) Execute

func (c *CommandMaintainer) Execute(b *Build) (State, error)

Execute runs the command

type CommandMount

type CommandMount struct {
	CommandBase
}

CommandMount implements MOUNT

func (*CommandMount) Execute

func (c *CommandMount) Execute(b *Build) (s State, err error)

Execute runs the command

type CommandOnbuild

type CommandOnbuild struct {
	CommandBase
}

CommandOnbuild implements ONBUILD

func (*CommandOnbuild) Execute

func (c *CommandOnbuild) Execute(b *Build) (s State, err error)

Execute runs the command

type CommandOnbuildWrap

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

CommandOnbuildWrap wraps ONBUILD command

func (*CommandOnbuildWrap) Execute

func (c *CommandOnbuildWrap) Execute(b *Build) (State, error)

Execute runs the command

func (*CommandOnbuildWrap) ReplaceEnv

func (c *CommandOnbuildWrap) ReplaceEnv(env []string) error

ReplaceEnv implements EnvReplacableCommand interface

func (*CommandOnbuildWrap) ShouldRun

func (c *CommandOnbuildWrap) ShouldRun(b *Build) (bool, error)

ShouldRun returns true if the command should be executed

func (*CommandOnbuildWrap) String

func (c *CommandOnbuildWrap) String() string

String returns the human readable string representation of the command

type CommandPush

type CommandPush struct {
	CommandBase
}

CommandPush implements PUSH

func (*CommandPush) Execute

func (c *CommandPush) Execute(b *Build) (State, error)

Execute runs the command

type CommandRun

type CommandRun struct {
	CommandBase
}

CommandRun implements RUN

func (*CommandRun) Execute

func (c *CommandRun) Execute(b *Build) (s State, err error)

Execute runs the command

type CommandTag

type CommandTag struct {
	CommandBase
}

CommandTag implements TAG

func (*CommandTag) Execute

func (c *CommandTag) Execute(b *Build) (State, error)

Execute runs the command

type CommandUser

type CommandUser struct {
	CommandBase
}

CommandUser implements USER

func (*CommandUser) Execute

func (c *CommandUser) Execute(b *Build) (s State, err error)

Execute runs the command

func (*CommandUser) ReplaceEnv

func (c *CommandUser) ReplaceEnv(env []string) error

ReplaceEnv implements EnvReplacableCommand interface

type CommandVolume

type CommandVolume struct {
	CommandBase
}

CommandVolume implements VOLUME

func (*CommandVolume) Execute

func (c *CommandVolume) Execute(b *Build) (s State, err error)

Execute runs the command

func (*CommandVolume) ReplaceEnv

func (c *CommandVolume) ReplaceEnv(env []string) error

ReplaceEnv implements EnvReplacableCommand interface

type CommandWorkdir

type CommandWorkdir struct {
	CommandBase
}

CommandWorkdir implements WORKDIR

func (*CommandWorkdir) Execute

func (c *CommandWorkdir) Execute(b *Build) (s State, err error)

Execute runs the command

func (*CommandWorkdir) ReplaceEnv

func (c *CommandWorkdir) ReplaceEnv(env []string) error

ReplaceEnv implements EnvReplacableCommand interface

type Config

type Config struct {
	OutStream     io.Writer
	InStream      io.ReadCloser
	ContextDir    string
	ID            string
	Dockerignore  []string
	ArtifactsPath string
	Pull          bool
	NoGarbage     bool
	Attach        bool
	Verbose       bool
	NoCache       bool
	ReloadCache   bool
	Push          bool
	CacheDir      string
	LogJSON       bool
	BuildArgs     map[string]string
}

Config used specify parameters for the builder in New()

type ConfigCommand

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

ConfigCommand configuration parameters for any command

type DockerClient

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

DockerClient implements the client that works with a docker socket

func NewDockerClient

func NewDockerClient(options DockerClientOptions) *DockerClient

NewDockerClient makes a new client that works with a docker socket

func (*DockerClient) CommitContainer

func (c *DockerClient) CommitContainer(s *State) (*docker.Image, error)

CommitContainer commits docker container

func (*DockerClient) CreateContainer

func (c *DockerClient) CreateContainer(s State) (string, error)

CreateContainer creates docker container

func (*DockerClient) EnsureContainer

func (c *DockerClient) EnsureContainer(containerName string, config *docker.Config, hostConfig *docker.HostConfig, purpose string) (containerID string, err error)

EnsureContainer checks if container with specified name exists and creates it otherwise

func (*DockerClient) EnsureImage

func (c *DockerClient) EnsureImage(imageName string) (err error)

EnsureImage checks if the image exists and pulls if not

func (*DockerClient) InspectContainer

func (c *DockerClient) InspectContainer(containerName string) (container *docker.Container, err error)

InspectContainer simply inspects the container by name or ID

func (*DockerClient) InspectImage

func (c *DockerClient) InspectImage(name string) (img *docker.Image, err error)

InspectImage inspects docker image it does not give an error when image not found, but returns nil instead

func (*DockerClient) ListImageTags

func (c *DockerClient) ListImageTags(name string) (images []*imagename.ImageName, err error)

ListImageTags returns the list of images instances obtained from all tags existing in the registry

func (*DockerClient) ListImages

func (c *DockerClient) ListImages() (images []*imagename.ImageName, err error)

ListImages lists all pulled images in the local docker registry

func (*DockerClient) PullImage

func (c *DockerClient) PullImage(name string) error

PullImage pulls docker image

func (*DockerClient) PushImage

func (c *DockerClient) PushImage(imageName string) (digest string, err error)

PushImage pushes the image, does retries if configured

func (*DockerClient) RemoveContainer

func (c *DockerClient) RemoveContainer(containerID string) error

RemoveContainer removes docker container

func (*DockerClient) RemoveImage

func (c *DockerClient) RemoveImage(imageID string) error

RemoveImage removes docker image

func (*DockerClient) ResolveHostPath

func (c *DockerClient) ResolveHostPath(path string) (resultPath string, err error)

ResolveHostPath proxy for the dockerclient.ResolveHostPath

func (*DockerClient) RunContainer

func (c *DockerClient) RunContainer(containerID string, attachStdin bool) error

RunContainer runs docker container and optionally attaches stdin

func (*DockerClient) TagImage

func (c *DockerClient) TagImage(imageID, imageName string) error

TagImage adds tag to the image

func (*DockerClient) UploadToContainer

func (c *DockerClient) UploadToContainer(containerID string, stream io.Reader, path string) error

UploadToContainer uploads files to a docker container

type DockerClientOptions

type DockerClientOptions struct {
	Client                   *docker.Client
	Auth                     *docker.AuthConfigurations
	Log                      *logrus.Logger
	S3storage                *s3.StorageS3
	StdoutContainerFormatter logrus.Formatter
	StderrContainerFormatter logrus.Formatter
	PushRetryCount           int
	Host                     string
	LogExactSizes            bool
}

DockerClientOptions stores options are used to create DockerClient object

type EnvReplacableCommand

type EnvReplacableCommand interface {
	ReplaceEnv(env []string) error
}

EnvReplacableCommand interface describes the command that can replace ENV variables into arguments of itself

type Plan

type Plan []Command

Plan is the list of commands to be executed sequentially by a build process

func NewPlan

func NewPlan(commands []ConfigCommand, finalCleanup bool) (plan Plan, err error)

NewPlan makes a new plan out of the list of commands from a Rockerfile

type Rockerfile

type Rockerfile struct {
	Name    string
	Source  string
	Content string
	Vars    template.Vars
	Funs    template.Funs
	// contains filtered or unexported fields
}

Rockerfile represents the data structure of a Rockerfile

func NewRockerfile

func NewRockerfile(name string, in io.Reader, vars template.Vars, funs template.Funs) (r *Rockerfile, err error)

NewRockerfile reads parses Rockerfile from an io.Reader

func NewRockerfileFromFile

func NewRockerfileFromFile(name string, vars template.Vars, funs template.Funs) (r *Rockerfile, err error)

NewRockerfileFromFile reads and parses Rockerfile from a file

func (*Rockerfile) Commands

func (r *Rockerfile) Commands() []ConfigCommand

Commands returns the list of command configurations from the Rockerfile

type State

type State struct {
	Config         docker.Config
	ImageID        string
	ParentID       string
	ExportsID      string
	NoBaseImage    bool
	ProducedImage  bool
	InjectCommands []string
	Commits        []string

	ParentSize int64
	Size       int64

	NoCache StateNoCache
}

State is the build state TODO: document

func NewState

func NewState(b *Build) State

NewState makes a fresh state

func (*State) CleanCommits

func (s *State) CleanCommits() *State

CleanCommits resets the commits struct

func (*State) Commit

func (s *State) Commit(msg string, args ...interface{}) *State

Commit adds a commit to the current state

func (State) Equals

func (s State) Equals(s2 State) bool

Equals returns true if the two states are equal NOTE: we identify unique commands by commits, so state uniqueness is simply a commit

func (State) GetCommits

func (s State) GetCommits() string

GetCommits returns merged commits string

type StateNoCache

type StateNoCache struct {
	Dockerignore []string
	CacheBusted  bool
	CmdSet       bool
	ContainerID  string
	HostConfig   docker.HostConfig
	BuildArgs    map[string]string
}

StateNoCache is a struct that cannot be overridden by a cached item

type URLFetcher

type URLFetcher interface {
	Get(url string) (*URLInfo, error)
	GetInfo(url string) (*URLInfo, error)
}

URLFetcher is an interface to fetch urls from internets

type URLFetcherFS

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

URLFetcherFS is an URLFetcher backed by FS cache

func NewURLFetcherFS

func NewURLFetcherFS(base string, noCache bool, httpClient *http.Client) (cache *URLFetcherFS)

NewURLFetcherFS returns an instance of URLFetcherFS, initialized to live in <base>/url_fetcher_cache

func (*URLFetcherFS) Get

func (uf *URLFetcherFS) Get(url0 string) (info *URLInfo, err error)

Get downloads url, stores file and metadata in cache

func (*URLFetcherFS) GetInfo

func (uf *URLFetcherFS) GetInfo(url0 string) (info *URLInfo, err error)

GetInfo retrieves stored URLInfo data

type URLInfo

type URLInfo struct {
	ID       string
	URL      string
	FileName string `json:"-"`
	BaseName string
	HasEtag  bool
	Etag     string
	Size     int64
	Fetcher  *URLFetcherFS `json:"-"`
}

URLInfo is a metadata representing stored or to-be-stored url

Jump to

Keyboard shortcuts

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