dockerengine

package
v1.33.3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package dockerengine provides functionality to interact with the Docker server.

Package dockerengine is a generated GoMock package.

Index

Constants

View Source
const (
	OSLinux   = "linux"
	OSWindows = "windows"

	ArchAMD64 = "amd64"
	ArchX86   = "x86_64"
	ArchARM   = "arm"
	ArchARM64 = "arm64"
)

Operating systems and architectures supported by docker.

Variables

View Source
var ErrDockerCommandNotFound = errors.New("docker: command not found")

ErrDockerCommandNotFound means the docker command is not found.

Functions

func PlatformString added in v1.12.0

func PlatformString(os, arch string) string

PlatformString returns a specified of the format <os>/<arch>.

Types

type BuildArguments

type BuildArguments struct {
	URI               string            // Required. Location of ECR Repo. Used to generate image name in conjunction with tag.
	Tags              []string          // Required. List of tags to apply to the image.
	Dockerfile        string            // Optional. One of Dockerfile or DockerfileContent is required. Dockerfile to pass to `docker build` via --file flag.
	DockerfileContent string            // Optional. One of Dockerfile or DockerfileContent is required. Dockerfile content to pass to `docker build` via stdin.
	Context           string            // Optional. Build context directory to pass to `docker build`.
	Target            string            // Optional. The target build stage to pass to `docker build`.
	CacheFrom         []string          // Optional. Images to consider as cache sources to pass to `docker build`
	Platform          string            // Optional. OS/Arch to pass to `docker build`.
	Args              map[string]string // Optional. Build args to pass via `--build-arg` flags. Equivalent to ARG directives in dockerfile.
	Labels            map[string]string // Required. Set metadata for an image.
}

BuildArguments holds the arguments that can be passed while building a container.

func (*BuildArguments) GenerateDockerBuildArgs added in v1.28.0

func (in *BuildArguments) GenerateDockerBuildArgs(c DockerCmdClient) ([]string, error)

GenerateDockerBuildArgs returns command line arguments to be passed to the Docker build command based on the provided BuildArguments. Returns an error if no tags are provided for building an image.

type Cmd

type Cmd interface {
	Run(name string, args []string, options ...exec.CmdOption) error
	RunWithContext(ctx context.Context, name string, args []string, opts ...exec.CmdOption) error
}

Cmd is the interface implemented by external commands.

type ContainerState added in v1.32.1

type ContainerState struct {
	Status   string `json:"Status"`
	ExitCode int    `json:"ExitCode"`
	Health   *struct {
		Status string `json:"Status"`
	}
}

ContainerState holds the status, exit code, and health information of a Docker container.

type DockerCmdClient added in v1.28.0

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

DockerCmdClient represents the docker client to interact with the server via external commands.

func New

func New(cmd Cmd) DockerCmdClient

New returns CmdClient to make requests against the Docker daemon via external commands.

func (DockerCmdClient) Build added in v1.28.0

Build will run a `docker build` command for the given ecr repo URI and build arguments.

func (DockerCmdClient) CheckDockerEngineRunning added in v1.28.0

func (c DockerCmdClient) CheckDockerEngineRunning() error

CheckDockerEngineRunning will run `docker info` command to check if the docker engine is running.

func (DockerCmdClient) ContainerExitCode added in v1.33.0

func (c DockerCmdClient) ContainerExitCode(ctx context.Context, name string) (int, error)

ContainerExitCode returns the exit code of a container.

func (DockerCmdClient) Exec added in v1.32.0

func (c DockerCmdClient) Exec(ctx context.Context, container string, out io.Writer, cmd string, args ...string) error

Exec runs cmd in container with args and writes stderr/stdout to out.

func (DockerCmdClient) GetPlatform added in v1.28.0

func (c DockerCmdClient) GetPlatform() (os, arch string, err error)

GetPlatform will run the `docker version` command to get the OS/Arch.

func (DockerCmdClient) IsContainerHealthy added in v1.32.1

func (c DockerCmdClient) IsContainerHealthy(ctx context.Context, containerName string) (bool, error)

IsContainerHealthy returns true if a container health state is healthy.

func (DockerCmdClient) IsContainerRunning added in v1.30.0

func (c DockerCmdClient) IsContainerRunning(ctx context.Context, name string) (bool, error)

IsContainerRunning checks if a specific Docker container is running.

