compose

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2018 License: MIT Imports: 34 Imported by: 0

README

Documentation

Index

Constants

View Source
const (

	// LabelImage is the label used to store image name provided in the compose file
	LabelImage = "com.docker.stack.image"
)
View Source
const (
	// LabelNamespace is the label used to track stack resources
	LabelNamespace = "com.docker.stack.namespace"
)

Variables

View Source
var DeprecatedProperties = map[string]string{
	"container_name": "Setting the container name is not supported.",
	"expose":         "Exposing ports is unnecessary - services on the same network can access each other's containers on any port.",
}

DeprecatedProperties that were removed from the v3 format, but their use should not impact the behaviour of the application.

View Source
var ForbiddenProperties = map[string]string{
	"extends":       "Support for `extends` is not implemented yet.",
	"volume_driver": "Instead of setting the volume driver on the service, define a volume using the top-level `volumes` option and specify the driver there.",
	"volumes_from":  "To share a volume between services, define it using the top-level `volumes` option and reference it from each service that shares it using the service-level `volumes` option.",
	"cpu_quota":     "Set resource limits using deploy.resources",
	"cpu_shares":    "Set resource limits using deploy.resources",
	"cpuset":        "Set resource limits using deploy.resources",
	"mem_limit":     "Set resource limits using deploy.resources",
	"memswap_limit": "Set resource limits using deploy.resources",
}

ForbiddenProperties that are not supported in this implementation of the compose file.

View Source
var UnsupportedProperties = []string{
	"build",
	"cap_add",
	"cap_drop",
	"cgroup_parent",
	"devices",
	"domainname",
	"external_links",
	"ipc",
	"links",
	"mac_address",
	"network_mode",
	"privileged",
	"restart",
	"security_opt",
	"shm_size",
	"sysctls",
	"tmpfs",
	"ulimits",
	"userns_mode",
}

UnsupportedProperties not yet supported by this implementation of the compose file

Functions

func AddStackLabel

func AddStackLabel(namespace Namespace, labels map[string]string) map[string]string

AddStackLabel returns labels with the namespace label added

func Configs

func Configs(namespace Namespace, configs map[string]ConfigObjConfig) ([]swarm.ConfigSpec, error)

Configs converts config objects from the Compose type to the engine API type

func ConvertKVStringsToMapWithNil

func ConvertKVStringsToMapWithNil(values []string) map[string]*string

ConvertKVStringsToMapWithNil converts ["key=value"] to {"key":"value"} but set unset keys to nil - meaning the ones with no "=" in them. We use this in cases where we need to distinguish between

FOO=  and FOO

where the latter case just means FOO was mentioned but not given a value

func ConvertPortToPortConfig

func ConvertPortToPortConfig(
	port nat.Port,
	portBindings map[nat.Port][]nat.PortBinding,
) ([]swarm.PortConfig, error)

ConvertPortToPortConfig converts ports to the swarm type

func GetDeprecatedProperties

func GetDeprecatedProperties(configDetails ConfigDetails) map[string]string

GetDeprecatedProperties returns the list of any deprecated properties that are used in the compose files.

func GetServicesDeclaredNetworks

func GetServicesDeclaredNetworks(serviceConfigs []ServiceConfig) map[string]struct{}

func GetUnsupportedProperties

func GetUnsupportedProperties(configDetails ConfigDetails) []string

GetUnsupportedProperties returns the list of any unsupported properties that are used in the Compose files.

func Interpolate

func Interpolate(config map[string]interface{}, section string, mapping Mapping) (map[string]interface{}, error)

Interpolate replaces variables in a string with the values from a mapping

func LoadConfigObjs

func LoadConfigObjs(source map[string]interface{}, workingDir string) (map[string]ConfigObjConfig, error)

LoadConfigObjs produces a ConfigObjConfig map from a compose file Dict the source Dict is not validated if directly used. Use Load() to enable validation

func LoadNetworks

