-- import "github.com/adampointer/cali"
const (
EXIT_CODE_RUNTIME_ERROR = 1
EXIT_CODE_API_ERROR = 2
)
func Cli(n string) *cli
Cli returns a brand new cli
type CreateResponse struct {
Id string `json:"id"`
Status string `json:"status"`
ProgressDetail ProgressDetail `json:"progressDetail"`
Progress string `json:"progress,omitempty"`
}
CreateResponse is the response from Docker API when pulling an image
type DockerClient struct {
Cli *client.Client
HostConf *container.HostConfig
NetConf *network.NetworkingConfig
Conf *container.Config
}
DockerClient is a slimmed down implementation of the docker cli
func NewDockerClient() *DockerClient
NewDockerClient returns a new DockerClient initialised with the API object
func (c *DockerClient) AddBind(bnd string)
AddBind adds a bind mount to the HostConfig
func (c *DockerClient) AddBinds(bnds []string)
AddBinds adds multiple bind mounts to the HostConfig
func (c *DockerClient) AddEnv(key, value string)
AddEnvs adds an environment variable to the HostConfig
func (c *DockerClient) AddEnvs(envs []string)
AddEnvs adds multiple envs to the HostConfig
func (c *DockerClient) BindFromGit(cfg *GitCheckoutConfig, noGit func() error) error
BindFromGit creates a data container with a git clone inside and mounts its volumes inside your app container If there is no valid Git repo set in config, the noGit callback function will be executed instead
func (c *DockerClient) ContainerExists(name string) bool
ContainerExists determines if the container with this name exist
func (c *DockerClient) DeleteContainer(id string) error
DeleteContainer - Delete a container
func (c *DockerClient) Git() *Git
Git returns a new instance
func (c *DockerClient) ImageExists(image string) bool
ImageExists determines if an image exist locally
func (c *DockerClient) InitDocker() error
Init initialises the client
func (c *DockerClient) Privileged(p bool)
Privileged sets whether the container should run as privileged
func (c *DockerClient) PullImage(image string) error
PullImage - Pull an image locally
func (c *DockerClient) SetBinds(bnds []string)
SetBinds sets the bind mounts in the HostConfig
func (c *DockerClient) SetCmd(cmd []string)
SetCmd sets the command to run in the container
func (c *DockerClient) SetConf(co *container.Config)
SetConf sets the container.Config struct for the new container
func (c *DockerClient) SetDefaults()
SetDefaults sets container, host and net configs to defaults. Called when instantiating a new client or can be called manually at any time to reset API configs back to empty defaults
func (c *DockerClient) SetEnvs(envs []string)
SetEnvs sets the environment variables in the Conf
func (c *DockerClient) SetHostConf(h *container.HostConfig)
SetHostConf sets the container.HostConfig struct for the new container
func (c *DockerClient) SetImage(img string)
SetImage sets the image in Conf
func (c *DockerClient) SetNetConf(n *network.NetworkingConfig)
SetNetConf sets the network.NetworkingConfig struct for the new container
func (c *DockerClient) SetWorkDir(wd string)
SetWorkDir sets the working directory of the container
func (c *DockerClient) StartContainer(rm bool, name string) (string, error)
StartContainer will create and start a container with logs and optional cleanup
type Event struct {
Id string `json:"id"`
Status string `json:"status"`
}
Event holds the json structure for Docker API events
type Git struct {
Image string
}
Git is used to interact with containerised git
func (g *Git) Checkout(cfg *GitCheckoutConfig) (string, error)
GitCheckout will create and start a container, checkout repo and leave container stopped so volume can be imported
func (g *Git) Pull(name string) (string, error)
type GitCheckoutConfig struct {
Repo, Branch, RelPath, Image string
}
GitCheckoutConfig is input for Git.Checkout
type ProgressDetail struct {
Current int `json:"current,omitempty"`
Total int `json:"total,omitempty"`
}
ProgressDetail records the progress achieved downloading an image
type Task struct {
*DockerClient
}
Task is the action performed when it's parent command is run
func (t *Task) Bind(src, dst string) (string, error)
Bind is a utility function which will return the correctly formatted string when given a source and destination directory
The ~ symbol and relative paths will be correctly expanded depending on the host OS
func (t *Task) SetDefaults(args []string) error
SetDefaults sets the default host config for a task container Mounts the PWD to /tmp/workspace Mounts your ~/.aws directory to /root - change this if your image runs as a non-root user Sets /tmp/workspace as the workdir Configures git
func (t *Task) SetFunc(f TaskFunc)
SetFunc sets the TaskFunc which is run when the parent command is run if this is left unset, the defaultTaskFunc will be executed instead
func (t *Task) SetInitFunc(f TaskFunc)
SetInitFunc sets the TaskFunc which is executed before the main TaskFunc. It's pupose is to do any setup of the DockerClient which depends on command line args for example
type TaskFunc func(t *Task, args []string)
TaskFunc is a function executed by a Task when the command the Task belongs to is run