docker

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package docker provides a simple docker abstraction layer.

Please note that the methods are idempotent (i.e. they can be called multiple times without changing the result). This is important because it reduces the need for additional checks if the user runs a command multiple times. E.g. the code that uses this package doesn't need to check if the container already runs, ContainerRuns does that internally and just does nothing if the container is already running.

Additionally it sometimes makes error handling simpler. If an particular method failed halfway, it can just be called again without causing any issues.

The general pattern used internally in this package is:

  1. Check if the desired result (e.g. container running) already exists
  2. If yes, do nothing
  3. If no, invoke the action that produces the result (e.g. run container)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicManager

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

func InitializeClient added in v0.10.0

func InitializeClient(currentNode node.Node) (*BasicManager, error)

InitializeClient creates a BasicManager from a node.Node

func NewBasicManager

func NewBasicManager(prefix, basePath, networkID string) (*BasicManager, error)

NewBasicManager creates a BasicManager

prefix is a string that gets added to every container-, network-, volume-name, etc. started by this client basePath is a path that gets added to every relative file paths. Example with basePath = /home/user/.bpm/nodes/xyz/config: test.yml becomes /home/user/.bpm/nodes/xyz/config/test.yml

func (*BasicManager) AddBasePath added in v0.12.0

func (bm *BasicManager) AddBasePath(myPath string) string

AddBasePath adds the base path if the supplied path is relative

func (*BasicManager) ContainerAbsent

func (bm *BasicManager) ContainerAbsent(ctx context.Context, container Container) error

ContainerAbsent stops and removes a container if it is running/exists

func (*BasicManager) ContainerRuns

func (bm *BasicManager) ContainerRuns(ctx context.Context, container Container) error

ContainerRuns creates and starts a container if it doesn't exist/run yet

func (*BasicManager) ContainerStopped

func (bm *BasicManager) ContainerStopped(ctx context.Context, container Container) error

ContainerStopped stops a container if it is running

func (*BasicManager) DoesNetworkExist added in v0.11.0

func (bm *BasicManager) DoesNetworkExist(ctx context.Context, networkID string) (bool, error)

DoesNetworkExist returns true if the docker network exists

func (*BasicManager) IsContainerRunning

func (bm *BasicManager) IsContainerRunning(ctx context.Context, containerName string) (bool, error)

func (*BasicManager) ListContainerNames

func (bm *BasicManager) ListContainerNames(ctx context.Context) ([]string, error)

ListContainerNames lists all containers by name

func (*BasicManager) ListVolumeIDs

func (bm *BasicManager) ListVolumeIDs(ctx context.Context) ([]string, error)

ListVolumeIDs lists all volumes by name (which is also a unique id)

func (*BasicManager) NetworkAbsent

func (bm *BasicManager) NetworkAbsent(ctx context.Context, networkID string) error

NetworkAbsent removes a network if it exists

func (*BasicManager) NetworkExists

func (bm *BasicManager) NetworkExists(ctx context.Context, networkID string) error

NetworkExists creates a network if it doesn't exist yet

func (*BasicManager) RunTransientContainer added in v0.10.0

func (bm *BasicManager) RunTransientContainer(ctx context.Context, container Container) (string, error)

RunTransientContainer runs a container once and removes it after it is finished.

func (*BasicManager) SetBasePath added in v0.10.0

func (bm *BasicManager) SetBasePath(myPath string)

func (*BasicManager) VolumeAbsent

func (bm *BasicManager) VolumeAbsent(ctx context.Context, volumeID string) error

VolumeAbsent removes a network if it exists

type Container

type Container struct {
	Name        string
	Image       string
	EnvFilename string
	Mounts      []Mount
	Ports       []Port
	Cmd         []string
	CmdFile     string
	User        string
	CollectLogs bool
}

Container defines all parameters used to create a container

type Mount

type Mount struct {
	Type string
	From string
	To   string
}

Mount defines a docker volume mount

type Port

type Port struct {
	HostIP        string
	HostPort      string
	ContainerPort string
	Protocol      string
}

Port defines a forwarded docker port

Jump to

Keyboard shortcuts

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