containers

package
v0.0.0-...-5b8b77a Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2021 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ContainerStopTimeout is the amount of time the container is given to stop gracefully.
	ContainerStopTimeout = time.Duration(time.Second * 30)
	// ImageBaseOSExportCommand is the command to execute when starting the base OS file system export container.
	ImageBaseOSExportCommand = []string{"/bin/sh"}
	// ImageBaseOSExportExecShell is the shell used to execute the docker exec commands.
	ImageBaseOSExportExecShell = []string{"/bin/sh", "-c"}
	// ImageBaseOSExportFsCopyExecTimeout is the amount of time the exec command has to work on the base operating system file system copy.
	ImageBaseOSExportFsCopyExecTimeout = time.Duration(time.Second * 15)
	// ImageBaseOSExportMountTarget is the path under which the volume where the file system is exported to will be mounted in the container.
	ImageBaseOSExportMountTarget = "/export-rootfs"
	// ImageBaseOSExportNoCopyDirs is a list of base operating system exported file system directories
	// for which no contents must be copied, the directory must only be created.
	// These are used in the following way:
	// - for every directory in base OS file system root (`find / -maxdepth 1 -type d`)
	//   - if directory exists in the list, just create the directory
	//   - if directory does not exist in the list and is not /, copy complete by preserving inode attributes
	ImageBaseOSExportNoCopyDirs = []string{"/boot", "/opt", "/proc", "/run", "/srv", "/sys", "/tmp"}
)

Functions

func FindImageIDByTag

func FindImageIDByTag(ctx context.Context, client *docker.Client, requiredTag string) (string, error)

FindImageIDByTag looks up the Docker image ID given a tag name.

func GetDefaultClient

func GetDefaultClient() (*docker.Client, error)

GetDefaultClient returns a default instance of the Docker client.

func HistoryToDockerfile

func HistoryToDockerfile(history []*DockerImageHistoryEntry, base string) []string

HistoryToDockerfile reconstructs the Dockerfile from the image history.

func ImageBaseOSExport

func ImageBaseOSExport(ctx context.Context, client *docker.Client, logger hclog.Logger, path, tagName string,
	tracer opentracing.Tracer, spanContext opentracing.SpanContext) error

ImageBaseOSExport exports the base operating system file system. It does so by starting the container with a bind volume pointing to the host directory defined by `path`. The `path` should point at a mounted ext4 file system such that, when the file system is copied, the ext4 file contains the contents of the base OS Docker image. The contents are copied via docker exec commands. Once the file system is exported, the function stops the container and removes it.

func ImageBuild

func ImageBuild(ctx context.Context, client *docker.Client, logger hclog.Logger, source, dockerfilePath, tagName string) error

ImageBuild builds a Docker image in the context os source directory, using Dockerfile from dockerfilePath and tags the image as tag.

func ImageExportResources

func ImageExportResources(ctx context.Context, client *docker.Client, opLogger hclog.Logger,
	exportsRoot string, opCopies []*ImageResourceExportCommand, tagName string) ([]resources.ResolvedResource, error)

ImageExportResources exports selected resources from a Docker image.

func ImageExportStageDependentResources

func ImageExportStageDependentResources(ctx context.Context, client *docker.Client, logger hclog.Logger,
	stage stage.Stage,
	exportsRoot string, externalCopies []commands.Copy, tagName string) ([]resources.ResolvedResource, error)

ImageExportStageDependentResources exports resources from a given Docker image indicated by tag. The resources are exported only when there is a command.Copy with the `--from` flag poiting at this container. This function opens the Docker image tar file system and reads every layer individually in search of a resource. If the resource is founnd in a layer, it is added to the list of returned resolved resources. If the resource points at a directory, the function lists the contents of the directory and returns an item for every resource, the function does not return resolved resources pointing at directories.

func ImagePull

func ImagePull(ctx context.Context, client *docker.Client, logger hclog.Logger, refStr string) error

ImagePull pulls a Docker image.

func ImageRemove

func ImageRemove(ctx context.Context, client *docker.Client, logger hclog.Logger, tagName string) error

ImageRemove removes the Docker image using the tag name.

Types

type DockerImageConfig

