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 ¶
- type Cmd
- type Config
- type Container
- type ContainerName
- func (n *ContainerName) DefaultNamespace(ns string)
- func (n *ContainerName) GetNamespace() string
- func (a *ContainerName) IsEqualNs(b *ContainerName) bool
- func (a *ContainerName) IsEqualTo(b *ContainerName) bool
- func (n *ContainerName) IsGlobalNs() bool
- func (n ContainerName) MarshalYAML() (interface{}, error)
- func (n ContainerName) String() string
- func (n *ContainerName) UnmarshalYAML(unmarshal func(interface{}) error) error
- type ContainerNames
- type ErrNotRockerCompose
- type Link
- type Links
- type Memory
- type Net
- type PortBinding
- type Ports
- type RestartPolicy
- type State
- type StringMap
- type Strings
- type Ulimit
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 ¶
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 ¶
HasExternalRefs returns true if there is at least one reference to the external namespace
func (*Config) UnmarshalYAML ¶
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"` // 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 ¶
NewFromDocker produces an container spec object from a docker.Container given by go-dockerclient.
func (*Container) ExtendFrom ¶
ExtendFrom extends the container spec from a given one
func (*Container) GetAPIConfig ¶
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 ¶
IsEqualTo compares the container spec against another one. It returns false if at least one property is unequal.
func (*Container) LastCompareField ¶
LastCompareField returns last equal compared field of IsEqualTo evaluation.
type ContainerName ¶
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 ¶
type Link struct { ContainerName ContainerName Alias string }
Link is same as ContainerName with addition of Alias property, which specifies associated container alias
func NewLinkFromString ¶
NewLinkFromString parses a string to a Link object format: name | namespace.name | name:alias | namespace.name:alias
func (*Link) DefaultNamespace ¶
DefaultNamespace assigns a namespace for Link it does not have one.
func (*Link) GetNamespace ¶
GetNamespace returns a real namespace of the container name if there is no namespace (global) then it returns an empty string
func (*Link) IsGlobalNs ¶
IsGlobalNs returns true if the container is in global space
func (Link) MarshalYAML ¶
MarshalYAML serialize ContainerName object to YAML
func (*Link) UnmarshalYAML ¶
UnmarshalYAML unserialize Link object from YAML
type Links ¶
type Links []Link
Links is a collection of container links
func (*Links) UnmarshalYAML ¶
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 ¶
NewConfigMemoryFromInt64 makes a ConfigMemory from int64 value
func NewConfigMemoryFromString ¶
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) UnmarshalYAML ¶
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 ¶
NewNetFromString parses a string to a Net object. Possible values: bridge|none|container:CONTAINER_NAME|host
func (*Net) MarshalYAML ¶
MarshalYAML serialize Net object to YAML
func (*Net) UnmarshalYAML ¶
UnmarshalYAML unserialize Net object from YAML
type PortBinding ¶
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 ¶
UnmarshalYAML unserialize slice of Port objects from YAML Either single value or array can be given. Single 'value' casts to array{'value'}
type RestartPolicy ¶
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
type StringMap ¶
StringMap implements yaml [un]serializable map[string]string is used for "labels" and "env" properties. See yaml.go for more info.
func (*StringMap) UnmarshalYAML ¶
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 ¶
UnmarshalYAML unserialize slice of Strings from YAML Either single value or array can be given. Single 'value' casts to array{'value'}