docker

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2020 License: EPL-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ErrOpContainerInspect exported for test purposes
	ErrOpContainerInspect = "CONTAINER_INSPECT_ERROR"
	// ErrOpContainerLogs exported for test purposes
	ErrOpContainerLogs = "CONTAINER_LOGS_ERROR"
	// ErrOpContainerError exported for test purposes
	ErrOpContainerError = "CONTAINER_ERROR"

	// ErrOpContainerList exported for test purposes
	ErrOpContainerList = "CONTAINER_LIST_ERROR"

	// ErrDockerVersion exported for test purposes
	ErrDockerVersion = "DOCKER_VERSION_ERROR"
)
View Source
const PerformanceContainerName = "codewind-performance"

PerformanceContainerName : name of the Codewind performance container

View Source
const PfeContainerName = "codewind-pfe"

PfeContainerName : name of the Codewind PFE container

Variables

View Source
var ErrContainerInspect = errors.New("error inspecting container")

ErrContainerInspect - exported for testing purposes

View Source
var ErrContainerList = errors.New("error listing containers")

ErrContainerList - exported for testing purposes

View Source
var ErrContainerLogs = errors.New("error getting container logs")

ErrContainerLogs - exported for testing purposes

View Source
var ErrCopyFromContainer = errors.New("error copying files from container")

ErrCopyFromContainer - exported for testing purposes

View Source
var ErrServerVersion = errors.New("error getting server version")

ErrServerVersion - exported for testing purposes

View Source
var LocalCWContainerNames = []string{
	PfeContainerName,
	PerformanceContainerName,
}

LocalCWContainerNames : array of all the container names for a locally deployed Codewind

Functions

func ClearDockerConfigSecret

func ClearDockerConfigSecret(parentPath string) error

ClearDockerConfigSecret We erase the contents rather than deleting the file as the docker-compose file expects the secret to be present.

func DetermineDebugPortForPFE

func DetermineDebugPortForPFE() (pfeDebugPort string)

DetermineDebugPortForPFE determines a debug port to use for PFE based on the external PFE port

func GetClientVersion added in v0.14.0

func GetClientVersion(dockerClient DockerClient) string

GetClientVersion : returns the docker server version string.

func GetCodewindProjectContainers added in v0.14.0

func GetCodewindProjectContainers(containerList []types.Container) []types.Container

GetCodewindProjectContainers returns a list of containers ([]types.Container) matching "/cw"

func NewDockerClient

func NewDockerClient() (DockerClient, *DockerError)

NewDockerClient creates a new client for the docker API

func UsingLocalDockerHost added in v0.14.0

func UsingLocalDockerHost(dockerClient DockerClient) bool

UsingLocalDockerHost returns true if we are using the default local docker host.

Types

type Compose

type Compose struct {
	Version  string `yaml:"version"`
	SERVICES struct {
		PFE struct {
			Image         string   `yaml:"image"`
			ContainerName string   `yaml:"container_name"`
			User          string   `yaml:"user"`
			Environment   []string `yaml:"environment"`
			DependsOn     []string `yaml:"depends_on"`
			Ports         []string `yaml:"ports"`
			Volumes       []string `yaml:"volumes"`
			Networks      []string `yaml:"networks"`
			Secrets       []string `yaml:"secrets"`
		} `yaml:"codewind-pfe"`
		PERFORMANCE struct {
			Image         string   `yaml:"image"`
			Ports         []string `yaml:"ports"`
			ContainerName string   `yaml:"container_name"`
			Volumes       []string `yaml:"volumes"`
			Networks      []string `yaml:"networks"`
		} `yaml:"codewind-performance"`
	} `yaml:"services"`
	VOLUME struct {
		CodewindWorkspace map[string]string `yaml:"cw-workspace"`
	} `yaml:"volumes"`
	NETWORKS struct {
		NETWORK struct {
			DRIVEROPTS struct {
				HostIP string `yaml:"com.docker.network.bridge.host_binding_ipv4"`
			} `yaml:"driver_opts"`
		} `yaml:"network"`
	} `yaml:"networks"`
	SECRETS struct {
		DOCKERCONFIG struct {
			File string `yaml:"file"`
		} `yaml:"dockerconfig"`
	} `yaml:"secrets"`
}

