docker

package
v0.14.0-alpha2 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2018 License: GPL-3.0 Imports: 19 Imported by: 0

README

Docker

The docker package provides tasks for interacting with docker.

docker/build Task

A build task will build a docker image.

Attributes
Name Required Default Description
dockerfile Yes The dockerfile to use while building
files A list of files that should be made available for the build
labels A list of labels to set on the image being built
tag The tag to apply to the image
tags The list of tags as described above
target The name of the target to build in a multi stage dockerfile

At least one tag must be supplied by either the tag or tags attribute. If both are supplied, tag is inserted to the front of tags.

Example
build-image:
  type: docker/build
  dockerfile: Dockerfile
  tag: myimage:latest

docker/environment Task

An environment task will read a file with environment variables and make them accessible to your plans.

A file is expected to have lines of the form variable=value. Empty lines are ignored. Files are read from the workspace, so files generated by the plan do not need to be exported in order to be a target of an environment task. From the other direction, it is necessary to import files on the host if they are to be read by an environment task.

Attributes
Name Required Default Description
from-file A file that should be read.
from-files A list of files that should be read.
prefix A prefix to add to each variable read from a file

At least one file must be supplied by either the from-file or from-files attributes. If both are supplied, from-file is inserted to the front of from-files. If the files being read are a result of environment variable expansion, the order that the files are read are not guaranteed to be stable (or in the order supplied). Be cautious of this if the environment files define overlapping variables.

Example
inject-version:
  type: docker/environment
  from-file: version.txt
  prefix: "APP_"

docker/export Task

An export task copies files from the volume to the host.

Attributes
Name Required Default Description
files Yes A single filename or a list of files to copy from the workspace to the host. Files can be specified in one of two forms which can be mixed. The first is source:destination and the other is filename where filename will be used for both the host and the volume.
Examples
export:
  type: docker/export
  files: filename1

export:
  type: docker/export
  files:
    - logo.png
    - binary:binary-linux-x86_64

docker/import Task

An import task copies files from the host to the volume. It has one required attribute named sources. This is a list of files relative to the directory that convey was run from that will be copied into the volume.

Attributes
Name Required Default Description
files Yes A single filename or a list of files to copy from the host to the workspace. Files can be specified in one of two forms which can be mixed. The first is source:destination and the other is filename where filename will be used for both the host and the volume.
Examples
import:
  type: docker/import
  files: filename1

import:
  type: docker/import
  files:
    - Dockerfile
    - src:source

docker/login Task

A login task will run docker login to login to a registry.

Attributes
Name Required Default Description
username Yes The username to login with.
password Yes The password to login with.
server The server to login to. If omitted docker hub is used.
Example
registry-login:
  type: docker/login
  username: superuser1
  password: abc123

docker/logout Task

A logout task will log you out from a Docker registry.

Attributes
Name Required Default Description
server The server to logout from. If omitted docker hub is used.
Example
registry-logout:
  type: docker/logout
  server: registry.my.domain:5000

docker/pull Task

A pull task pulls an image.

Attributes
Name Required Default Description
image The name including the tag and registry of the image to pull.
images A list of images as described above.

At least one image must be supplied by either the image or images attribute. If both are supplied, image is inserted to the front of images.

Example
pull-alpine:
  type: docker/pull
  image: gliderlabs/alpine:edge

docker/push Task

A push task pushes an image.

Attributes
Name Required Default Description
image The name including the tag and registry of the image to push.
images A list of images as described above.

At least one image must be supplied by either the image or images attribute. If both are supplied, image is inserted to the front of images.

Example
push-image:
  type: docker/push
  images:
    - registry.my.domain:5000/newimage:master-latest
    - registry.my.domain:5000/newimage:master-deadbeef

docker/remove Task

A remove task removes an image.

Attributes
Name Required Default Description
image The name including the tag and registry of the image to remove.
images A list of images as described above.
quiet false True if a missing image should not count as a task failure.

At least one image must be supplied by either the image or images attribute. If both are supplied, image is inserted to the front of images.

Example
remove-image:
  type: docker/remove
  images:
    - registry.my.domain:5000/newimage:master-latest
    - registry.my.domain:5000/newimage:master-deadbeef

docker/run Task

A run task runs an image.

Attributes
Name Required Default Description
command The command to run in the container. This is only necessary if the image does not provide a command by default.
detach false Will run the container in the background allowing other tasks to run. The container will be cleaned up on exit. If the image has a HEALTHCHECK specified in the Dockerfile, convey will wait until it is healthy before proceeding.
hostname Will set the --network-alias argument in the docker run command. This is generally only useful to connect to service containers.
user The user to run as when executing the script or command inside the container.
entrypoint The entrypoint to use for the container. This is only necessary if the image does not provide one by default.
environment A list of environment variables to set. The should be specified in a NAME or NAME=VALUE format. If no value is provided, the value of the variable from the host will be provided if it is available.
healthcheck See the HealthCheck attributes below.
image Yes The image including the registry and tag to run.
labels A list of labels to set on the image being built
workdir The working directory to use in the container.
workspace /workspace The path inside the container to mount the workspace volume.
HealthCheck Attributes

