config

package
v0.0.0-...-dc5648e Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2018 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package config holds functionality for processing compose.yml manifests, templating, converting manifests to docker api run spec and comparing them against each other.

Comparing mechanism plays the key role for rocker-compose idempotency features. We implement both parsing and serializing for each property and whole manifests, which allows us to store configuration in a label of a container and makes easier detecting changes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

type Cmd []string

Cmd implements yaml [un]serializable "cmd" property of the container spec. See yaml.go for more info.

func (*Cmd) UnmarshalYAML

func (cmd *Cmd) UnmarshalYAML(unmarshal func(interface{}) error) (err error)

UnmarshalYAML unserialize Cmd object from YAML If string is given, then it adds '/bin/sh -c' prefix to a command

type Config

type Config struct {
	Namespace  string // All containers names under current compose.yml will be prefixed with this namespace
	Containers map[string]*Container
	Vars       template.Vars
}

Config represents the data structure which is loaded from compose.yml

func NewFromFile

func NewFromFile(filename string, vars template.Vars, funcs map[string]interface{}, print bool) (*Config, error)

NewFromFile reads and parses config from a file. If given filename is not absolute path, it resolves absolute name from the current working directory. See ReadConfig/4 for reading and parsing details.

func ReadConfig

func ReadConfig(configName string, reader io.Reader, vars template.Vars, funcs map[string]interface{}, print bool) (*Config, error)

ReadConfig reads and parses the config from io.Reader stream. Before parsing it processes config through a template engine implemented in template.go.

func (*Config) HasExternalRefs

func (c *Config) HasExternalRefs() bool

HasExternalRefs returns true if there is at least one reference to the external namespace

func (*Config) UnmarshalYAML

func (config *Config) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unserialize Config object form YAML It supports compatibility with docker-compose YAML spec where containers map is specified on the first level. rocker-compose provides extra level for global properties such as 'namespace' This function fallbacks to the docker-compose format if 'namespace' key was not found on the first level.

type Container

type Container struct {
	Extends         string         `yaml:"extends,omitempty"`           // can extend from other container spec referring by name
	Image           *string        `yaml:"image,omitempty"`             //
	Net             *Net           `yaml:"net,omitempty"`               //
	Pid             *string        `yaml:"pid,omitempty"`               //
	Uts             *string        `yaml:"uts,omitempty"`               //
	State           *State         `yaml:"state,omitempty"`             // "running" or "created" or "ran"
	DNS             Strings        `yaml:"dns,omitempty"`               //
	AddHost         Strings        `yaml:"add_host,omitempty"`          //
	Restart         *RestartPolicy `yaml:"restart,omitempty"`           //
	Memory          *Memory        `yaml:"memory,omitempty"`            //
	MemorySwap      *Memory        `yaml:"memory_swap,omitempty"`       //
	CPUShares       *int64         `yaml:"cpu_shares,omitempty"`        //
	CpusetCpus      *string        `yaml:"cpuset_cpus,omitempty"`       //
	OomKillDisable  *bool          `yaml:"oom_kill_disable,omitempty"`  // e.g. docker run --oom-kill-disable TODO: pull request to go-dockerclient
	Ulimits         []Ulimit       `yaml:"ulimits,omitempty"`           // search by "Ulimits" here https://goo.gl/IxbZck
	Privileged      *bool          `yaml:"privileged,omitempty"`        //
	Cmd             Cmd            `yaml:"cmd,omitempty"`               //
	Entrypoint      Strings        `yaml:"entrypoint,omitempty"`        //
	Expose          Strings        `yaml:"expose,omitempty"`            //
	Ports           Ports          `yaml:"ports,omitempty"`             //
	LogDriver       *string        `yaml:"log_driver,omitempty"`        //
	LogOpt          StringMap      `yaml:"log_opt,omitempty"`           //
	PublishAllPorts *bool          `yaml:"publish_all_ports,omitempty"` //
	Labels          StringMap      `yaml:"labels,omitempty"`            //
	Env             StringMap      `yaml:"env,omitempty"`               //
	VolumesFrom     ContainerNames `yaml:"volumes_from,omitempty"`      //
	Volumes         Strings        `yaml:"volumes,omitempty"`           //
	Links           Links          `yaml:"links,omitempty"`             //
	WaitFor         ContainerNames `yaml:"wait_for,omitempty"`          //
	KillTimeout     *uint          `yaml:"kill_timeout,omitempty"`      //
	Hostname        *string        `yaml:"hostname,omitempty"`          //
	Domainname      *string        `yaml:"domainname,omitempty"`        //
	User            *string        `yaml:"user,omitempty"`              //
	Workdir         *string        `yaml:"workdir,omitempty"`           //
	NetworkDisabled *bool          `yaml:"network_disabled,omitempty"`  // TODO: do we need this?
	KeepVolumes     *bool          `yaml:"keep_volumes,omitempty"`      //

	Command     Cmd       `yaml:"command,omitempty"`
	Link        Links     `yaml:"link,omitempty"`
	Label       StringMap `yaml:"label,omitempty"`
	Hosts       Strings   `yaml:"hosts,omitempty"`
	ExtraHosts  Strings   `yaml:"extra_hosts,omitempty"`
	WorkingDir  *string   `yaml:"working_dir,omitempty"`
	Environment StringMap `yaml:"environment,omitempty"`

	// Extra properties that is not known by rocker-compose
	Extra map[string]interface{} `yaml:"extra,omitempty"`
	// contains filtered or unexported fields
}

