clients

package
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2020 License: MPL-2.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Red    = "\033[1;31m%s\033[0m"
	Green  = "\033[1;32m%s\033[0m"
	Yellow = "\033[1;33m%s\033[0m"
)
View Source
const ImageTypeDocker string = "Docker"

ImageTypeDocker defines a type for a Docker image

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command interface {
	Execute(string, ...string) error
}

func NewCommand

func NewCommand(maxCommandTime time.Duration, l hclog.Logger) Command

NewCommand creates a new command with the given logger and maximum command time

type CommandImpl

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

Command executes local commands

func (*CommandImpl) Execute

func (c *CommandImpl) Execute(command string, args ...string) error

Execute the given command

type ContainerTasks

type ContainerTasks interface {
	SetForcePull(bool)
	// CreateContainer creates a new container for the given configuration
	// if successful CreateContainer returns the ID of the created container and a nil error
	// if not successful CreateContainer returns a blank string for the id and an error message
	CreateContainer(*config.Container) (id string, err error)
	// RemoveContainer stops and removes a running container
	RemoveContainer(id string) error
	// CreateVolume creates a new volume with the given name.
	// If successful the id of the newly created volume is returned
	CreateVolume(name string) (id string, err error)
	// RemoveVolume removes a volume with the given name
	RemoveVolume(name string) error
	// PullImage pulls a Docker image from the registry if it is not already
	// present in the local cache.
	// If the Username and Password config options are set then PullImage will attempt to
	// authenticate with the registry before pulling the image.
	// If the force parameter is set then PullImage will pull regardless of the image already
	// being cached locally.
	PullImage(image config.Image, force bool) error
	// FindContainerIDs returns the Container IDs for the given identifier
	FindContainerIDs(name string, typeName config.ResourceType) ([]string, error)
	// ContainerLogs attaches to the container and streams the logs to the returned
	// io.ReadCloser.
	// Returns an error if the container is not running
	ContainerLogs(id string, stdOut, stdErr bool) (io.ReadCloser, error)
	// CopyFromContainer allows the copying of a file from a container
	CopyFromContainer(id, src, dst string) error
	// CopyLocaDockerImageToVolume copies the docker images to the docker volume as a
	// compressed archive.
	// the path in the docker volume where the archive is created is returned
	// along with any errors.
	CopyLocalDockerImageToVolume(images []string, volume string) ([]string, error)
	// Execute command allows the execution of commands in a running docker container
	// id is the id of the container to execute the command in
	// command is a slice of strings to execute
	// writer [optional] will be used to write any output from the command execution.
	ExecuteCommand(id string, command []string, env []string, writer io.Writer) error
	// NetworkDisconnect disconnects a container from the network
	DetachNetwork(network, containerid string) error

	// CreateShell in the running container and attach
	CreateShell(id string, command []string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) error
}

ContainerTasks is a task oriented client which abstracts the underlying container technology from the providers this allows different concrete implementations such as Docker, or ContainerD without needing to change the provider code.

The Docker SDK can also be quite terse, the API design for this client is design is centered around performing a task such as CreateContainer, this may be composed of many individual SDK calls.

type Docker