All of these attributes map directory to the --health arguments to docker run.

Name Description
command The command to run as the health check.
interval The interval with which to check the health.
retries The number of attempts before giving up.
start-period How long to wait before starting to check the container's health.
timeout How long to wait for a health check to return before aborting.
Example

A basic example where the image knows everything to do.

build-golang:
  type: docker/run
  image: golang:onbuild

A basic example using a standard image to do something else

download-file:
  type: docker/run
  image: debian:jessie-slim
  script:
    - wget https://somedomain.tld/file1
    - wget https://somedomain.tld/file1.sha256
    - sha256sum -c file1.sha256

A more compilicated example waiting for a detached nginx to start

web-server:
  type: docker/run
  image: nginx:alpine
  detach: true
  command: wget http://localhost
  interval: 1s

docker/tag Task

A tag task will tag an existing image.

Attributes
Name Required Default Description
source The source image, including registry and tag, to tag.
destination The destination tag, including registry and tag, to tag.
Example
tag-development:
  type: docker/tag
  source: registry.my.domain:5000/newimage:latest
  destination: registry.my.domain:5000/newimage:development

Documentation

Overview

Package docker implements the docker task types.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Tasks is a map of all docker tasks.
	Tasks = map[string]tasks.Task{
		"build":       &Build{},
		"export":      &Export{},
		"import":      &Import{},
		"login":       &Login{},
		"logout":      &Logout{},
		"pull":        &Pull{},
		"push":        &Push{},
		"remove":      &Remove{},
		"run":         &Run{},
		"tag":         &Tag{},
		"environment": &Environment{},
	}
)

Functions

func Docker added in v0.8.0

func Docker(name string, cmdv []string, st *state.State) error

Docker runs a docker command.

func DockerOutput added in v0.8.0

func DockerOutput(name string, cmdv []string, st *state.State) (string, string, error)

DockerOutput runs a docker command but returns the output rather than outputting to the logger.

func ImageID

func ImageID(tag string, logger *gomol.LogAdapter, st *state.State) (string, error)

ImageID will return the ID of the given image if it's available locally

func ParseCommand

func ParseCommand(argv []string) (tasks.Task, error)

ParseCommand is a super stripped down kingpin parser that will parse docker command line options and return a convey task or an error

func ParseImage added in v0.8.0

func ParseImage(image string) (string, string, string)

ParseImage will convert an image like python:3 to it's registry, name, and tag

func StopContainer added in v0.9.0

func StopContainer(cid string, logger *gomol.LogAdapter, st *state.State) error

StopContainer will call 'docker stop' on the given container id

Types

type Build

type Build struct {
	Dockerfile string             `yaml:"dockerfile"`
	Files      yaml.StringOrSlice `yaml:"files"`
	Tag        string             `yaml:"tag"`
	Tags       yaml.StringOrSlice `yaml:"tags"`
	Target     string             `yaml:"target"`
	Labels     yaml.StringOrSlice `yaml:"labels"`
	Arguments  yaml.StringOrSlice `yaml:"arguments"`
}

Build defines the options for building a docker image.

func (*Build) Execute

func (b *Build) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error

Execute runs the docker build command

func (*Build) New

func (b *Build) New() tasks.Task

New creates a new docker build task.

func (*Build) Valid

func (b *Build) Valid() error

Valid checks that the build task is valid.

type Environment added in v0.11.0

type Environment struct {
	File   string             `yaml:"from-file"`
	Files  yaml.StringOrSlice `yaml:"from-files"`
	Prefix string             `yaml:"prefix"`
}

Environment contains options for loading environment variables from a file in the workspace.

func (*Environment) Execute added in v0.11.0

func (e *Environment) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error

Execute runs the environment plan.

func (*Environment) New added in v0.11.0

func (e *Environment) New() tasks.Task

New creates a new environment command.

func (*Environment) Valid added in v0.11.0

func (e *Environment) Valid() error

Valid validate the environment command.

type Export

type Export struct {
	Files yaml.StringOrSlice `yaml:"files"`
	Path  string
}

Export represents an export task which exports files from the workspace to the host.

func (*Export) Execute

func (e *Export) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error

Execute runs the export task.

func (*Export) New

func (e *Export) New() tasks.Task

New creates a new Export task.

func (*Export) Valid

func (e *Export) Valid() error

Valid validates the export task.

type HealthCheck added in v0.9.0

type HealthCheck struct {
	Command     string        `yaml:"command"`
	Interval    time.Duration `yaml:"interval"`
	Retries     int           `yaml:"retries"`
	StartPeriod time.Duration `yaml:"start-period"`
	Timeout     time.Duration `yaml:"timeout"`
}

HealthCheck represents a docker health check.

type Import

type Import struct {
	Files yaml.StringOrSlice `yaml:"files"`
}

Import represents an import task which imports files from the host to the workspace.

func (*Import) Execute

func (i *Import) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error

Execute runs the import task.