Container represents a single container spec from compose.yml

func NewFromDocker

func NewFromDocker(apiContainer *docker.Container) (*Container, error)

NewFromDocker produces an container spec object from a docker.Container given by go-dockerclient.

func (*Container) ExtendFrom

func (container *Container) ExtendFrom(parent *Container)

ExtendFrom extends the container spec from a given one

func (*Container) GetAPIConfig

func (config *Container) GetAPIConfig() *docker.Config

GetAPIConfig as an opposite from NewFromDocker - it returns docker.Config that can be used to run containers through the docker api.

func (*Container) GetAPIHostConfig

func (config *Container) GetAPIHostConfig() *docker.HostConfig

GetAPIHostConfig as an opposite from NewFromDocker - it returns docker.HostConfig that can be used to run containers through the docker api.

func (*Container) IsEqualTo

func (a *Container) IsEqualTo(b *Container) bool

IsEqualTo compares the container spec against another one. It returns false if at least one property is unequal.

func (*Container) LastCompareField

func (a *Container) LastCompareField() string

LastCompareField returns last equal compared field of IsEqualTo evaluation.

type ContainerName

type ContainerName struct {
	Namespace string
	Name      string
}

ContainerName represents the pair of namespace and container name. It is used in all places that refers to container by name, such as: containers in manifests, volumes_from, etc.

func NewContainerName

func NewContainerName(namespace, name string) *ContainerName

NewContainerName produce ContainerName object

func NewContainerNameFromString

func NewContainerNameFromString(str string) *ContainerName

NewContainerNameFromString parses a string to a ContainerName object format: name | namespace.name

func (*ContainerName) DefaultNamespace

func (n *ContainerName) DefaultNamespace(ns string)

DefaultNamespace assigns a namespace for ContainerName it does not have one.

func (*ContainerName) GetNamespace

func (n *ContainerName) GetNamespace() string

GetNamespace returns a real namespace of the container name if there is no namespace (global) then it returns an empty string

func (*ContainerName) IsEqualNs

func (a *ContainerName) IsEqualNs(b *ContainerName) bool

IsEqualNs returns true if both containers have same namespace.

func (*ContainerName) IsEqualTo

func (a *ContainerName) IsEqualTo(b *ContainerName) bool

IsEqualTo compares the ContainerName against another one. namespace and name should be same.

func (*ContainerName) IsGlobalNs

func (n *ContainerName) IsGlobalNs() bool

IsGlobalNs returns true if the container is in global space

func (ContainerName) MarshalYAML

func (n ContainerName) MarshalYAML() (interface{}, error)

MarshalYAML serialize ContainerName object to YAML

func (ContainerName) String

func (n ContainerName) String() string

String gives a string representation of the container name

func (*ContainerName) UnmarshalYAML

func (n *ContainerName) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unserialize ContainerName object from YAML

type ContainerNames

type ContainerNames []ContainerName

ContainerNames is a collection of container references

func (*ContainerNames) UnmarshalYAML

func (v *ContainerNames) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unserialize slice of ContainerName objects from YAML Either single value or array can be given. Single 'value' casts to array{'value'}

type ErrNotRockerCompose

type ErrNotRockerCompose struct {
	ContainerID string
}

ErrNotRockerCompose error describing that given container was not likely to beinitialized by rocker-compose

func (ErrNotRockerCompose) Error

func (err ErrNotRockerCompose) Error() string

Error returns string error

type Link struct {
	ContainerName ContainerName
	Alias         string
}

Link is same as ContainerName with addition of Alias property, which specifies associated container alias

func NewLinkFromString

func NewLinkFromString(str string) *Link

NewLinkFromString parses a string to a Link object format: name | namespace.name | name:alias | namespace.name:alias

func (*Link) DefaultNamespace

func (link *Link) DefaultNamespace(ns string)

DefaultNamespace assigns a namespace for Link it does not have one.

func (*Link) GetNamespace

func (link *Link) GetNamespace() string

GetNamespace returns a real namespace of the container name if there is no namespace (global) then it returns an empty string

func (*Link) IsGlobalNs

func (link *Link) IsGlobalNs() bool

