container

package
v2.2.13 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: GPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrContainerNotFound is an error returned when a container is not found.
	ErrContainerNotFound = errors.New("container not found")
	// ErrContainerNotRunning is an error returned when a container is not running.
	ErrContainerNotRunning = errors.New("container is not running")
	// ErrCannotDeleteCommit is an error returned when a container commit cannot be deleted.
	ErrCannotDeleteCommit = errors.New("cannot delete commit")
	// ErrImageNotFound is an error returned when a container image is not found.
	ErrImageNotFound = errors.New("image not found")
	// ErrInvalidSlot is an error returned when an invalid slot is specified.
	ErrInvalidSlot = errors.New("invalid slot")
	// ErrCommandExited is an error returned when a container command exits with a non zero exit code.
	ErrCommandExited = errors.New("command exited with error")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	ProjectID    string
	Slot         int  // set the slot to use for mount volumes
	NoCommit     bool // when true don't use committed app image
	ObjectType   ObjectContainerType
	ObjectName   string
	Command      []string
	Images       []string
	Volumes      map[string]string
	Binds        map[string]string
	Env          map[string]string
	Ports        []string
	WorkingDir   string
	EnableOSXNFS bool
}

Config contains configuration for a Docker container.

func (Config) GetCommand

func (d Config) GetCommand() []string

GetCommand returns the container command.

func (Config) GetContainerName

func (d Config) GetContainerName() string

GetContainerName return the name of the Docker container.

func (Config) GetEnv

func (d Config) GetEnv() []string

GetEnv converts environment vars to format needed to start docker container.

func (Config) GetHumanName

func (d Config) GetHumanName() string

GetHumanName returns human readable container name.

func (Config) GetNetworkName

func (d Config) GetNetworkName() string

GetNetworkName returns the name of the Docker network.

type Docker

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

Docker defines the Docker container handler.

func NewDocker

func NewDocker() (Docker, error)

NewDocker creates a new Docker container handler.

func (Docker) AllPurge

func (d Docker) AllPurge(deleteGlobalVolumes bool) error

AllPurge deletes all Platform.CC Docker resources.

func (Docker) AllStatus

func (d Docker) AllStatus() ([]Status, error)

AllStatus returns the status of all Platform.CC Docker containers.

func (Docker) AllStop

func (d Docker) AllStop() error

AllStop stops all Platform.CC Docker containers.

func (Docker) ContainerCommand

func (d Docker) ContainerCommand(id string, user string, cmd []string, out io.Writer) (int, error)

ContainerCommand runs a command inside a Docker container.

func (Docker) ContainerCommit

func (d Docker) ContainerCommit(id string) error

ContainerCommit stores a Docker container's state as an image.

func (Docker) ContainerDeleteCommit

func (d Docker) ContainerDeleteCommit(id string) error

ContainerDeleteCommit deletes Docker image for given container.

func (Docker) ContainerDownload

func (d Docker) ContainerDownload(id string, path string, w io.Writer) error

ContainerDownload downloads one or more files from container and write to writer as tarball.

func (Docker) ContainerLog

func (d Docker) ContainerLog(id string, follow bool) (io.ReadCloser, error)

ContainerLog returns a reader containing log data for a Docker container.

func (Docker) ContainerShell

func (d Docker) ContainerShell(id string, user string, cmd []string, stdin io.Reader) (int, error)

ContainerShell creates an interactive shell in given container.

func (Docker) ContainerStart

func (d Docker) ContainerStart(c Config) error

ContainerStart starts a Docker container.

func (Docker) ContainerStatus

func (d Docker) ContainerStatus(id string) (Status, error)

ContainerStatus returns status of Docker container.

func (Docker) ContainerUpload

func (d Docker) ContainerUpload(id string, path string, r io.Reader) error

ContainerUpload uploads one or more files to a Docker container from a tarball reader.

func (Docker) ImagePull

func (d Docker) ImagePull(c []Config) error

ImagePull pulls one or more Docker images.

func (Docker) ProjectCopySlot

func (d Docker) ProjectCopySlot(pid string, sourceSlot int, destSlot int) error

ProjectCopySlot copies volumes in given slot to another slot.

func (Docker) ProjectPurge

func (d Docker) ProjectPurge(pid string) error

ProjectPurge deletes all Docker resources for given project.

func (Docker) ProjectPurgeSlot

func (d Docker) ProjectPurgeSlot(pid string, slot int) error

ProjectPurgeSlot deletes all Docker resources for given project slot.

func (Docker) ProjectStop

func (d Docker) ProjectStop(pid string) error

ProjectStop stops all running Docker containers for given project.

type Dummy

type Dummy struct {
	Tracker *DummyTracker
}

Dummy defines the dummy container handler.

func NewDummy

func NewDummy() Dummy

NewDummy creates a new dummy handler.

func (Dummy) AllPurge

func (d Dummy) AllPurge(deleteGlobalVolumes bool) error

AllPurge purges dummy resources.

func (Dummy) AllStatus

func (d Dummy) AllStatus() ([]Status, error)

AllStatus returns status of dummy containers.

func (Dummy) AllStop

func (d Dummy) AllStop() error

AllStop stops dummy containers.

func (Dummy) ContainerCommand

func (d Dummy) ContainerCommand(id string, user string, cmd []string, out io.Writer) (int, error)

