Documentation
¶
Index ¶
- Constants
- Variables
- func AddStackLabel(namespace Namespace, labels map[string]string) map[string]string
- func Configs(namespace Namespace, configs map[string]ConfigObjConfig) ([]swarm.ConfigSpec, error)
- func ConvertKVStringsToMapWithNil(values []string) map[string]*string
- func ConvertPortToPortConfig(port nat.Port, portBindings map[nat.Port][]nat.PortBinding) ([]swarm.PortConfig, error)
- func GetDeprecatedProperties(configDetails ConfigDetails) map[string]string
- func GetServicesDeclaredNetworks(serviceConfigs []ServiceConfig) map[string]struct{}
- func GetUnsupportedProperties(configDetails ConfigDetails) []string
- func Interpolate(config map[string]interface{}, section string, mapping Mapping) (map[string]interface{}, error)
- func LoadConfigObjs(source map[string]interface{}, workingDir string) (map[string]ConfigObjConfig, error)
- func LoadNetworks(source map[string]interface{}) (map[string]NetworkConfig, error)
- func LoadSecrets(source map[string]interface{}, workingDir string) (map[string]SecretConfig, error)
- func LoadVolumes(source map[string]interface{}) (map[string]VolumeConfig, error)
- func Networks(namespace Namespace, networks networkMap, servicesNetworks map[string]struct{}) (map[string]types.NetworkCreate, []string)
- func ParseCPUs(value string) (int64, error)
- func ParseConfigs(client client.ConfigAPIClient, requestedConfigs []*swarm.ConfigReference) ([]*swarm.ConfigReference, error)
- func ParseEnvFile(filename string) ([]string, error)
- func ParseRestartPolicy(policy string) (container.RestartPolicy, error)
- func ParseSecrets(client *client.Client, requestedSecrets []*swarm.SecretReference) ([]*swarm.SecretReference, error)
- func ParseYAML(source []byte) (map[string]interface{}, error)
- func Secrets(namespace Namespace, secrets map[string]SecretConfig) ([]swarm.SecretSpec, error)
- func Service(apiVersion string, namespace Namespace, service ServiceConfig, ...) (swarm.ServiceSpec, error)
- func Services(namespace Namespace, config *Config, client *client.Client) (map[string]swarm.ServiceSpec, error)
- func Substitute(template string, mapping Mapping) (string, error)
- func Volumes(serviceVolumes []ServiceVolumeConfig, stackVolumes volumes, ...) ([]mount.Mount, error)
- type BuildConfig
- type Config
- type ConfigDetails
- type ConfigFile
- type ConfigObjConfig
- type CredentialSpecConfig
- type DeployConfig
- type ErrBadEnvVariable
- type External
- type ForbiddenPropertiesError
- type HealthCheckConfig
- type HealthCheckTest
- type IPAMConfig
- type IPAMPool
- type InvalidTemplateError
- type Labels
- type LoggingConfig
- type Mapping
- type MappingWithColon
- type MappingWithEquals
- type Namespace
- type NetworkConfig
- type Placement
- type PlacementPreferences
- type PortOpt
- type Resource
- type Resources
- type RestartPolicy
- type SecretConfig
- type ServiceConfig
- type ServiceConfigObjConfig
- type ServiceNetworkConfig
- type ServicePortConfig
- type ServiceSecretConfig
- type ServiceVolumeBind
- type ServiceVolumeConfig
- type ServiceVolumeVolume
- type ShellCommand
- type StringList
- type StringOrNumberList
- type UlimitsConfig
- type UnitBytes
- type UpdateConfig
- type VolumeConfig
Constants ¶
const (
// LabelImage is the label used to store image name provided in the compose file
LabelImage = "com.docker.stack.image"
)
const (
// LabelNamespace is the label used to track stack resources
LabelNamespace = "com.docker.stack.namespace"
)
Variables ¶
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.
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.
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 ¶
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 ¶
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 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 ¶
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 ¶
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 ¶
Substitute variables in the string with their values
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
type ConfigDetails ¶
type ConfigDetails struct {
WorkingDir string
ConfigFiles []ConfigFile
Environment map[string]string
}
ConfigDetails are the details about a group of ConfigFiles
type ConfigFile ¶
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 ¶
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 ¶
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 ¶
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 ¶
IPAMConfig 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 LoggingConfig ¶
LoggingConfig the logging configuration for a service
type Mapping ¶
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 ¶
MappingWithColon is a mapping type that can be converted from a list of 'key: value' strings
type MappingWithEquals ¶
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 ¶
NewNamespace returns a new Namespace for scoping of names
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.
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 RestartPolicy ¶
type RestartPolicy struct {
Condition string
Delay *time.Duration
MaxAttempts *uint64 `mapstructure:"max_attempts"`
Window *time.Duration
}
RestartPolicy the service restart policy
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 ¶
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 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 ¶
UlimitsConfig the ulimit configuration