docker

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2016 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttachAndWait

func AttachAndWait(
	dockerClient *docker.Client,
	containerID string,
	attachOpts docker.AttachToContainerOptions,
	exitCodeCh chan<- int,
	errCh chan<- error,
)

AttachAndWait attaches to and waits for the container with the given ID using the given client, according to the given options. This function should be started in a goroutine. exitCodeCh will receive if the container completed execution. errCh may receive if the attach couldn't be completed or the container didn't complete properly. if errCh receives, exitCodeCh will not receive

func AttachToContainerOpts

func AttachToContainerOpts(containerID string, stdout io.Writer, stderr io.Writer) docker.AttachToContainerOptions

AttachContainerOpts returns docker.AttachToContainerOptions with output and error streams turned on as well as logs. the returned io.Reader will output both stdout and stderr

func ClientOrDie

func ClientOrDie() *docker.Client

ClientOrDie creates a new Docker client. If one couldn't be created, logs and error and exits with status code 1

func CmdStr

CmdStr returns the 'docker run' command that you'd execute to achieve the run configuration represented by co and hc

func ContainerGopath

func ContainerGopath(gopath, packageName string) string

func CreateAndStartContainerOpts

func CreateAndStartContainerOpts(
	imageName,
	containerName string,
	cmd []string,
	env []string,
	mounts []docker.Mount,
	workDir string,
) (docker.CreateContainerOptions, docker.HostConfig)

CreateAndStartContainerOpts creates a container from imageName with the name containerName. The container will execute cmd with the given enviroment variables (env). The container will specify volumes as each 'Source' field in mounts, and bind each mount.Source to each mount.Destination. Finally, the container will set GOPATH to the given containerGoPath variable.

func EnsureImage

func EnsureImage(dockerCl *dlib.Client, image string, ifNotExists func() (io.Writer, error)) error

EnsureImage ensures that image is on the docker daemon pointed to by dockerCl. If it doesn't, then it attempts to pull the image. If the image doesn't exist, calls ifNotExists before proceeding to download the image. If ifNotExists returns an error, immediately returns that error. Otherwise, returns any error pulling the image.

func GetImages

func GetImages(dockerCl *dlib.Client, img *Image) ([]dlib.APIImages, error)

GetImages gets images matching img from dockerCl. Returns an empty slice and a non-nil error if there was an error talking to the daemon

func NewContainerName

func NewContainerName(prefix string, cwd string) string

NewContainerName returns a new, unique container name that includes prefix and cwd

func Run

func Run(
	cl *docker.Client,
	image *Image,
	taskName,
	cwd,
	containerMount,
	cmd string,
	env []string,
	rmContainerCh chan<- func(),
	stdOut chan<- Log,
	stdErr chan<- Log,
	exitCodeCh chan<- int,
	errCh chan<- error,
)

Run runs cmd in the given image using the docker client cl. It mounts cwd into containerMount in the running container and sends on the following channels:

- rmContainerCh: a function closure that the receiver should call, after they receive on errCh or exitCodeCh, to remove the container. this is commonly done with a 'defer' - stdOut: all logs from STDOUT in the container. this may never receive - stdErr: all logs from STDERR in the container. this may never receive - exitCodeCh: the exit code of the container - errCh: any error in setting up or running the container. if errCh receives, exitCodeCh may not receive

Types

type ChanWriter

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

ChanWriter returns an io.Writer that sends all of its writes as log messages to ch

func NewChanWriter

func NewChanWriter(ch chan<- Log) *ChanWriter

NewChanWriter creates a new ChanWriter ready to accept writes and forward

func (*ChanWriter) Write

func (c *ChanWriter) Write(b []byte) (int, error)

Write is the io.Writer interface implementation

type Image

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

Image represents a single image name, including all information about its registry, repository and tag

func ParseImageFromName

func ParseImageFromName(name string) (*Image, error)

ParseImageFromName parses a raw image name string into an Image

func (Image) FullWithoutTag

func (i Image) FullWithoutTag() string

FullWithoutTag returns the full image name without its tag

func (Image) String

func (i Image) String() string

String is the fmt.Stringer interface implementation. It returns the full image name and its tag

type Log

type Log struct {
	fmt.Stringer
	// contains filtered or unexported fields
}

Log represents a single line from a running docker container

func LogFromString

func LogFromString(fmtStr string, vals ...interface{}) Log

func (Log) Message

func (l Log) Message() string

func (Log) String

func (l Log) String() string

type PullImageStatus

type PullImageStatus interface {
	String() string
}

PullImageStatus represents the status of an image pull

Jump to

Keyboard shortcuts

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