func (DockerCmdClient) IsEcrCredentialHelperEnabled added in v1.28.0

func (c DockerCmdClient) IsEcrCredentialHelperEnabled(uri string) bool

IsEcrCredentialHelperEnabled return true if ecr-login is enabled either globally or registry level

func (DockerCmdClient) Login added in v1.28.0

func (c DockerCmdClient) Login(uri, username, password string) error

Login will run a `docker login` command against the Service repository URI with the input uri and auth data.

func (DockerCmdClient) Push added in v1.28.0

func (c DockerCmdClient) Push(ctx context.Context, uri string, w io.Writer, tags ...string) (digest string, err error)

Push pushes the images with the specified tags and ecr repository URI, and returns the image digest on success.

func (DockerCmdClient) Rm added in v1.30.0

func (c DockerCmdClient) Rm(ctx context.Context, containerID string) error

Rm calls `docker rm` to remove a stopped container.

func (DockerCmdClient) Run added in v1.30.0

func (c DockerCmdClient) Run(ctx context.Context, options *RunOptions) error

Run runs a Docker container with the sepcified options.

func (DockerCmdClient) Stop added in v1.30.0

func (c DockerCmdClient) Stop(ctx context.Context, containerID string) error

Stop calls `docker stop` to stop a running container.

type ErrContainerExited added in v1.32.1

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

ErrContainerExited represents an error when a Docker container has exited. It includes the container name and exit code in the error message.

func (*ErrContainerExited) Error added in v1.32.1

func (e *ErrContainerExited) Error() string

ErrContainerExited represents docker container exited with an exitcode.

func (*ErrContainerExited) ExitCode added in v1.33.0

func (e *ErrContainerExited) ExitCode() int

ExitCode returns the OS exit code configured for this error.

type ErrContainerNotExited added in v1.33.0

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

ErrContainerNotExited represents an error when a Docker container has not exited.

func (*ErrContainerNotExited) Error added in v1.33.0

func (e *ErrContainerNotExited) Error() string

Error returns the error message.

type ErrDockerDaemonNotResponsive

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

ErrDockerDaemonNotResponsive means the docker daemon is not responsive.

func (ErrDockerDaemonNotResponsive) Error

type MockCmd

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

MockCmd is a mock of Cmd interface.

func NewMockCmd

func NewMockCmd(ctrl *gomock.Controller) *MockCmd

NewMockCmd creates a new mock instance.

func (*MockCmd) EXPECT

func (m *MockCmd) EXPECT() *MockCmdMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockCmd) Run

func (m *MockCmd) Run(name string, args []string, options ...exec.CmdOption) error

Run mocks base method.

func (*MockCmd) RunWithContext added in v1.28.0

func (m *MockCmd) RunWithContext(ctx context.Context, name string, args []string, opts ...exec.CmdOption) error

RunWithContext mocks base method.

type MockCmdMockRecorder

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

MockCmdMockRecorder is the mock recorder for MockCmd.

func (*MockCmdMockRecorder) Run

func (mr *MockCmdMockRecorder) Run(name, args interface{}, options ...interface{}) *gomock.Call

Run indicates an expected call of Run.

func (*MockCmdMockRecorder) RunWithContext added in v1.28.0

func (mr *MockCmdMockRecorder) RunWithContext(ctx, name, args interface{}, opts ...interface{}) *gomock.Call

RunWithContext indicates an expected call of RunWithContext.

type RunLogOptions added in v1.30.0

type RunLogOptions struct {
	Color      *color.Color
	Output     io.Writer
	LinePrefix string
}

RunLogOptions holds the logging configuration for Run().

type RunOptions added in v1.30.0

type RunOptions struct {
	ImageURI             string            // Required. The image name to run.
	Secrets              map[string]string // Optional. Secrets to pass to the container as environment variables.
	EnvVars              map[string]string // Optional. Environment variables to pass to the container.
	ContainerName        string            // Optional. The name for the container.
	ContainerPorts       map[string]string // Optional. Contains host and container ports.
	Command              []string          // Optional. The command to run in the container.
	ContainerNetwork     string            // Optional. Network mode for the container.
	LogOptions           RunLogOptions     // Optional. Configure logging for output from the container
	AddLinuxCapabilities []string          // Optional. Adds linux capabilities to the container.
	Init                 bool              // Optional. Adds an init process as an entrypoint.
}

RunOptions holds the options for running a Docker container.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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