func LoadNetworks(source map[string]interface{}) (map[string]NetworkConfig, error)

LoadNetworks produces a NetworkConfig map from a compose file Dict the source Dict is not validated if directly used. Use Load() to enable validation

func LoadSecrets

func LoadSecrets(source map[string]interface{}, workingDir string) (map[string]SecretConfig, error)

LoadSecrets produces a SecretConfig map from a compose file Dict the source Dict is not validated if directly used. Use Load() to enable validation

func LoadVolumes

func LoadVolumes(source map[string]interface{}) (map[string]VolumeConfig, error)

LoadVolumes produces a VolumeConfig map from a compose file Dict the source Dict is not validated if directly used. Use Load() to enable validation

func Networks

func Networks(namespace Namespace, networks networkMap, servicesNetworks map[string]struct{}) (map[string]types.NetworkCreate, []string)

Networks from the compose-file type to the engine API type

func ParseCPUs

func ParseCPUs(value string) (int64, error)

ParseCPUs takes a string ratio and returns an integer value of nano cpus

func ParseConfigs

func ParseConfigs(client client.ConfigAPIClient, requestedConfigs []*swarm.ConfigReference) ([]*swarm.ConfigReference, error)

ParseConfigs retrieves the configs from the requested names and converts them to config references to use with the spec

func ParseEnvFile

func ParseEnvFile(filename string) ([]string, error)

ParseEnvFile reads a file with environment variables enumerated by lines

“Environment variable names used by the utilities in the Shell and Utilities volume of IEEE Std 1003.1-2001 consist solely of uppercase letters, digits, and the '_' (underscore) from the characters defined in Portable Character Set and do not begin with a digit. *But*, other characters may be permitted by an implementation; applications shall tolerate the presence of such names.” -- http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html

As of #16585, it's up to application inside docker to validate or not environment variables, that's why we just strip leading whitespace and nothing more.

func ParseRestartPolicy

func ParseRestartPolicy(policy string) (container.RestartPolicy, error)

ParseRestartPolicy returns the parsed policy or an error indicating what is incorrect

func ParseSecrets

func ParseSecrets(client *client.Client, requestedSecrets []*swarm.SecretReference) ([]*swarm.SecretReference, error)

ParseSecrets retrieves the secrets with the requested names and fills secret IDs into the secret references.

func ParseYAML

func ParseYAML(source []byte) (map[string]interface{}, error)

ParseYAML reads the bytes from a file, parses the bytes into a mapping structure, and returns it.

func Secrets

func Secrets(namespace Namespace, secrets map[string]SecretConfig) ([]swarm.SecretSpec, error)

Secrets converts secrets from the Compose type to the engine API type

func Service

func Service(
	apiVersion string,
	namespace Namespace,
	service ServiceConfig,
	networkConfigs map[string]NetworkConfig,
	volumes map[string]VolumeConfig,
	secrets []*swarm.SecretReference,
	configs []*swarm.ConfigReference,
) (swarm.ServiceSpec, error)

Service converts a ServiceConfig into a swarm ServiceSpec

func Services

func Services(
	namespace Namespace,
	config *Config,
	client *client.Client,
) (map[string]swarm.ServiceSpec, error)

Services from compose-file types to engine API types

func Substitute

func Substitute(template string, mapping Mapping) (string, error)

Substitute variables in the string with their values

func Volumes

func Volumes(serviceVolumes []ServiceVolumeConfig, stackVolumes volumes, namespace Namespace) ([]mount.Mount, error)

Volumes from compose-file types to engine api types

Types

type BuildConfig

type BuildConfig struct {
	Context    string
	Dockerfile string
	Args       MappingWithEquals
	Labels     Labels
	CacheFrom  StringList `mapstructure:"cache_from"`
	Network    string
	Target     string
}

BuildConfig is a type for build using the same format at libcompose: https://github.com/docker/libcompose/blob/master/yaml/build.go#L12

type Config

