container

package
v0.1.0-beta.202310300232 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: AGPL-3.0 Imports: 13 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"`
	Cmd             []string          `json:"cmd"`
	Env             map[string]string `json:"env"`
	EntryPoint      []string          `json:"entrypoint"`
	RetainArtifacts bool              `json:"retain_artifacts"`

	// 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)

NewConfig creates a new Function Config with the provided options.

func (*Container) CleanupArtifacts

func (c *Container) CleanupArtifacts() error

Cleanup all docker containers for the given container.

func (*Container) GetEnv

func (c *Container) GetEnv() []string

func (*Container) Load

func (c *Container) Load() error

Load loads the function config.

func (*Container) Run

func (c *Container) Run() (string, 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.

type ContainerOption

type ContainerOption func(*Container) error

Option defines a function signature for configuring the Docker client.

func WithContext

func WithContext(ctx context.Context) ContainerOption

WithContext configures the Docker client with a specific context.

func WithDockerClient

func WithDockerClient(client *docker.DockerClient) ContainerOption

WithConfigDockerClient configures the Docker client.

func WithRunContext

func WithRunContext(ctx context.Context) ContainerOption

type ContainerRun

type ContainerRun struct {
	ContainerID string `json:"container_id"`
	Status      string `json:"status"`
	Stdout      string `json:"stdout"`
	Stderr      string `json:"stderr"`
	Combined    string `json:"combined"`
}

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 {
	Type string
	Text string
}

Jump to

Keyboard shortcuts

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