engine

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2014 License: Apache-2.0 Imports: 17 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 added in v0.7.1

func Tail(buffer *bytes.Buffer, n int) string

Tail returns the n last lines of a buffer stripped out of the last \n, if any if n <= 0, returns an empty string

Types

type Decoder added in v0.7.2

type Decoder struct {
	*json.Decoder
}

func NewDecoder added in v0.7.2

func NewDecoder(src io.Reader) *Decoder

func (*Decoder) Decode added in v0.7.2

func (decoder *Decoder) Decode() (*Env, error)

type Engine

type Engine struct {
	Stdout  io.Writer
	Stderr  io.Writer
	Stdin   io.Reader
	Logging bool
	// 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() *Engine

New initializes a new engine.

func (*Engine) Hack_GetGlobalVar added in v0.6.7

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

func (*Engine) Hack_SetGlobalVar added in v0.6.7

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 added in v0.6.7

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

func (*Engine) ParseJob added in v0.9.0

func (eng *Engine) ParseJob(input string) (*Job, error)

ParseJob creates a new job from a text description using a shell-like syntax.

The following syntax is used to parse `input`:

* Words are separated using standard whitespaces as separators. * Quotes and backslashes are not interpreted. * Words of the form 'KEY=[VALUE]' are added to the job environment. * All other words are added to the job arguments.

For example:

job, _ := eng.ParseJob("VERBOSE=1 echo hello TEST=true world")

The resulting job will have:

job.Args={"echo", "hello", "world"}
job.Env={"VERBOSE":"1", "TEST":"true"}

func (*Engine) Register added in v0.6.7

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

func (*Engine) RegisterCatchall added in v0.11.0

func (eng *Engine) RegisterCatchall(catchall Handler)

func (*Engine) ServeHTTP added in v0.7.2

func (eng *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP executes a job as specified by the http request `r`, and sends the result as an http response. This method allows an Engine instance to be passed as a standard http.Handler interface.

Note that the protocol used in this method is a convenience wrapper and is not the canonical implementation of remote job execution. This is because HTTP/1 does not handle stream multiplexing, and so cannot differentiate stdout from stderr. Additionally, headers cannot be added to a response once data has been written to the body, which makes it inconvenient to return metadata such as the exit status.

func (*Engine) String added in v0.6.7

func (eng *Engine) String() string

type Env added in v0.7.2

type Env []string

func (*Env) Decode added in v0.7.2

func (env *Env) Decode(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 (*Env) Encode added in v0.7.2

func (env *Env) Encode(dst io.Writer) error

func (*Env) Exists added in v0.7.2

func (env *Env) Exists(key string) bool

func (*Env) Get added in v0.7.2

func (env *Env) Get(key string) (value string)

func (*Env) GetBool added in v0.7.2

func (env *Env) GetBool(key string) (value bool)

func (*Env) GetInt added in v0.7.2

func (env *Env) GetInt(key string) int

func (*Env) GetInt64 added in v0.7.2

func (env *Env) GetInt64(key string) int64

func (*Env) GetJson added in v0.7.2

func (env *Env) GetJson(key string, iface interface{}) error

func (*Env) GetList added in v0.7.2

func (env *Env) GetList(key string) []string

Returns nil if key not found

func (*Env) GetSubEnv added in v0.8.0

func (env *Env) GetSubEnv(key string) *Env

func (*Env) Import added in v0.7.2

func (env *Env) Import(src interface{}) (err error)

func (*Env) Init added in v0.9.0

func (env *Env) Init(src *Env)

func (*Env) InitMultiMap added in v0.12.0

func (env *Env) InitMultiMap(m map[string][]string)

InitMultiMap removes all values in env, then initializes new values from the contents of m.

func (*Env) Len added in v0.11.0

func (env *Env) Len() int

Len returns the number of keys in the environment. Note that len(env) might be different from env.Len(), because the same key might be set multiple times.

func (*Env) Map added in v0.7.2

func (env *Env) Map() map[string]string

func (*Env) MultiMap added in v0.12.0

func (env *Env) MultiMap() map[string][]string

MultiMap returns a representation of env as a map of string arrays, keyed by string. This is the same structure as http headers for example, which allow each key to have multiple values.

func (*Env) Set added in v0.7.2

func (env *Env) Set(key, value string)

func (*Env) SetAuto added in v0.7.2

func (env *Env) SetAuto(k string, v interface{})

func (*Env) SetBool added in v0.7.2

func (env *Env) SetBool(key string, value bool)

func (*Env) SetInt added in v0.7.2

func (env *Env) SetInt(key string, value int)

func (*Env) SetInt64 added in v0.7.2

func (env *Env) SetInt64(key string, value int64)

func (*Env) SetJson added in v0.7.2

func (env *Env) SetJson(key string, value interface{}) error

func (*Env) SetList added in v0.7.2

func (env *Env) SetList(key string, value []string) error

func (*Env) SetSubEnv added in v0.8.0

func (env *Env) SetSubEnv(key string, sub *Env) error

func (*Env) WriteTo added in v0.7.2

func (env *Env) WriteTo(dst io.Writer) (n int64, err error)

type Hack added in v0.6.7

type Hack map[string]interface{}

type Handler

type Handler func(*Job) Status

type Input added in v0.7.1

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

func NewInput added in v0.7.1

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 added in v0.7.1

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) Close added in v0.8.0

func (i *Input) Close() error

Closes the src Not thread safe on purpose

func (*Input) Read added in v0.7.1

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

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

type Installer added in v0.11.0

type Installer interface {
	Install(*Engine) error
}

Installer is a standard interface for objects which can "install" themselves on an engine by registering handlers. This can be used as an entrypoint for external plugins etc.

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 added in v0.6.7

func (job *Job) CallString() string

func (*Job) DecodeEnv added in v0.6.7

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 added in v0.6.7

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

func (*Job) Env added in v0.9.0

func (job *Job) Env() *Env

func (*Job) EnvExists added in v0.8.0

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

func (*Job) Environ added in v0.6.7

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

func (*Job) Error added in v0.7.1

func (job *Job) Error(err error) Status

func (*Job) Errorf added in v0.6.7

func (job *Job) Errorf(format string, args ...interface{}) Status

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 added in v0.6.7

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

func (*Job) GetenvInt64 added in v0.7.2

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

func (*Job) GetenvJson added in v0.7.2

func (job *Job) GetenvJson(key string, iface interface{}) error

func (*Job) GetenvList

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

Returns nil if key not found

func (*Job) GetenvSubEnv added in v0.8.0

func (job *Job) GetenvSubEnv(key string) *Env

func (*Job) ImportEnv added in v0.6.7

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

func (*Job) Logf added in v0.6.7

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

func (*Job) Printf added in v0.6.7

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 added in v0.6.7

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

func (*Job) SetenvInt64 added in v0.7.2

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

func (*Job) SetenvJson added in v0.6.7

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

func (*Job) SetenvList

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

func (*Job) SetenvSubEnv added in v0.8.0

func (job *Job) SetenvSubEnv(key string, value *Env) error

func (*Job) StatusCode added in v0.11.0

func (job *Job) StatusCode() int

func (*Job) StatusString added in v0.6.7

func (job *Job) StatusString() string

func (*Job) String

func (job *Job) String() string

String returns a human-readable description of `job`

type Output added in v0.7.1

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

func NewOutput added in v0.7.1

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 added in v0.7.1

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

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.

func (*Output) AddEnv added in v0.7.2

func (o *Output) AddEnv() (dst *Env, err error)

AddEnv starts a new goroutine which will decode all subsequent data as a stream of json-encoded objects, and point `dst` to the last decoded object. The result `env` can be queried using the type-neutral Env interface. It is not safe to query `env` until the Output is closed.

func (*Output) AddListTable added in v0.8.0

func (o *Output) AddListTable() (dst *Table, err error)

func (*Output) AddPipe added in v0.7.1

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) AddTable added in v0.8.0

func (o *Output) AddTable() (dst *Table, err error)

func (*Output) Close added in v0.7.1

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) Set added in v0.8.0