type Config struct {
	Services []ServiceConfig
	Networks map[string]NetworkConfig
	Volumes  map[string]VolumeConfig
	Secrets  map[string]SecretConfig
	Configs  map[string]ConfigObjConfig
}

Config is a full compose file configuration

func Load

func Load(configDetails ConfigDetails) (*Config, error)

Load reads a ConfigDetails and returns a fully loaded configuration

func Parse

func Parse(name, content string) (*Config, error)

type ConfigDetails

type ConfigDetails struct {
	WorkingDir  string
	ConfigFiles []ConfigFile
	Environment map[string]string
}

ConfigDetails are the details about a group of ConfigFiles

func (ConfigDetails) LookupEnv

func (cd ConfigDetails) LookupEnv(key string) (string, bool)

LookupEnv provides a lookup function for environment variables

type ConfigFile

type ConfigFile struct {
	Filename string
	Config   map[string]interface{}
}

ConfigFile is a filename and the contents of the file as a Dict

type ConfigObjConfig

type ConfigObjConfig fileObjectConfig

ConfigObjConfig is the config for the swarm "Config" object

type CredentialSpecConfig

type CredentialSpecConfig struct {
	File     string
	Registry string
}

CredentialSpecConfig for credential spec on Windows

type DeployConfig

type DeployConfig struct {
	Mode          string
	Replicas      *uint64
	Labels        Labels
	UpdateConfig  *UpdateConfig `mapstructure:"update_config"`
	Resources     Resources
	RestartPolicy *RestartPolicy `mapstructure:"restart_policy"`
	Placement     Placement
	EndpointMode  string `mapstructure:"endpoint_mode"`
}

DeployConfig the deployment configuration for a service

type ErrBadEnvVariable

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

ErrBadEnvVariable typed error for bad environment variable

func (ErrBadEnvVariable) Error

func (e ErrBadEnvVariable) Error() string

type External

type External struct {
	Name     string
	External bool
}

External identifies a Volume or Network as a reference to a resource that is not managed, and should already exist. External.name is deprecated and replaced by Volume.name

type ForbiddenPropertiesError

type ForbiddenPropertiesError struct {
	Properties map[string]string
}

ForbiddenPropertiesError is returned when there are properties in the Compose file that are forbidden.

func (*ForbiddenPropertiesError) Error

func (e *ForbiddenPropertiesError) Error() string

type HealthCheckConfig

type HealthCheckConfig struct {
	Test        HealthCheckTest
	Timeout     *time.Duration
	Interval    *time.Duration
	Retries     *uint64
	StartPeriod *time.Duration `mapstructure:"start_period"`
	Disable     bool
}

HealthCheckConfig the healthcheck configuration for a service

type HealthCheckTest

type HealthCheckTest []string

HealthCheckTest is the command run to test the health of a service

type IPAMConfig

type IPAMConfig struct {
	Driver string
	Config []*IPAMPool
}

IPAMConfig for a network

type IPAMPool

type IPAMPool struct {
	Subnet string
}

IPAMPool for a network

type InvalidTemplateError

type InvalidTemplateError struct {
	Template string
}

InvalidTemplateError is returned when a variable template is not in a valid format

func (InvalidTemplateError) Error

func (e InvalidTemplateError) Error() string

type Labels

type Labels map[string]string

Labels is a mapping type for labels

type LoggingConfig

type LoggingConfig struct {
	Driver  string
	Options map[string]string
}

LoggingConfig the logging configuration for a service

type Mapping

type Mapping func(string) (string, bool)

Mapping is a user-supplied function which maps from variable names to values. Returns the value as a string and a bool indicating whether the value is present, to distinguish between an empty string and the absence of a value.

type MappingWithColon

type MappingWithColon map[string]string

MappingWithColon is a mapping type that can be converted from a list of 'key: value' strings

type MappingWithEquals

type MappingWithEquals map[string]*string