type Docker interface {
	ContainerCreate(
		ctx context.Context,
		config *container.Config,
		hostConfig *container.HostConfig,
		networkingConfig *network.NetworkingConfig,
		containerName string,
	) (container.ContainerCreateCreatedBody, error)
	ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error)
	ContainerStart(context.Context, string, types.ContainerStartOptions) error
	ContainerStop(ctx context.Context, containerID string, timeout *time.Duration) error
	ContainerRemove(ctx context.Context, containerID string, options types.ContainerRemoveOptions) error
	ContainerLogs(ctx context.Context, container string, options types.ContainerLogsOptions) (io.ReadCloser, error)
	ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error)
	ContainerExecStart(ctx context.Context, execID string, config types.ExecStartCheck) error
	ContainerExecAttach(ctx context.Context, execID string, config types.ExecStartCheck) (types.HijackedResponse, error)
	ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error)
	ContainerExecResize(ctx context.Context, execID string, config types.ResizeOptions) error

	CopyToContainer(ctx context.Context, container, path string, content io.Reader, options types.CopyToContainerOptions) error
	CopyFromContainer(ctx context.Context, containerID, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)

	NetworkList(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error)
	NetworkCreate(ctx context.Context, name string, options types.NetworkCreate) (types.NetworkCreateResponse, error)
	NetworkRemove(ctx context.Context, networkID string) error
	NetworkConnect(ctx context.Context, networkID, containerID string, config *network.EndpointSettings) error
	NetworkDisconnect(ctx context.Context, networkID, containerID string, force bool) error

	VolumeList(ctx context.Context, filter filters.Args) (volumetypes.VolumeListOKBody, error)
	VolumeCreate(ctx context.Context, options volumetypes.VolumeCreateBody) (types.Volume, error)
	VolumeRemove(ctx context.Context, volumeID string, force bool) error

	ImagePull(ctx context.Context, refStr string, options types.ImagePullOptions) (io.ReadCloser, error)
	ImageList(ctx context.Context, options types.ImageListOptions) ([]types.ImageSummary, error)
	ImageSave(ctx context.Context, imageIDs []string) (io.ReadCloser, error)
	ImageRemove(ctx context.Context, imageID string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error)
}

Docker defines an interface for a Docker client

func NewDocker

func NewDocker() (Docker, error)

NewDocker creates a new Docker client

type DockerTasks

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

DockerTasks is a concrete implementation of ContainerTasks which uses the Docker SDK

func NewDockerTasks

func NewDockerTasks(c Docker, il ImageLog, l hclog.Logger) *DockerTasks

NewDockerTasks creates a DockerTasks with the given Docker client

func (*DockerTasks) ContainerLogs

func (d *DockerTasks) ContainerLogs(id string, stdOut, stdErr bool) (io.ReadCloser, error)

ContainerLogs streams the logs for the container to the returned io.ReadCloser

func (*DockerTasks) CopyFromContainer

func (d *DockerTasks) CopyFromContainer(id, src, dst string) error

CopyFromContainer copies a file from a container

func (*DockerTasks) CopyLocalDockerImageToVolume

func (d *DockerTasks) CopyLocalDockerImageToVolume(images []string, volume string) ([]string, error)

CopyLocalDockerImageToVolume writes multiple Docker images to a Docker volume as a compressed archive returns the filename of the archive and an error if one occured

func (*DockerTasks) CreateContainer

func (d *DockerTasks) CreateContainer(c *config.Container) (string, error)

CreateContainer creates a new Docker container for the given configuation

func (*DockerTasks) CreateShell

func (d *DockerTasks) CreateShell(id string, command []string, stdin io.ReadCloser, stdout io.Writer, stderr io.Writer) error

CreateShell creates an interactive shell inside a container https://github.com/docker/cli/blob/ae1618713f83e7da07317d579d0675f578de22fa/cli/command/container/exec.go

func (*DockerTasks) CreateVolume

func (d *DockerTasks) CreateVolume(name string) (string, error)

CreateVolume creates a Docker volume for a cluster if the volume exists performs no action returns the volume name and an error if unsuccessful

func (*DockerTasks) DetachNetwork

func (d *DockerTasks) DetachNetwork(network, containerid string) error

DetachNetwork detaches a container from a network TODO: Docker returns success before removing a container tasks which depend on the network being removed may fail in the future we need to check it has been removed before returning

func (*DockerTasks) ExecuteCommand

func (d *DockerTasks) ExecuteCommand(id string, command []string, env []string, writer io.Writer) error

ExecuteCommand allows the execution of commands in a running docker container id is the id of the container to execute the command in command is a slice of strings to execute writer [optional] will be used to write any output from the command execution.

func (*DockerTasks) FindContainerIDs

func (d *DockerTasks) FindContainerIDs(containerName string, typeName config.ResourceType) ([]string, error)

FindContainerIDs returns the Container IDs for the given identifier

func (*DockerTasks) PullImage

func (d *DockerTasks) PullImage(image config.Image, force bool) error

PullImage pulls a Docker image from a remote repo

func (*DockerTasks) RemoveContainer

func (d *DockerTasks) RemoveContainer(id string) error

RemoveContainer with the given id

func (*DockerTasks) RemoveVolume