Compose struct for the docker compose yaml file

type DockerClient

type DockerClient interface {
	ImagePull(ctx context.Context, image string, imagePullOptions types.ImagePullOptions) (io.ReadCloser, error)
	ImageList(ctx context.Context, imageListOptions types.ImageListOptions) ([]types.ImageSummary, error)
	ClientVersion() string
	ContainerList(ctx context.Context, containerListOptions types.ContainerListOptions) ([]types.Container, error)
	ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)
	ContainerLogs(ctx context.Context, containerID string, options types.ContainerLogsOptions) (io.ReadCloser, error)
	ContainerStop(ctx context.Context, containerID string, timeout *time.Duration) error
	ContainerRemove(ctx context.Context, containerID string, options types.ContainerRemoveOptions) error
	DaemonHost() string
	CopyFromContainer(ctx context.Context, containerID, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
	DistributionInspect(ctx context.Context, image, encodedRegistryAuth string) (registry.DistributionInspect, error)
	ServerVersion(ctx context.Context) (types.Version, error)
}

DockerClient requires all the functions called on the docker client

type DockerConfig

type DockerConfig struct {
	Auths map[string]DockerCredential `json:"auths"`
}

DockerConfig : The docker config.json object.

type DockerCredential

type DockerCredential struct {
	Username string `json:"username"`
	Password string `json:"password"`
	Auth     string `json:"auth"`
}

DockerCredential : A single login for a docker registry.

type DockerError

type DockerError struct {
	Op   string
	Err  error
	Desc string
}

DockerError struct will format the error

func AddDockerCredential

func AddDockerCredential(connectionID string, address string, username string, password string) *DockerError

AddDockerCredential : Add (or update) a single docker login in the keychain entry.

func CheckContainerStatus

func CheckContainerStatus(dockerClient DockerClient, codewindPrefixes []string) (bool, *DockerError)

CheckContainerStatus : check that containers exist with each of the given prefixes

func CheckImageStatus

func CheckImageStatus(dockerClient DockerClient) (bool, *DockerError)

CheckImageStatus of Codewind installed/uninstalled

func DockerCompose

func DockerCompose(dockerComposeFile string, tag string, loglevel string) *DockerError

DockerCompose to set up the Codewind environment

func DockerComposeRemove

func DockerComposeRemove(dockerComposeFile, tag string) *DockerError

DockerComposeRemove to remove Codewind images

func DockerComposeStop

func DockerComposeStop(tag, dockerComposeFile string) *DockerError

DockerComposeStop to stop Codewind containers

func GetContainerList

func GetContainerList(dockerClient DockerClient) ([]types.Container, *DockerError)

GetContainerList from docker

func GetContainerListWithOptions added in v0.14.0

func GetContainerListWithOptions(dockerClient DockerClient, options types.ContainerListOptions) ([]types.Container, *DockerError)

GetContainerListWithOptions from docker

func GetContainerLogs added in v0.14.0

func GetContainerLogs(dockerClient DockerClient, containerID string) (io.ReadCloser, *DockerError)

GetContainerLogs : returns the container log for the specified container.

func GetContainerTags

func GetContainerTags(dockerClient DockerClient) ([]string, *DockerError)

GetContainerTags of the Codewind version(s) currently running

func GetFilesFromContainer added in v0.14.0

func GetFilesFromContainer(dockerClient DockerClient, containerID, path string) (io.ReadCloser, *DockerError)

GetFilesFromContainer : returns the tar file stream for the path in the specified container.

func GetImageList

func GetImageList(dockerClient DockerClient) ([]types.ImageSummary, *DockerError)

GetImageList from docker

func GetImageTags

func GetImageTags(dockerClient DockerClient) ([]string, *DockerError)

GetImageTags of Codewind images

func GetPFEHostAndPort

