docker

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const WorkspaceDir = "/workspace"

WorkspaceDir is the path of the task's mounted workspace inside a container

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option interface {
	Apply(opts *Options)
}

func Command

func Command(cmd ...string) Option

Command sets the command arguments to the container image

func Entrypoint

func Entrypoint(entryPoint string) Option

Entrypoint overrides the container image's entrypoint

func Env

func Env(key string, value string) Option

Env sets an environment variable in the container

func EnvFile

func EnvFile(envFile string) Option

EnvFile read environment variables from a file

func ForcePull

func ForcePull(forcePull bool) Option

ForcePull sets the containers force-pull option

func Label

func Label(key string, value string) Option

Label sets a container label

func RedirectStderr

func RedirectStderr(redirect bool) Option

RedirectStderr redirects stderr to stdout, combining both streams into one.

func Stderr

func Stderr(w io.Writer) Option

Stderr sets the stderr stream

func StderrCallback

func StderrCallback(fn func(line string)) Option

StderrCallback sets the function that gets called for every stderr line

func Stdout

func Stdout(w io.Writer) Option

Stdout sets the stdout stream

func StdoutCallback

func StdoutCallback(fn func(line string)) Option

StdoutCallback sets the function that gets called for every stdout line

func User

func User(user string) Option

User sets the user/uid of the container process

func WorkDir

func WorkDir(workDir string) Option

WorkDir sets the working directory of the container

type Options

type Options struct {
	// Image is the docker image reference for the container. (Required)
	Image string
	// Name sets the name of the container
	Name string
	// User sets a different user to run unside the container
	User string
	// WorkDir specifies an alternate starting directory
	WorkDir string
	// EntryPoint changes the command that is the entrypoint of the docker image
	EntryPoint string
	// Command is the list of command arguments to pass to the container
	Command []string
	// Env contains additional environment variables to set
	Env map[string]string
	// EnvFile loads the given file with the list of environment variables and values
	EnvFile string
	// Labels contains a list of labels to apply to the container
	Labels map[string]string
	// ForcePull forces a docker pull before running the container, useful if the tag was updated
	ForcePull bool
	// Hosts is a list of additional hosts that the container can resolve, like from /etc/hosts
	// Hosts are given `name:ip` strings like 'foo:10.0.0.3'
	Hosts []string
	// StdoutFilePath directs all standard error to a file
	StdoutFilePath string
	// RedirectStdError redirects all standard err output into standard out
	RedirectStdError bool
	// Stdout directs all standard out to the given writer
	Stdout io.Writer
	// Stderr directs all standard err to the given writer
	Stderr io.Writer
	// StdoutCallback is an optional function that is called with every output line of the container's standard out
	StdoutCallback func(string)
	// StderrCallback is an optional function that is called with every output line of the container's standard err
	StderrCallback func(string)
}

Options are the container run options

func (Options) Apply

func (o Options) Apply(t *Options)

type Service

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

func NewService

func NewService(conn grpc.ClientConnInterface) *Service

func (*Service) RunContainer

func (c *Service) RunContainer(ctx context.Context, image string, opts ...Option) error

RunContainer runs a docker container. The container being run should exit. If the container exits with a non-zero exit code, an error implementing `interface { ExitCode() int }` will be returned from which the exit code may be extracted.

Jump to

Keyboard shortcuts

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