Documentation ¶
Index ¶
- func FilterArchive(r io.Reader, w io.Writer, fn TransformFileFunc) error
- func NewClientFromEnv() (*docker.Client, error)
- func NewLazyArchive(fn CreateFileFunc) io.ReadCloser
- func NoAuthFn(string) ([]dockerregistrytypes.AuthConfig, bool)
- type ClientExecutor
- func (e *ClientExecutor) Archive(fromFS bool, src, dst string, allowDownload bool, excludes []string) (io.Reader, io.Closer, error)
- func (e *ClientExecutor) Build(b *imagebuilder.Builder, node *parser.Node, from string) error
- func (e *ClientExecutor) Commit(b *imagebuilder.Builder) error
- func (e *ClientExecutor) Copy(excludes []string, copies ...imagebuilder.Copy) error
- func (e *ClientExecutor) CopyContainer(container *docker.Container, excludes []string, copies ...imagebuilder.Copy) error
- func (e *ClientExecutor) CreateScratchImage() (string, error)
- func (e *ClientExecutor) DefaultExcludes() error
- func (e *ClientExecutor) EnsureContainerPath(path string) error
- func (e *ClientExecutor) EnsureContainerPathAs(path, user string, mode *os.FileMode) error
- func (e *ClientExecutor) Execute(b *imagebuilder.Builder, node *parser.Node) error
- func (e *ClientExecutor) LoadImage(from string) (*docker.Image, error)
- func (e *ClientExecutor) LoadImageWithPlatform(from string, platform string) (*docker.Image, error)
- func (e *ClientExecutor) PopulateTransientMounts(opts docker.CreateContainerOptions, transientMounts []Mount, ...) ([]string, error)
- func (e *ClientExecutor) Prepare(b *imagebuilder.Builder, node *parser.Node, from string) error
- func (e *ClientExecutor) Preserve(path string) error
- func (e *ClientExecutor) Release() []error
- func (e *ClientExecutor) Run(run imagebuilder.Run, config docker.Config) error
- func (e *ClientExecutor) Stages(b *imagebuilder.Builder, stages imagebuilder.Stages, from string) (*ClientExecutor, error)
- func (e *ClientExecutor) UnrecognizedInstruction(step *imagebuilder.Step) error
- func (e *ClientExecutor) WithName(name string, position int) *ClientExecutor
- type ContainerVolumeTracker
- func (t *ContainerVolumeTracker) Add(path string)
- func (t *ContainerVolumeTracker) Empty() bool
- func (t *ContainerVolumeTracker) Invalidate(path string)
- func (t *ContainerVolumeTracker) Release() []error
- func (t *ContainerVolumeTracker) ReleasePath(path string)
- func (t *ContainerVolumeTracker) Restore(containerID string, client *docker.Client) error
- func (t *ContainerVolumeTracker) Save(containerID, tempDir string, client *docker.Client) error
- type CopyInfo
- type CreateFileFunc
- type DirectoryCheck
- type FetchArchiveFunc
- type Mount
- type TransformFileFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FilterArchive ¶
FilterArchive transforms the provided input archive to a new archive, giving the fn a chance to transform arbitrary files.
func NewClientFromEnv ¶
NewClientFromEnv is exposed to simplify getting a client when vendoring this library.
func NewLazyArchive ¶
func NewLazyArchive(fn CreateFileFunc) io.ReadCloser
func NoAuthFn ¶
func NoAuthFn(string) ([]dockerregistrytypes.AuthConfig, bool)
NoAuthFn can be used for AuthFn when no authentication is required in Docker.
Types ¶
type ClientExecutor ¶
type ClientExecutor struct { // Name is an optional name for this executor. Name string // Named is a map of other named executors. Named map[string]*ClientExecutor // TempDir is the temporary directory to use for storing file // contents. If unset, the default temporary directory for the // system will be used. TempDir string // Client is a client to a Docker daemon. Client *docker.Client // Directory is the context directory to build from, will use // the current working directory if not set. Ignored if // ContextArchive is set. Directory string // A compressed or uncompressed tar archive that should be used // as the build context. ContextArchive string // Excludes are a list of file patterns that should be excluded // from the context. Will be set to the contents of the // .dockerignore file if nil. Excludes []string // Tag is an optional value to tag the resulting built image. Tag string // Additional tags is an optional array of other tags to apply // to the image. AdditionalTags []string // AllowPull when set will pull images that are not present on // the daemon. AllowPull bool // IgnoreUnrecognizedInstructions, if true, allows instructions // that are not yet supported to be ignored (will be printed) IgnoreUnrecognizedInstructions bool // StrictVolumeOwnership if true will fail the build if a RUN // command follows a VOLUME command, since this client cannot // guarantee that the restored contents of the VOLUME directory // will have the right permissions. StrictVolumeOwnership bool // TransientMounts are a set of mounts from outside the build // to the inside that will not be part of the final image. Any // content created inside the mount's destinationPath will be // omitted from the final image. TransientMounts []Mount // The path within the container to perform the transient mount. ContainerTransientMount string // The streams used for canonical output. Out, ErrOut io.Writer // Container is optional and can be set to a container to use as // the execution environment for a build. Container *docker.Container // Command, if set, will be used as the entrypoint for the new // container. This is ignored if Container is set. Command []string // Image is optional and may be set to control which image is used // as a base for this build. Otherwise the FROM value from the // Dockerfile is read (will be pulled if not locally present). Image *docker.Image // Committed is optional and is used to track a temporary image, if one // was created, that was based on the container as its stage ended. Committed *docker.Image // AuthFn will handle authenticating any docker pulls if Image // is set to nil. AuthFn func(name string) ([]dockerregistrytypes.AuthConfig, bool) // HostConfig is used to start the container (if necessary). HostConfig *docker.HostConfig // LogFn is an optional command to log information to the end user LogFn func(format string, args ...interface{}) // Deferred is a list of operations that must be cleaned up at // the end of execution. Use Release() to invoke all of these. Deferred []func() error // Volumes handles saving and restoring volumes after RUN // commands are executed. Volumes *ContainerVolumeTracker }
ClientExecutor can run Docker builds from a Docker client.
func NewClientExecutor ¶
func NewClientExecutor(client *docker.Client) *ClientExecutor
NewClientExecutor creates a client executor.
func (*ClientExecutor) Build ¶
func (e *ClientExecutor) Build(b *imagebuilder.Builder, node *parser.Node, from string) error
Build is a helper method to perform a Docker build against the provided Docker client. It will load the image if not specified, create a container if one does not already exist, and start a container if the Dockerfile contains RUN commands. It will cleanup any containers it creates directly, and set the e.Committed.ID field to the generated image.
func (*ClientExecutor) Commit ¶
func (e *ClientExecutor) Commit(b *imagebuilder.Builder) error
Commit saves the completed build as an image with the provided tag. It will stop the container, commit the image, and then remove the container.
func (*ClientExecutor) Copy ¶
func (e *ClientExecutor) Copy(excludes []string, copies ...imagebuilder.Copy) error
Copy implements the executor copy function.
func (*ClientExecutor) CopyContainer ¶
func (e *ClientExecutor) CopyContainer(container *docker.Container, excludes []string, copies ...imagebuilder.Copy) error
CopyContainer copies the provided content into a destination container.
func (*ClientExecutor) CreateScratchImage ¶
func (e *ClientExecutor) CreateScratchImage() (string, error)
CreateScratchImage creates a new, zero byte layer that is identical to "scratch" except that the resulting image will have two layers.
func (*ClientExecutor) DefaultExcludes ¶
func (e *ClientExecutor) DefaultExcludes() error
DefaultExcludes reads the default list of excluded file patterns from the context directory's .containerignore file if it exists, or from the context directory's .dockerignore file, if it exists.
func (*ClientExecutor) EnsureContainerPath ¶
func (e *ClientExecutor) EnsureContainerPath(path string) error
func (*ClientExecutor) EnsureContainerPathAs ¶ added in v1.2.3
func (e *ClientExecutor) EnsureContainerPathAs(path, user string, mode *os.FileMode) error
func (*ClientExecutor) Execute ¶
func (e *ClientExecutor) Execute(b *imagebuilder.Builder, node *parser.Node) error
Execute performs all of the provided steps against the initialized container. May be invoked multiple times for a given container.
func (*ClientExecutor) LoadImage ¶
func (e *ClientExecutor) LoadImage(from string) (*docker.Image, error)
LoadImage checks the client for an image matching from. If not found, attempts to pull the image and then tries to inspect again.
func (*ClientExecutor) LoadImageWithPlatform ¶ added in v1.2.2
LoadImage checks the client for an image matching from. If not found, attempts to pull the image with specified platform string.
func (*ClientExecutor) PopulateTransientMounts ¶
func (e *ClientExecutor) PopulateTransientMounts(opts docker.CreateContainerOptions, transientMounts []Mount, sharedMount string) ([]string, error)
func (*ClientExecutor) Prepare ¶
func (e *ClientExecutor) Prepare(b *imagebuilder.Builder, node *parser.Node, from string) error
func (*ClientExecutor) Preserve ¶
func (e *ClientExecutor) Preserve(path string) error
func (*ClientExecutor) Release ¶
func (e *ClientExecutor) Release() []error
Release deletes any items started by this executor.
func (*ClientExecutor) Run ¶
func (e *ClientExecutor) Run(run imagebuilder.Run, config docker.Config) error
Run executes a single Run command against the current container using exec(). Since exec does not allow ENV or WORKINGDIR to be set, we force the execution of the user command into a shell and perform those operations before. Since RUN requires /bin/sh, we can use both 'cd' and 'export'.
func (*ClientExecutor) Stages ¶
func (e *ClientExecutor) Stages(b *imagebuilder.Builder, stages imagebuilder.Stages, from string) (*ClientExecutor, error)
Stages executes all of the provided stages, starting from the base image. It returns the executor of the last stage or an error if a stage fails.
func (*ClientExecutor) UnrecognizedInstruction ¶
func (e *ClientExecutor) UnrecognizedInstruction(step *imagebuilder.Step) error
func (*ClientExecutor) WithName ¶
func (e *ClientExecutor) WithName(name string, position int) *ClientExecutor
WithName creates a new child executor that will be used whenever a COPY statement uses --from=NAME or --from=POSITION.
type ContainerVolumeTracker ¶
type ContainerVolumeTracker struct {
// contains filtered or unexported fields
}
ContainerVolumeTracker manages tracking archives of specific paths inside a container.
func NewContainerVolumeTracker ¶
func NewContainerVolumeTracker() *ContainerVolumeTracker
func (*ContainerVolumeTracker) Add ¶
func (t *ContainerVolumeTracker) Add(path string)
Add tracks path unless it already is being tracked.
func (*ContainerVolumeTracker) Empty ¶
func (t *ContainerVolumeTracker) Empty() bool
Empty returns true if the tracker is not watching any paths
func (*ContainerVolumeTracker) Invalidate ¶
func (t *ContainerVolumeTracker) Invalidate(path string)
func (*ContainerVolumeTracker) Release ¶
func (t *ContainerVolumeTracker) Release() []error
Release removes any stored snapshots
func (*ContainerVolumeTracker) ReleasePath ¶
func (t *ContainerVolumeTracker) ReleasePath(path string)
func (*ContainerVolumeTracker) Restore ¶
func (t *ContainerVolumeTracker) Restore(containerID string, client *docker.Client) error
Restore ensures the paths managed by t exactly match the container. This requires running exec as a user that can delete contents from the container. It will return an error if any client operation fails.
type CopyInfo ¶
type CopyInfo struct { os.FileInfo Path string Decompress bool // deprecated, is never set and is ignored FromDir bool }
func CalcCopyInfo ¶
CalcCopyInfo identifies the source files selected by a Dockerfile ADD or COPY instruction.
type CreateFileFunc ¶
type DirectoryCheck ¶
type FetchArchiveFunc ¶ added in v1.2.2
type FetchArchiveFunc func(pw *io.PipeWriter)
FetchArchiveFunc retrieves an entire second copy of the archive we're processing, so that we can fetch something from it that we discarded earlier. This is expensive, so it is only called when it's needed.