func (*Import) New

func (i *Import) New() tasks.Task

New creates a new import task.

func (*Import) Valid

func (i *Import) Valid() error

Valid validates the import task.

type Login

type Login struct {
	Username string `yaml:"username"`
	Password string `yaml:"password"`
	Server   string `yaml:"server"`
}

Login represents an login task for logging into a docker registry.

func (*Login) Execute

func (l *Login) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error

Execute runs the login task.

func (*Login) New

func (l *Login) New() tasks.Task

New creates a new login task.

func (*Login) Valid

func (l *Login) Valid() error

Valid validate the login task.

type Logout

type Logout struct {
	Server string `yaml:"server"`
}

Logout represents a logout task which logs out of a docker registry.

func (*Logout) Execute

func (l *Logout) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error

Execute runs the logout task.

func (*Logout) New

func (l *Logout) New() tasks.Task

New creates a new logout task.

func (*Logout) Valid

func (l *Logout) Valid() error

Valid validates the logout task.

type Network added in v0.9.0

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

Network represents a docker network.

func NewNetwork added in v0.9.0

func NewNetwork(st *state.State) (*Network, error)

NewNetwork creates a new docker network.

func (*Network) Destroy added in v0.9.0

func (network *Network) Destroy() error

Destroy tears down the docker network.

func (*Network) Name added in v0.9.0

func (network *Network) Name() string

Name returns the name of the network.

type Pull

type Pull struct {
	Image  string             `yaml:"image"`
	Images yaml.StringOrSlice `yaml:"images"`
}

Pull represents a docker pull task which pulls an image from a docker registry.

func (*Pull) Execute

func (p *Pull) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error

Execute runs the pull task.

func (*Pull) New

func (p *Pull) New() tasks.Task

New creates a new pull task.

func (*Pull) Valid

func (p *Pull) Valid() error

Valid validates the pull task.

type Push

type Push struct {
	Image  string             `yaml:"image"`
	Images yaml.StringOrSlice `yaml:"images"`
}

Push represents a docker push task which push an image to a docker registry.

func (*Push) Execute

func (p *Push) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error

Execute runs the push task.

func (*Push) New

func (p *Push) New() tasks.Task

New creates a new push task.

func (*Push) Valid

func (p *Push) Valid() error

Valid validates the push task.

type Remove

type Remove struct {
	Image  string             `yaml:"image"`
	Images yaml.StringOrSlice `yaml:"images"`
	Quiet  bool               `yaml:"quiet"`
}

Remove represents a docker rm task which deletes a local docker image.

func (*Remove) Execute

func (r *Remove) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error

Execute runs the remove task.

func (*Remove) New

func (r *Remove) New() tasks.Task

New creates a new remove task.

func (*Remove) Valid

func (r *Remove) Valid() error

Valid validates the remove task.

type Run

type Run struct {
	Command     string             `yaml:"command"`
	Detach      bool               `yaml:"detach"`
	Hostname    string             `yaml:"hostname"`
	EntryPoint  string             `yaml:"entrypoint"`
	Environment yaml.StringOrSlice `yaml:"environment"`
	Image       string             `yaml:"image"`
	WorkDir     string             `yaml:"workdir"`
	WorkSpace   string             `yaml:"workspace"`
	Script      yaml.StringOrSlice `yaml:"script"`
	Shell       string             `yaml:"shell"`
	Labels      yaml.StringOrSlice `yaml:"labels"`
	User        string             `yaml:"user"`
	HealthCheck HealthCheck        `yaml:"healthcheck"`
}

Run represents a docker run task which will run a container.

func (*Run) Execute

func (r *Run) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error

Execute runs the run task.

func (*Run) New

func (r *Run) New() tasks.Task

New creates a new run task.

func (*Run) UnmarshalYAML added in v0.5.0

func (r *Run) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is a custom yaml unmarshaller for run tasks.

func (*Run) Valid

func (r *Run) Valid() error

Valid validates the run task.

type Tag

type Tag struct {
	Source       string             `yaml:"source"`
	Destination  string             `yaml:"destination"`
	Destinations yaml.StringOrSlice `yaml:"destinations"`
}

Tag represents a docker tag command.

func (*Tag) Execute

func (t *Tag) Execute(name string, logger *gomol.LogAdapter, env []string, st *state.State) error

Execute runs the execute task.

func (*Tag) New

func (t *Tag) New() tasks.Task

New creates a new docker tag task.

func (*Tag) Valid

func (t *Tag) Valid() error

Valid validates the tag task.

type Workspace added in v0.9.0

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

Workspace represents a docker workspace.

func NewWorkspace added in v0.9.0

func NewWorkspace(st *state.State) (*Workspace, error)

NewWorkspace creates a new docker workspace.

func (*Workspace) Destroy added in v0.9.0

func (ws *Workspace) Destroy() error

Destroy removes the docker workspace.

func (*Workspace) Name added in v0.9.0

func (ws *Workspace) Name() string

Name returns the name of the docker workspace.

Jump to

Keyboard shortcuts

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