func GetPFEHostAndPort(dockerClient DockerClient) (string, string, *DockerError)

GetPFEHostAndPort will return the current hostname and port that PFE is running on

func GetServerVersion added in v0.14.0

func GetServerVersion(dockerClient DockerClient) (types.Version, *DockerError)

GetServerVersion : returns the docker server version string.

func InspectContainer added in v0.14.0

func InspectContainer(dockerClient DockerClient, containerID string) (types.ContainerJSON, *DockerError)

InspectContainer : returns the result of 'docker inspect' for the specified container.

func LoginToRegistry

func LoginToRegistry(address string, username string, password string) *DockerError

LoginToRegistry : Log in locally to a docker registry with the supplied credentials.

func PingHealth

func PingHealth(healthEndpoint string) (bool, *DockerError)

PingHealth - pings environment api every 15 seconds to check if containers started

func PullImage

func PullImage(dockerClient DockerClient, image string, jsonOutput bool) *DockerError

PullImage - pull pfe/performance images from dockerhub

func RemoveDockerCredential

func RemoveDockerCredential(connectionID string, address string) *DockerError

RemoveDockerCredential : Remove a single docker login in the keychain entry.

func RemoveImage

func RemoveImage(imageID string) *DockerError

RemoveImage of Codewind and project

func StopContainer

func StopContainer(dockerClient DockerClient, container types.Container) *DockerError

StopContainer will stop only codewind containers

func ValidateImageDigest

func ValidateImageDigest(dockerClient DockerClient, image string) (string, *DockerError)

ValidateImageDigest - will ensure the image digest matches that of the one in dockerhub returns imageID, docker error

func WriteToComposeFile

func WriteToComposeFile(dockerComposeFile string, debug bool) *DockerError

WriteToComposeFile the contents of the docker compose yaml

func (*DockerError) Error

func (de *DockerError) Error() string

DockerError : Error formatted in JSON containing an errorOp and a description

type MockDockerClientWithCw added in v0.14.0

type MockDockerClientWithCw struct {
}

MockDockerClientWithCw - This mock client will return container and images lists, with Codewind items included

func (*MockDockerClientWithCw) ClientVersion added in v0.14.0

func (m *MockDockerClientWithCw) ClientVersion() string

ClientVersion - returns empty string

func (*MockDockerClientWithCw) ContainerInspect added in v0.14.0

func (m *MockDockerClientWithCw) ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)

ContainerInspect - returns basic ContainerJSON

func (*MockDockerClientWithCw) ContainerList added in v0.14.0

func (m *MockDockerClientWithCw) ContainerList(ctx context.Context, containerListOptions types.ContainerListOptions) ([]types.Container, error)

ContainerList - returns some mock containers

func (*MockDockerClientWithCw) ContainerLogs added in v0.14.0

func (m *MockDockerClientWithCw) ContainerLogs(ctx context.Context, containerID string, options types.ContainerLogsOptions) (io.ReadCloser, error)

ContainerLogs - returns empty ReadCloser

func (*MockDockerClientWithCw) ContainerRemove added in v0.14.0

func (m *MockDockerClientWithCw) ContainerRemove(ctx context.Context, containerID string, options types.ContainerRemoveOptions) error

ContainerRemove - returns no errors

func (*MockDockerClientWithCw) ContainerStop added in v0.14.0

func (m *MockDockerClientWithCw) ContainerStop(ctx context.Context, containerID string, timeout *time.Duration) error

ContainerStop - returns no errors

func (*MockDockerClientWithCw) CopyFromContainer added in v0.14.0

func (m *MockDockerClientWithCw) CopyFromContainer(ctx context.Context, containerID, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)

CopyFromContainer - returns empty ReadCloser, empty ContainerPathStat

func (*MockDockerClientWithCw) DaemonHost added in v0.14.0

func (m *MockDockerClientWithCw) DaemonHost() string

DaemonHost - returns empty string

func (*MockDockerClientWithCw) DistributionInspect added in v0.14.0

