container

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StdoutType = "stdout"
	StderrType = "stderr"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

type Container struct {

	// Configuration
	Name   string `json:"name"`
	Image  string `json:"image"`
	Source string `json:"source"`

	// Runtime information
	CreatedAt   *time.Time               `json:"created_at,omitempty"`
	UpdatedAt   *time.Time               `json:"updated_at,omitempty"`
	ImageExists bool                     `json:"image_exists"`
	Runs        map[string]*ContainerRun `json:"runs"`
	// contains filtered or unexported fields
}

func NewContainer

func NewContainer(options ...ContainerOption) (*Container, error)

NewContainer creates a new Container with the provided ContainerOption.

func (*Container) Build added in v0.2.0

func (c *Container) Build() error

func (*Container) CleanupArtifacts

func (c *Container) CleanupArtifacts(keepLatest bool) error

CleanupArtifacts will clean up all docker artifacts for the given container

func (*Container) GetImageLatestTag added in v0.2.0

func (c *Container) GetImageLatestTag() string

GetImageLatestTag returns the docker image name with latest as tag

func (*Container) GetImageName added in v0.2.0

func (c *Container) GetImageName() string

GetImageName returns the docker image name (e.g. flowpipe/my_func) for the function.

func (*Container) GetImageTag added in v0.2.0

func (c *Container) GetImageTag() string

GetImageTag returns the docker image name and a timestamped tag

func (*Container) IsFromSource added in v0.2.0

func (c *Container) IsFromSource() bool

func (*Container) Load

func (c *Container) Load() error

Load loads the function config.

func (*Container) Run

func (c *Container) Run(cConfig ContainerRunConfig) (string, int, error)

func (*Container) SetRunStatus

func (c *Container) SetRunStatus(containerID string, newStatus string) error

func (*Container) SetUpdatedAt

func (c *Container) SetUpdatedAt()

SetUpdatedAt sets the updated at time.

func (*Container) Unload

func (c *Container) Unload() error

Unload unloads the function config.

func (*Container) Validate

func (c *Container) Validate() error

Validate validates the function config.

func (*Container) Watch added in v0.2.0

func (c *Container) Watch() error

type ContainerOption

type ContainerOption func(*Container) error

ContainerOption defines a function signature for configuring the Container.

func WithContext

func WithContext(ctx context.Context) ContainerOption

WithContext configures the Container with a specific context.

func WithDockerClient

func WithDockerClient(client *docker.DockerClient) ContainerOption

WithDockerClient configures the Docker client.

func WithName added in v0.2.0

func WithName(name string) ContainerOption

func WithRunContext

func WithRunContext(ctx context.Context) ContainerOption

WithRunContext configures the Container with a specific run context.

type ContainerRun

type ContainerRun struct {
	ContainerID string       `json:"container_id"`
	Status      string       `json:"status"`
	Stdout      string       `json:"stdout"`
	Stderr      string       `json:"stderr"`
	Lines       []OutputLine `json:"lines"`
}

type ContainerRunConfig added in v0.2.1

type ContainerRunConfig struct {
	Cmd             []string          `json:"cmd"`
	Env             map[string]string `json:"env"`
	EntryPoint      []string          `json:"entrypoint"`
	RetainArtifacts bool              `json:"retain_artifacts"`
	Timeout         *int64            `json:"timeout"`
	CpuShares       *int64            `json:"cpu_shares"`
	User            string            `json:"user"`
	Workdir         string            `json:"workdir"`

	// Host configuration
	Memory            *int64 `json:"memory"`
	MemoryReservation *int64 `json:"memory_reservation"`
	MemorySwap        *int64 `json:"memory_swap"`
	MemorySwappiness  *int64 `json:"memory_swappiness"`
	ReadOnly          *bool  `json:"read_only"`
}

func (*ContainerRunConfig) GetEnv added in v0.2.1

func (crc *ContainerRunConfig) GetEnv() []string

type Output

type Output struct {
	Lines []OutputLine
}

func NewOutput

func NewOutput() *Output

func (*Output) Combined

func (o *Output) Combined() string

Combined returns the combined stdout and stderr output as a single string.

func (*Output) FromDockerLogsReader

func (o *Output) FromDockerLogsReader(reader io.Reader) error

FromDockerLogsReader reads the output from a docker logs reader and populates the Output struct. Docker logs inject a control character at the start of each line to indicate if it's stdout or stderr.

For example, the bytes output: [1 0 0 0 0 0 0 2 123 10 1 0 0 0 0 0 0 14 32 32 32 32 34 86 112 99 115 34 58 32 91 10

which corresponds to the stdout: 1 0 0 0 0 0 0 2 { 1 0 0 0 0 0 0 14 "Vpcs": [

Specifically it has "1 0 0 0 w x y z" as the start of each line, indicating stdout (1) or stderr (2) and with the last 4 bytes being the length of the payload.

See https://github.com/moby/moby/issues/7375#issuecomment-51462963

This function will read that input into our Output struct so we can choose the format we want later.

func (*Output) Stderr

func (o *Output) Stderr() string

Stderr returns the stderr output as a single string.

func (*Output) Stdout

func (o *Output) Stdout() string

Stdout returns the stdout output as a single string.

type OutputLine

type OutputLine struct {
	Stream string `json:"stream"`
	Line   string `json:"line"`
}

type StreamLines

type StreamLines struct {
	Stream string `json:"stream"`
	Line   string `json:"line"`
}

Jump to

Keyboard shortcuts

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