func (o *Output) Set(dst io.Writer)

Set closes and remove existing destination and then 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.

func (*Output) Used added in v0.8.0

func (o *Output) Used() bool

Return true if something was written on this output

func (*Output) Write added in v0.7.1

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 Receiver added in v0.11.0

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

func NewReceiver added in v0.11.0

func NewReceiver(peer beam.Receiver) *Receiver

func (*Receiver) Run added in v0.11.0

func (rcv *Receiver) Run() error

type Sender added in v0.11.0

type Sender struct {
	beam.Sender
}

func NewSender added in v0.11.0

func NewSender(s beam.Sender) *Sender

func (*Sender) Handle added in v0.11.0

func (s *Sender) Handle(job *Job) Status

func (*Sender) Install added in v0.11.0

func (s *Sender) Install(eng *Engine) error

type Status added in v0.7.1

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

type Table added in v0.8.0

type Table struct {
	Data []*Env

	Chan chan *Env
	// contains filtered or unexported fields
}

func NewTable added in v0.8.0

func NewTable(sortKey string, sizeHint int) *Table

func (*Table) Add added in v0.8.0

func (t *Table) Add(env *Env)

func (*Table) Len added in v0.8.0

func (t *Table) Len() int

func (*Table) Less added in v0.8.0

func (t *Table) Less(a, b int) bool

func (*Table) ReadFrom added in v0.8.0

func (t *Table) ReadFrom(src io.Reader) (n int64, err error)

func (*Table) ReadListFrom added in v0.8.0

func (t *Table) ReadListFrom(src []byte) (n int64, err error)

func (*Table) ReverseSort added in v0.8.0

func (t *Table) ReverseSort()

func (*Table) SetKey added in v0.8.0

func (t *Table) SetKey(sortKey string)

func (*Table) Sort added in v0.8.0

func (t *Table) Sort()

func (*Table) Swap added in v0.8.0

func (t *Table) Swap(a, b int)

func (*Table) ToListString added in v0.8.0

func (t *Table) ToListString() (string, error)

func (*Table) WriteListTo added in v0.8.0

func (t *Table) WriteListTo(dst io.Writer) (n int64, err error)

func (*Table) WriteTo added in v0.8.0

func (t *Table) WriteTo(dst io.Writer) (n int64, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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