func (d *DockerTasks) RemoveVolume(name string) error

RemoveVolume deletes the Docker volume associated with a cluster

func (*DockerTasks) SetForcePull

func (d *DockerTasks) SetForcePull(force bool)

SetForcePull sets a global override for the DockerTasks, when set to true Images will always be pulled from remote registries

type Getter

type Getter interface {
	Get(uri, dst string) error
	SetForce(force bool)
}

Getter is an interface which defines interations for downloading remote folders

type GetterImpl

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

GetterImpl is a concrete implementation of the Getter interface

func NewGetter

func NewGetter(force bool) *GetterImpl

NewGetter creates a new Getter

func (*GetterImpl) Get

func (g *GetterImpl) Get(uri, dst string) error

Get attempts to retrieve a folder from a remote location and stores it at the destination.

If force was set to true when creating a Getter then the destination folder will automatically be overwritten.

Returns error on failure

func (*GetterImpl) SetForce

func (g *GetterImpl) SetForce(force bool)

SetForce sets the force flag causing all downloads to overwrite the destination

type HTTP

type HTTP interface {
	// HealthCheckHTTP makes a HTTP GET request to the given URI and
	// if a successful status 200 is returned the method returns a nil error.
	// If it is not possible to contact the URI or if any status other than 200 is returned
	// by the upstream, then the URI is retried until the timeout elapses.
	HealthCheckHTTP(uri string, timeout time.Duration) error
	// Do executes a HTTP request and returns the response
	Do(r *http.Request) (*http.Response, error)
}

HTTP defines an interface for a HTTP client

func NewHTTP

func NewHTTP(backoff time.Duration, l hclog.Logger) HTTP

type HTTPImpl

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

func (*HTTPImpl) Do

func (h *HTTPImpl) Do(r *http.Request) (*http.Response, error)

Do executes a HTTP request and returns the response

func (*HTTPImpl) HealthCheckHTTP

func (h *HTTPImpl) HealthCheckHTTP(address string, timeout time.Duration) error

type Helm

type Helm interface {
	Create(kubeConfig, name, namespace, chartPath, valuesPath string, valuesString map[string]string) error
	Destroy(kubeConfig, name, namespace string) error
}

func NewHelm

func NewHelm(l hclog.Logger) Helm

type HelmImpl

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

func (*HelmImpl) Create

func (h *HelmImpl) Create(kubeConfig, name, namespace, chartPath, valuesPath string, valuesString map[string]string) error

func (*HelmImpl) Destroy

func (h *HelmImpl) Destroy(kubeConfig, name, namespace string) error

Destroy removes an installed Helm chart from the system

type ImageFileLog added in v0.0.19

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

func NewImageFileLog added in v0.0.19

func NewImageFileLog(file string) *ImageFileLog

NewImageFileLog creates an ImageLog which uses a file as the underlying Datastore

func (*ImageFileLog) Clear added in v0.0.19

func (i *ImageFileLog) Clear() error

Clear the list of images

func (*ImageFileLog) Log added in v0.0.19

func (i *ImageFileLog) Log(name, t string) error

Log an image has been downloaded by Shypyard

func (*ImageFileLog) Read added in v0.0.19

func (i *ImageFileLog) Read(t string) ([]string, error)

Read a list of images which have been downloaded by Shipyard

type ImageLog added in v0.0.19

type ImageLog interface {
	Log(string, string) error
	Read(string) ([]string, error)
	Clear() error
}

ImageLog logs machine images to make cleanup possible

type Kubernetes

type Kubernetes interface {
	SetConfig(string) error
	GetPods(string) (*v1.PodList, error)
	HealthCheckPods(selectors []string, timeout time.Duration) error
	Apply(files []string, waitUntilReady bool) error
	Delete(files []string) error
}

Kubernetes defines an interface for a Kuberenetes client

func NewKubernetes

func NewKubernetes(t time.Duration, l hclog.Logger) Kubernetes

NewKubernetes creates a new client for interacting with Kubernetes clusters

type KubernetesImpl

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

KubernetesImpl is a concrete implementation of a Kubernetes client

func (*KubernetesImpl) Apply

func (k *KubernetesImpl) Apply(files []string, waitUntilReady bool) error