func (m *MockDockerClientWithCw) DistributionInspect(ctx context.Context, image, encodedRegistryAuth string) (registry.DistributionInspect, error)

DistributionInspect - returns a basic DistributionInspect

func (*MockDockerClientWithCw) ImageList added in v0.14.0

func (m *MockDockerClientWithCw) ImageList(ctx context.Context, imageListOptions types.ImageListOptions) ([]types.ImageSummary, error)

ImageList - reutrns some mock images

func (*MockDockerClientWithCw) ImagePull added in v0.14.0

func (m *MockDockerClientWithCw) ImagePull(ctx context.Context, image string, imagePullOptions types.ImagePullOptions) (io.ReadCloser, error)

ImagePull - returns empty ReadCloser

func (*MockDockerClientWithCw) RegistryLogin added in v0.14.0

RegistryLogin - returns basic AuthenticateOKBody

func (*MockDockerClientWithCw) ServerVersion added in v0.14.0

func (m *MockDockerClientWithCw) ServerVersion(ctx context.Context) (types.Version, error)

ServerVersion - returns empty Version struct

type MockDockerErrorClient added in v0.14.0

type MockDockerErrorClient struct {
}

MockDockerErrorClient - This mock client will return errors for each call to a docker function

func (*MockDockerErrorClient) ClientVersion added in v0.14.0

func (m *MockDockerErrorClient) ClientVersion() string

ClientVersion - returns an empty string

func (*MockDockerErrorClient) ContainerInspect added in v0.14.0

func (m *MockDockerErrorClient) ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)

ContainerInspect - returns an error

func (*MockDockerErrorClient) ContainerList added in v0.14.0

func (m *MockDockerErrorClient) ContainerList(ctx context.Context, containerListOptions types.ContainerListOptions) ([]types.Container, error)

ContainerList - returns an error

func (*MockDockerErrorClient) ContainerLogs added in v0.14.0

func (m *MockDockerErrorClient) ContainerLogs(ctx context.Context, containerID string, options types.ContainerLogsOptions) (io.ReadCloser, error)

ContainerLogs - returns an error

func (*MockDockerErrorClient) ContainerRemove added in v0.14.0

func (m *MockDockerErrorClient) ContainerRemove(ctx context.Context, containerID string, options types.ContainerRemoveOptions) error

ContainerRemove - returns an error

func (*MockDockerErrorClient) ContainerStop added in v0.14.0

func (m *MockDockerErrorClient) ContainerStop(ctx context.Context, containerID string, timeout *time.Duration) error

ContainerStop - returns an error

func (*MockDockerErrorClient) CopyFromContainer added in v0.14.0

func (m *MockDockerErrorClient) CopyFromContainer(ctx context.Context, containerID, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)

CopyFromContainer - returns an error

func (*MockDockerErrorClient) DaemonHost added in v0.14.0

func (m *MockDockerErrorClient) DaemonHost() string

DaemonHost - returns an empty string

func (*MockDockerErrorClient) DistributionInspect added in v0.14.0

func (m *MockDockerErrorClient) DistributionInspect(ctx context.Context, image, encodedRegistryAuth string) (registry.DistributionInspect, error)

DistributionInspect - returns an error

func (*MockDockerErrorClient) ImageList added in v0.14.0

func (m *MockDockerErrorClient) ImageList(ctx context.Context, imageListOptions types.ImageListOptions) ([]types.ImageSummary, error)

ImageList - returns an error

func (*MockDockerErrorClient) ImagePull added in v0.14.0

func (m *MockDockerErrorClient) ImagePull(ctx context.Context, image string, imagePullOptions types.ImagePullOptions) (io.ReadCloser, error)

ImagePull - returns an error

func (*MockDockerErrorClient) RegistryLogin added in v0.14.0

RegistryLogin - returns an error

func (*MockDockerErrorClient) ServerVersion added in v0.14.0

func (m *MockDockerErrorClient) ServerVersion(ctx context.Context) (types.Version, error)

ServerVersion - returns an error

Jump to

Keyboard shortcuts

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