IsGlobalNs returns true if the container is in global space

func (Link) MarshalYAML

func (link Link) MarshalYAML() (interface{}, error)

MarshalYAML serialize ContainerName object to YAML

func (Link) String

func (link Link) String() string

String is same as ContainerName.String() but adds alias

func (*Link) UnmarshalYAML

func (link *Link) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unserialize Link object from YAML

type Links []Link

Links is a collection of container links

func (*Links) UnmarshalYAML

func (v *Links) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unserialize slice of Link objects from YAML Either single value or array can be given. Single 'value' casts to array{'value'}

type Memory

type Memory int64

Memory is memory in bytes that is used for Memory and MemorySwap properties of the container spec. It is parsed from string (e.g. "64M") to int64 bytes as a uniform representation.

func NewConfigMemoryFromInt64

func NewConfigMemoryFromInt64(value int64) *Memory

NewConfigMemoryFromInt64 makes a ConfigMemory from int64 value

func NewConfigMemoryFromString

func NewConfigMemoryFromString(str string) (*Memory, error)

NewConfigMemoryFromString parses a string to a ConfigMemory object Examples of string that can be given:

"124124" (124124 bytes)
"124124b" (same)
"1024k"
"512m"
"2g"

func (*Memory) Int64

func (m *Memory) Int64() int64

Int64 returns int64 value of the ConfigMemory object

func (*Memory) UnmarshalYAML

func (m *Memory) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unserialize ConfigMemory object from YAML

type Net

type Net struct {
	Type      string // bridge|none|container|host
	Container ContainerName
}

Net is "net" property, which can also refer to some container

func NewNetFromString

func NewNetFromString(str string) (*Net, error)

NewNetFromString parses a string to a Net object. Possible values: bridge|none|container:CONTAINER_NAME|host

func (*Net) MarshalYAML

func (n *Net) MarshalYAML() (interface{}, error)

MarshalYAML serialize Net object to YAML

func (*Net) String

func (net *Net) String() string

String returns string representation of Net object.

func (*Net) UnmarshalYAML

func (n *Net) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unserialize Net object from YAML

type PortBinding

type PortBinding struct {
	Port     string
	HostIP   string
	HostPort string
}

PortBinding represents a single port binding spec, which is used in "ports" property. format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort

func (PortBinding) MarshalYAML

func (b PortBinding) MarshalYAML() (interface{}, error)

MarshalYAML serialize PortBinding object to YAML

func (*PortBinding) UnmarshalYAML

func (b *PortBinding) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unserialize PortBinding object from YAML

type Ports

type Ports []PortBinding

Ports is a collection of port bindings

func (*Ports) UnmarshalYAML

func (v *Ports) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unserialize slice of Port objects from YAML Either single value or array can be given. Single 'value' casts to array{'value'}

type RestartPolicy

type RestartPolicy struct {
	Name              string
	MaximumRetryCount int
}

RestartPolicy represents "restart" property of the container spec. Possible values are: no | always | on-failure,N (where N is number of times it is allowed to fail) Default value is "always". Despite Docker's default value is "no", we found that more often we want to have "always" and people constantly forget to put it.

func (*RestartPolicy) MarshalYAML

func (r *RestartPolicy) MarshalYAML() (interface{}, error)

MarshalYAML serialize RestartPolicy object to YAML

func (*RestartPolicy) ToDockerAPI

func (r *RestartPolicy) ToDockerAPI() docker.RestartPolicy

ToDockerAPI converts RestartPolicy to a docker.RestartPolicy object which is eatable by go-dockerclient.

func (*RestartPolicy) UnmarshalYAML

func (r *RestartPolicy) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unserialize RestartPolicy object from YAML

type State

type State string

State represents "state" property from the manifest. Possible values are: running | created | ran

func (*State) Bool

func (state *State) Bool() bool

Bool returns true if state is "running" or not specified

func (*State) IsRan

func (state *State) IsRan() bool

IsRan returns true if state is "ran"

type StringMap

type StringMap map[string]string

StringMap implements yaml [un]serializable map[string]string is used for "labels" and "env" properties. See yaml.go for more info.

func (*StringMap) UnmarshalYAML

func (v *StringMap) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unserialize map[string]string objects from YAML Map can be also specified as string "key=val key2=val2" and also as array of strings []string{"key=val", "key2=val2"}

type Strings

type Strings []string

Strings implements yaml [un]serializable list of strings. See yaml.go for more info.

func (*Strings) UnmarshalYAML

func (v *Strings) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unserialize slice of Strings from YAML Either single value or array can be given. Single 'value' casts to array{'value'}

type Ulimit

type Ulimit struct {
	Name string
	Soft int64
	Hard int64
}

Ulimit describes ulimit specification for the manifest file

Jump to

Keyboard shortcuts

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