type DockerImageConfig struct {
	Architecture    string                     `json:"architecture" mapstructure:"architecture"`
	Config          *DockerImageConfigConfig   `json:"config" mapstructure:"config"`
	Container       string                     `json:"container" mapstructure:"container"`
	ContainerConfig *DockerImageConfigConfig   `json:"container_config" mapstructure:"container_config"`
	Created         string                     `json:"created" mapstructure:"created"`
	DockerVersion   string                     `json:"docker_version" mapstructure:"docker_version"`
	History         []*DockerImageHistoryEntry `json:"history" mapstructure:"history"`
	Os              string                     `json:"os" mapstructure:"os"`
	Rootfs          interface{}                `json:"rootfs" mapstructure:"rootfs"`
}

DockerImageConfig is the Docker image config.

type DockerImageConfigConfig

type DockerImageConfigConfig struct {
	AttachStderr bool                   `json:"AttachStderr" mapstructure:"AttachStderr"`
	AttachStdin  bool                   `json:"AttachStdin" mapstructure:"AttachStdin"`
	AttachStdout bool                   `json:"AttachStdout" mapstructure:"AttachStdout"`
	Cmd          []string               `json:"Cmd" mapstructure:"Cmd"`
	Domainname   string                 `json:"Domainname" mapstructure:"Domainname"`
	Entrypoint   []string               `json:"Entrypoint" mapstructure:"Entrypoint"`
	Env          []string               `json:"Env" mapstructure:"Env"`
	ExposedPorts map[string]interface{} `json:"ExposedPorts" mapstructure:"ExposedPorts"`
	Hostname     string                 `json:"Hostname" mapstructure:"Hostname"`
	Image        string                 `json:"Image" mapstructure:"Image"`
	Labels       map[string]string      `json:"Labels" mapstructure:"Labels"`
	OnBuild      interface{}            `json:"OnBuild" mapstructure:"OnBuild"`
	OpenStdin    bool                   `json:"OpenStdin" mapstructure:"OpenStdin"`
	StdinOnce    bool                   `json:"StdinOnce" mapstructure:"StdinOnce"`
	StopSignal   string                 `json:"StopSignal" mapstructure:"StopSignal"`
	Tty          bool                   `json:"Tty" mapstructure:"Tty"`
	User         string                 `json:"User" mapstructure:"User"`
	Volumes      map[string]interface{} `json:"Volumes" mapstructure:"Volumes"`
	WorkingDir   string                 `json:"WorkingDir" mapstructure:"WorkingDir"`
}

DockerImageConfigConfig is the Docker image config Config and ContainerConfig configuration.

type DockerImageHistoryEntry

type DockerImageHistoryEntry struct {
	Created    string `json:"created" mapstructure:"created"`
	CreatedBy  string `json:"created_by" mapstructure:"created_by"`
	EmptyLayer bool   `json:"empty_layer" mapstructure:"empty_layer"`
}

DockerImageHistoryEntry is the Docker image history entry.

type DockerImageManifest

type DockerImageManifest struct {
	Config   string   `json:"Config" mapstructure:"Config"`
	Layers   []string `json:"Layers" mapstructure:"Layers"`
	RepoTags []string `json:"RepoTags" mapstructure:"RepoTags"`
}

DockerImageManifest is the Docker image manifest.

type DockerImageMetadata

type DockerImageMetadata struct {
	Manifest *DockerImageManifest
	Config   *DockerImageConfig
}

DockerImageMetadata contains the Docker image manifest and config.

func ReadImageConfig

func ReadImageConfig(ctx context.Context, client *docker.Client, opLogger hclog.Logger, tagName string) (*DockerImageMetadata, error)

ReadImageConfig extracts the manifest and the image config from a Docker image.

type ImageResourceExportCommand

type ImageResourceExportCommand struct {
	Source             string
	Target             string
	User               commands.User
	UserFromLocalChown *commands.User
	Workdir            commands.Workdir
}

ImageResourceExportCommand is an internal resource export command.

func ImageResourceExportFromCommand

func ImageResourceExportFromCommand(input interface{}) (*ImageResourceExportCommand, error)

ImageResourceExportFromCommand converts an ADD and COPY command to a resource export command.

Jump to

Keyboard shortcuts

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