MappingWithEquals is a mapping type that can be converted from a list of key[=value] strings. For the key with an empty value (`key=`), the mapped value is set to a pointer to `""`. For the key without value (`key`), the mapped value is set to nil.

type Namespace

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

Namespace mangles names by prepending the name

func NewNamespace

func NewNamespace(name string) Namespace

NewNamespace returns a new Namespace for scoping of names

func (Namespace) Descope

func (n Namespace) Descope(name string) string

Descope returns the name without the namespace prefix

func (Namespace) Name

func (n Namespace) Name() string

Name returns the name of the namespace

func (Namespace) Scope

func (n Namespace) Scope(name string) string

Scope prepends the namespace to a name

type NetworkConfig

type NetworkConfig struct {
	Driver     string
	DriverOpts map[string]string `mapstructure:"driver_opts"`
	Ipam       IPAMConfig
	External   External
	Internal   bool
	Attachable bool
	Labels     Labels
}

NetworkConfig for a network

type Placement

type Placement struct {
	Constraints []string
	Preferences []PlacementPreferences
}

Placement constraints for the service

type PlacementPreferences

type PlacementPreferences struct {
	Spread string
}

PlacementPreferences is the preferences for a service placement

type PortOpt

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

PortOpt represents a port config in swarm mode.

func (*PortOpt) Set

func (p *PortOpt) Set(value string) error

Set a new port value nolint: gocyclo

func (*PortOpt) String

func (p *PortOpt) String() string

String returns a string repr of this option

func (*PortOpt) Type

func (p *PortOpt) Type() string

Type returns the type of this option

func (*PortOpt) Value

func (p *PortOpt) Value() []swarm.PortConfig

Value returns the ports

type Resource

type Resource struct {
	// TODO: types to convert from units and ratios
	NanoCPUs    string    `mapstructure:"cpus"`
	MemoryBytes UnitBytes `mapstructure:"memory"`
}

Resource is a resource to be limited or reserved

type Resources

type Resources struct {
	Limits       *Resource
	Reservations *Resource
}

Resources the resource limits and reservations

type RestartPolicy

type RestartPolicy struct {
	Condition   string
	Delay       *time.Duration
	MaxAttempts *uint64 `mapstructure:"max_attempts"`
	Window      *time.Duration
}

RestartPolicy the service restart policy

type SecretConfig

type SecretConfig fileObjectConfig

SecretConfig for a secret

type ServiceConfig

type ServiceConfig struct {
	Name string

	Build           BuildConfig
	CapAdd          []string `mapstructure:"cap_add"`
	CapDrop         []string `mapstructure:"cap_drop"`
	CgroupParent    string   `mapstructure:"cgroup_parent"`
	Command         ShellCommand
	Configs         []ServiceConfigObjConfig
	ContainerName   string               `mapstructure:"container_name"`
	CredentialSpec  CredentialSpecConfig `mapstructure:"credential_spec"`
	DependsOn       []string             `mapstructure:"depends_on"`
	Deploy          DeployConfig
	Devices         []string
	DNS             StringList
	DNSSearch       StringList `mapstructure:"dns_search"`
	DomainName      string     `mapstructure:"domainname"`
	Entrypoint      ShellCommand
	Environment     MappingWithEquals
	EnvFile         StringList `mapstructure:"env_file"`
	Expose          StringOrNumberList
	ExternalLinks   []string         `mapstructure:"external_links"`
	ExtraHosts      MappingWithColon `mapstructure:"extra_hosts"`
	Hostname        string
	HealthCheck     *HealthCheckConfig
	Image           string
	Ipc             string
	Labels          Labels
	Links           []string
	Logging         *LoggingConfig
	MacAddress      string `mapstructure:"mac_address"`
	NetworkMode     string `mapstructure:"network_mode"`
	Networks        map[string]*ServiceNetworkConfig
	Pid             string
	Ports           []ServicePortConfig
	Privileged      bool
	ReadOnly        bool `mapstructure:"read_only"`
	Restart         string
	Secrets         []ServiceSecretConfig
	SecurityOpt     []string       `mapstructure:"security_opt"`
	StdinOpen       bool           `mapstructure:"stdin_open"`
	StopGracePeriod *time.Duration `mapstructure:"stop_grace_period"`
	StopSignal      string         `mapstructure:"stop_signal"`
	Tmpfs           StringList
	Tty             bool `mapstructure:"tty"`
	Ulimits         map[string]*UlimitsConfig
	User            string
	Volumes         []ServiceVolumeConfig
	WorkingDir      string `mapstructure:"working_dir"`
}

