engine

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2013 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(name string, handler Handler) error

func Tail

func Tail(src io.Reader, n int, dst *[]string)

Tail reads from `src` line per line, and returns the last `n` lines as an array. A ring buffer is used to only store `n` lines at any time.

Types

type Engine

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

The Engine is the core of Docker. It acts as a store for *containers*, and allows manipulation of these containers by executing *jobs*.

func New

func New(root string) (*Engine, error)

New initializes a new engine managing the directory specified at `root`. `root` is used to store containers and any other state private to the engine. Changing the contents of the root without executing a job will cause unspecified behavior.

func (*Engine) Hack_GetGlobalVar

func (eng *Engine) Hack_GetGlobalVar(key string) interface{}

func (*Engine) Hack_SetGlobalVar

func (eng *Engine) Hack_SetGlobalVar(key string, val interface{})

func (*Engine) Job

func (eng *Engine) Job(name string, args ...string) *Job

Job creates a new job which can later be executed. This function mimics `Command` from the standard os/exec package.

func (*Engine) Logf

func (eng *Engine) Logf(format string, args ...interface{}) (n int, err error)

func (*Engine) Register

func (eng *Engine) Register(name string, handler Handler) error

func (*Engine) Root

func (eng *Engine) Root() string

func (*Engine) String

func (eng *Engine) String() string

type Hack

type Hack map[string]interface{}

type Handler

type Handler func(*Job) Status

type Input

type Input struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewInput

func NewInput() *Input

NewInput returns a new Input object with no source attached. Reading to an empty Input will return io.EOF.

func (*Input) Add

func (i *Input) Add(src io.Reader) error

Add attaches a new source to the input. Add can only be called once per input. Subsequent calls will return an error.

func (*Input) Read

func (i *Input) Read(p []byte) (n int, err error)

Read reads from the input in a thread-safe way.

type Job

type Job struct {
	Eng  *Engine
	Name string
	Args []string

	Stdout *Output
	Stderr *Output
	Stdin  *Input
	// contains filtered or unexported fields
}

A job is the fundamental unit of work in the docker engine. Everything docker can do should eventually be exposed as a job. For example: execute a process in a container, create a new container, download an archive from the internet, serve the http api, etc.

The job API is designed after unix processes: a job has a name, arguments, environment variables, standard streams for input, output and error, and an exit status which can indicate success (0) or error (anything else).

One slight variation is that jobs report their status as a string. The string "0" indicates success, and any other strings indicates an error. This allows for richer error reporting.

func (*Job) CallString

func (job *Job) CallString() string

func (*Job) DecodeEnv

func (job *Job) DecodeEnv(src io.Reader) error

DecodeEnv decodes `src` as a json dictionary, and adds each decoded key-value pair to the environment.

If `src` cannot be decoded as a json dictionary, an error is returned.

func (*Job) EncodeEnv

func (job *Job) EncodeEnv(dst io.Writer) error

func (*Job) Environ

func (job *Job) Environ() map[string]string

func (*Job) Error

func (job *Job) Error(err error) (int, error)

func (*Job) Errorf

func (job *Job) Errorf(format string, args ...interface{}) (n int, err error)

func (*Job) ExportEnv

func (job *Job) ExportEnv(dst interface{}) (err error)

func (*Job) Getenv

func (job *Job) Getenv(key string) (value string)

func (*Job) GetenvBool

func (job *Job) GetenvBool(key string) (value bool)

func (*Job) GetenvInt

func (job *Job) GetenvInt(key string) int64

func (*Job) GetenvList

func (job *Job) GetenvList(key string) []string

Returns nil if key not found

func (*Job) ImportEnv

func (job *Job) ImportEnv(src interface{}) (err error)

func (*Job) Logf

func (job *Job) Logf(format string, args ...interface{}) (n int, err error)

func (*Job) Printf

func (job *Job) Printf(format string, args ...interface{}) (n int, err error)

func (*Job) Run

func (job *Job) Run() error

Run executes the job and blocks until the job completes. If the job returns a failure status, an error is returned which includes the status.

func (*Job) Setenv

func (job *Job) Setenv(key, value string)

func (*Job) SetenvBool

func (job *Job) SetenvBool(key string, value bool)

func (*Job) SetenvInt

func (job *Job) SetenvInt(key string, value int64)

func (*Job) SetenvJson

func (job *Job) SetenvJson(key string, value interface{}) error

func (*Job) SetenvList

func (job *Job) SetenvList(key string, value []string) error

func (*Job) StatusString

func (job *Job) StatusString() string

func (*Job) String

func (job *Job) String() string

String returns a human-readable description of `job`

type Output

type Output struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewOutput

func NewOutput() *Output

NewOutput returns a new Output object with no destinations attached. Writing to an empty Output will cause the written data to be discarded.

func (*Output) Add

func (o *Output) Add(dst io.Writer) error

Add attaches a new destination to the Output. Any data subsequently written to the output will be written to the new destination in addition to all the others. This method is thread-safe. FIXME: Add cannot fail

func (*Output) AddPipe

func (o *Output) AddPipe() (io.Reader, error)

AddPipe creates an in-memory pipe with io.Pipe(), adds its writing end as a destination, and returns its reading end for consumption by the caller. This is a rough equivalent similar to Cmd.StdoutPipe() in the standard os/exec package. This method is thread-safe.

func (*Output) AddString

func (o *Output) AddString(dst *string) error

AddString starts a new goroutine which will read all subsequent data written to the output, line by line, and store the last line into `dst`.

func (*Output) AddTail

func (o *Output) AddTail(dst *[]string, n int) error

AddTail starts a new goroutine which will read all subsequent data written to the output, line by line, and append the last `n` lines to `dst`.

func (*Output) Close

func (o *Output) Close() error

Close unregisters all destinations and waits for all background AddTail and AddString tasks to complete. The Close method of each destination is called if it exists.

func (*Output) Write

func (o *Output) Write(p []byte) (n int, err error)

Write writes the same data to all registered destinations. This method is thread-safe.

type Status

type Status int
const (
	StatusOK       Status = 0
	StatusErr      Status = 1
	StatusNotFound Status = 127
)

Jump to

Keyboard shortcuts

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