ContainerCommand runs dummy command.

func (Dummy) ContainerCommit

func (d Dummy) ContainerCommit(id string) error

ContainerCommit commits dummy container.

func (Dummy) ContainerDeleteCommit

func (d Dummy) ContainerDeleteCommit(id string) error

ContainerDeleteCommit deletes dummy commit.

func (Dummy) ContainerDownload

func (d Dummy) ContainerDownload(id string, path string, w io.Writer) error

ContainerDownload uploads to dummy container.

func (Dummy) ContainerLog

func (d Dummy) ContainerLog(id string, follow bool) (io.ReadCloser, error)

ContainerLog returns dummy logs.

func (Dummy) ContainerShell

func (d Dummy) ContainerShell(id string, user string, cmd []string, stdin io.Reader) (int, error)

ContainerShell runs dummy shell.

func (Dummy) ContainerStart

func (d Dummy) ContainerStart(c Config) error

ContainerStart starts dummy container.

func (Dummy) ContainerStatus

func (d Dummy) ContainerStatus(id string) (Status, error)

ContainerStatus gets dummy status.

func (Dummy) ContainerUpload

func (d Dummy) ContainerUpload(id string, path string, r io.Reader) error

ContainerUpload uploads to dummy container.

func (Dummy) GetContainer

func (d Dummy) GetContainer(id string) *DummyContainer

GetContainer returns the dummy container for given ID.

func (Dummy) HasVolume

func (d Dummy) HasVolume(id string) bool

HasVolume returns true if given volume exists.

func (Dummy) ImagePull

func (d Dummy) ImagePull(c []Config) error

ImagePull pulls dummy images.

func (Dummy) ProjectCopySlot

func (d Dummy) ProjectCopySlot(pid string, sourceSlot int, destSlot int) error

ProjectCopySlot copy dummy slots.

func (Dummy) ProjectPurge

func (d Dummy) ProjectPurge(pid string) error

ProjectPurge purges dummy resources.

func (Dummy) ProjectPurgeSlot

func (d Dummy) ProjectPurgeSlot(pid string, slot int) error

ProjectPurgeSlot purges dummy project slot.

func (Dummy) ProjectStop

func (d Dummy) ProjectStop(pid string) error

ProjectStop stops dummy containers.

type DummyContainer

type DummyContainer struct {
	ID             string
	Config         Config
	Committed      bool
	Running        bool
	CommandHistory []string
	Uploads        []string
}

DummyContainer is a dummy container.

func (DummyContainer) CommandHistoryIndex

func (d DummyContainer) CommandHistoryIndex(v string) int

CommandHistoryIndex returns command history index of command that contains given string.

func (DummyContainer) HasUpload

func (d DummyContainer) HasUpload(path string) bool

HasUpload returns true if upload was run at given path.

type DummyTracker

type DummyTracker struct {
	Volumes    []string
	Containers []*DummyContainer
	Sync       sync.Mutex
}

DummyTracker track the status of the dummy container environment.

type Interface

type Interface interface {
	ContainerStart(c Config) error
	ContainerCommand(id string, user string, cmd []string, out io.Writer) (int, error)
	ContainerShell(id string, user string, cmd []string, stdin io.Reader) (int, error)
	ContainerStatus(id string) (Status, error)
	ContainerUpload(id string, path string, r io.Reader) error
	ContainerDownload(id string, path string, w io.Writer) error
	ContainerLog(id string, follow bool) (io.ReadCloser, error)
	ContainerCommit(id string) error
	ContainerDeleteCommit(id string) error
	ImagePull(c []Config) error
	ProjectStop(pid string) error
	ProjectPurge(pid string) error
	ProjectPurgeSlot(pid string, slot int) error
	ProjectCopySlot(pid string, sourceSlot int, destSlot int) error
	AllStop() error
	AllPurge(deleteGlobalVolumes bool) error
	AllStatus() ([]Status, error)
}

Interface defines methods used to interact with container.

type ObjectContainerType

type ObjectContainerType byte

ObjectContainerType defines the type of container.

const (
	// ObjectContainerNone is an unknown container.
	ObjectContainerNone ObjectContainerType = '-'
	// ObjectContainerApp is an application container.
	ObjectContainerApp ObjectContainerType = 'a'
	// ObjectContainerWorker is a worker container.
	ObjectContainerWorker ObjectContainerType = 'w'
	// ObjectContainerService is a service container.
	ObjectContainerService ObjectContainerType = 's'
	// ObjectContainerRouter is the router container.
	ObjectContainerRouter ObjectContainerType = 'r'
)

func (ObjectContainerType) TypeName

func (o ObjectContainerType) TypeName() string

TypeName gets the type of container as a string.

type Status

type Status struct {
	ID           string              `json:"id"`
	Name         string              `json:"name"`
	ObjectType   ObjectContainerType `json:"object_type"`
	Image        string              `json:"image"`
	Type         string              `json:"type"`
	ProjectID    string              `json:"project_id"`
	Committed    bool                `json:"committed"`
	Running      bool                `json:"running"`
	State        string              `json:"state"`
	IPAddress    string              `json:"ip_address"`
	Slot         int                 `json:"slot"`
	HasContainer bool                `json:"has_container"`
}

Status defines container status.

Jump to

Keyboard shortcuts

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