ServiceConfig is the configuration of one service

func LoadService

func LoadService(name string, serviceDict map[string]interface{}, workingDir string, lookupEnv Mapping) (*ServiceConfig, error)

LoadService produces a single ServiceConfig from a compose file Dict the serviceDict is not validated if directly used. Use Load() to enable validation

func LoadServices

func LoadServices(servicesDict map[string]interface{}, workingDir string, lookupEnv Mapping) ([]ServiceConfig, error)

LoadServices produces a ServiceConfig map from a compose file Dict the servicesDict is not validated if directly used. Use Load() to enable validation

type ServiceConfigObjConfig

type ServiceConfigObjConfig fileReferenceConfig

ServiceConfigObjConfig is the config obj configuration for a service

type ServiceNetworkConfig

type ServiceNetworkConfig struct {
	Aliases     []string
	Ipv4Address string `mapstructure:"ipv4_address"`
	Ipv6Address string `mapstructure:"ipv6_address"`
}

ServiceNetworkConfig is the network configuration for a service

type ServicePortConfig

type ServicePortConfig struct {
	Mode      string
	Target    uint32
	Published uint32
	Protocol  string
}

ServicePortConfig is the port configuration for a service

type ServiceSecretConfig

type ServiceSecretConfig fileReferenceConfig

ServiceSecretConfig is the secret configuration for a service

type ServiceVolumeBind

type ServiceVolumeBind struct {
	Propagation string
}

ServiceVolumeBind are options for a service volume of type bind

type ServiceVolumeConfig

type ServiceVolumeConfig struct {
	Type        string
	Source      string
	Target      string
	ReadOnly    bool `mapstructure:"read_only"`
	Consistency string
	Bind        *ServiceVolumeBind
	Volume      *ServiceVolumeVolume
}

ServiceVolumeConfig are references to a volume used by a service

func ParseVolume

func ParseVolume(spec string) (ServiceVolumeConfig, error)

ParseVolume parses a volume spec without any knowledge of the target platform

type ServiceVolumeVolume

type ServiceVolumeVolume struct {
	NoCopy bool `mapstructure:"nocopy"`
}

ServiceVolumeVolume are options for a service volume of type volume

type ShellCommand

type ShellCommand []string

ShellCommand is a string or list of string args

type StringList

type StringList []string

StringList is a type for fields that can be a string or list of strings

type StringOrNumberList

type StringOrNumberList []string

StringOrNumberList is a type for fields that can be a list of strings or numbers

type UlimitsConfig

type UlimitsConfig struct {
	Single int
	Soft   int
	Hard   int
}

UlimitsConfig the ulimit configuration

type UnitBytes

type UnitBytes int64

UnitBytes is the bytes type

type UpdateConfig

type UpdateConfig struct {
	Parallelism     *uint64
	Delay           time.Duration
	FailureAction   string `mapstructure:"failure_action"`
	Monitor         time.Duration
	MaxFailureRatio float32 `mapstructure:"max_failure_ratio"`
	Order           string
}

UpdateConfig the service update configuration

type VolumeConfig

type VolumeConfig struct {
	Name       string
	Driver     string
	DriverOpts map[string]string `mapstructure:"driver_opts"`
	External   External
	Labels     Labels
}

VolumeConfig for a volume

Jump to

Keyboard shortcuts

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