Apply Kubernetes YAML files at path if waitUntilReady is true then the client will block until all resources have been created

func (*KubernetesImpl) Delete

func (k *KubernetesImpl) Delete(files []string) error

Delete Kuberentes YAML files at path

func (*KubernetesImpl) GetPods

func (k *KubernetesImpl) GetPods(selector string) (*v1.PodList, error)

GetPods returns the Kubernetes pods based on the label selector

func (*KubernetesImpl) HealthCheckPods

func (k *KubernetesImpl) HealthCheckPods(selectors []string, timeout time.Duration) error

HealthCheckPods uses the given selector to check that all pods are started and running. selectors are checked sequentially pods = ["component=server,app=consul", "component=client,app=consul"]

func (*KubernetesImpl) SetConfig

func (k *KubernetesImpl) SetConfig(kubeconfig string) error

SetConfig for the Kubernetes cluster

type Nomad

type Nomad interface {
	// SetConfig for the client, path is a valid Nomad JSON config file
	SetConfig(string) error
	// Create jobs in the provided files
	Create(files []string) error
	// Stop jobs in the provided files
	Stop(files []string) error
	// ParseJob in the given file and return a JSON blob representing the HCL job
	ParseJob(file string) ([]byte, error)
	// JobStatus returns the status for the given job
	JobStatus(job string) (string, error)
	// HealthCheckAPI uses the Nomad API to check that all servers and nodes
	// are ready. The function will block until either all nodes are healthy or the
	// timeout period elapses.
	HealthCheckAPI(time.Duration) error
}

Nomad defines an interface for a Nomad client

func NewNomad

func NewNomad(c HTTP, backoff time.Duration, l hclog.Logger) Nomad

NewNomad creates a new Nomad client

type NomadConfig

type NomadConfig struct {
	// Location of the Nomad cluster
	Location string `json:"location"`
	// Number of nodes in the cluster
	NodeCount int `json:"node_count"`
}

NomadConfig defines a config file which is used to store Nomad cluster connection info

func (*NomadConfig) Load

func (n *NomadConfig) Load(file string) error

Load the config from a file

func (*NomadConfig) Save

func (n *NomadConfig) Save(file string) error

Save the config to a file

type NomadImpl

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

NomadImpl is an implementation of the Nomad interface

func (*NomadImpl) Create

func (n *NomadImpl) Create(files []string) error

Create jobs in the Nomad cluster for the given files and wait until all jobs are running

func (*NomadImpl) HealthCheckAPI

func (n *NomadImpl) HealthCheckAPI(timeout time.Duration) error

HealthCheckAPI executes a HTTP heathcheck for a Nomad cluster

func (*NomadImpl) JobStatus

func (n *NomadImpl) JobStatus(job string) (string, error)

JobStatus returns a string status for the given job

func (*NomadImpl) ParseJob

func (n *NomadImpl) ParseJob(file string) ([]byte, error)

ParseJob validates a HCL job file with the Nomad API and returns a slice of bytes representing the JSON payload.

func (*NomadImpl) SetConfig

func (n *NomadImpl) SetConfig(nomadconfig string) error

SetConfig loads the Nomad config from a file

func (*NomadImpl) Stop

func (n *NomadImpl) Stop(files []string) error

Stop the jobs defined in the files for the referenced Nomad cluster

type System

type System interface {
	OpenBrowser(string) error
	Preflight() (string, error)
	CheckVersion(string) (string, bool)
}

System handles interactions between Shipyard and the OS

type SystemImpl

type SystemImpl struct{}

SystemImpl is a concrete implementation of the System interface

func (*SystemImpl) CheckVersion added in v0.0.19

func (b *SystemImpl) CheckVersion(current string) (string, bool)

CheckVersion checks the current version against the latest online version if an update is required the function returns a string with the upgrade text and a boolean value set to false. If no upgrade is reuquired then the boolean will be set to true and the string will be empty.

func (*SystemImpl) OpenBrowser

func (b *SystemImpl) OpenBrowser(uri string) error

OpenBrowser opens a URI in a new browser window

func (*SystemImpl) Preflight

func (b *SystemImpl) Preflight() (string, error)

Preflight checks that the required software is installed and is working correctly

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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