github.com/flavio/docker@v0.1.3-0.20170117145210-f63d1a6eec47/cli/compose/types/types.go (about)

     1  package types
     2  
     3  import (
     4  	"time"
     5  )
     6  
     7  // UnsupportedProperties not yet supported by this implementation of the compose file
     8  var UnsupportedProperties = []string{
     9  	"build",
    10  	"cap_add",
    11  	"cap_drop",
    12  	"cgroup_parent",
    13  	"devices",
    14  	"dns",
    15  	"dns_search",
    16  	"domainname",
    17  	"external_links",
    18  	"ipc",
    19  	"links",
    20  	"mac_address",
    21  	"network_mode",
    22  	"privileged",
    23  	"read_only",
    24  	"restart",
    25  	"security_opt",
    26  	"shm_size",
    27  	"stop_signal",
    28  	"tmpfs",
    29  }
    30  
    31  // DeprecatedProperties that were removed from the v3 format, but their
    32  // use should not impact the behaviour of the application.
    33  var DeprecatedProperties = map[string]string{
    34  	"container_name": "Setting the container name is not supported.",
    35  	"expose":         "Exposing ports is unnecessary - services on the same network can access each other's containers on any port.",
    36  }
    37  
    38  // ForbiddenProperties that are not supported in this implementation of the
    39  // compose file.
    40  var ForbiddenProperties = map[string]string{
    41  	"extends":       "Support for `extends` is not implemented yet.",
    42  	"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.",
    43  	"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.",
    44  	"cpu_quota":     "Set resource limits using deploy.resources",
    45  	"cpu_shares":    "Set resource limits using deploy.resources",
    46  	"cpuset":        "Set resource limits using deploy.resources",
    47  	"mem_limit":     "Set resource limits using deploy.resources",
    48  	"memswap_limit": "Set resource limits using deploy.resources",
    49  }
    50  
    51  // Dict is a mapping of strings to interface{}
    52  type Dict map[string]interface{}
    53  
    54  // ConfigFile is a filename and the contents of the file as a Dict
    55  type ConfigFile struct {
    56  	Filename string
    57  	Config   Dict
    58  }
    59  
    60  // ConfigDetails are the details about a group of ConfigFiles
    61  type ConfigDetails struct {
    62  	WorkingDir  string
    63  	ConfigFiles []ConfigFile
    64  	Environment map[string]string
    65  }
    66  
    67  // Config is a full compose file configuration
    68  type Config struct {
    69  	Services []ServiceConfig
    70  	Networks map[string]NetworkConfig
    71  	Volumes  map[string]VolumeConfig
    72  }
    73  
    74  // ServiceConfig is the configuration of one service
    75  type ServiceConfig struct {
    76  	Name string
    77  
    78  	CapAdd          []string `mapstructure:"cap_add"`
    79  	CapDrop         []string `mapstructure:"cap_drop"`
    80  	CgroupParent    string   `mapstructure:"cgroup_parent"`
    81  	Command         []string `compose:"shell_command"`
    82  	ContainerName   string   `mapstructure:"container_name"`
    83  	DependsOn       []string `mapstructure:"depends_on"`
    84  	Deploy          DeployConfig
    85  	Devices         []string
    86  	DNS             []string          `compose:"string_or_list"`
    87  	DNSSearch       []string          `mapstructure:"dns_search" compose:"string_or_list"`
    88  	DomainName      string            `mapstructure:"domainname"`
    89  	Entrypoint      []string          `compose:"shell_command"`
    90  	Environment     map[string]string `compose:"list_or_dict_equals"`
    91  	Expose          []string          `compose:"list_of_strings_or_numbers"`
    92  	ExternalLinks   []string          `mapstructure:"external_links"`
    93  	ExtraHosts      map[string]string `mapstructure:"extra_hosts" compose:"list_or_dict_colon"`
    94  	Hostname        string
    95  	HealthCheck     *HealthCheckConfig
    96  	Image           string
    97  	Ipc             string
    98  	Labels          map[string]string `compose:"list_or_dict_equals"`
    99  	Links           []string
   100  	Logging         *LoggingConfig
   101  	MacAddress      string                           `mapstructure:"mac_address"`
   102  	NetworkMode     string                           `mapstructure:"network_mode"`
   103  	Networks        map[string]*ServiceNetworkConfig `compose:"list_or_struct_map"`
   104  	Pid             string
   105  	Ports           []string `compose:"list_of_strings_or_numbers"`
   106  	Privileged      bool
   107  	ReadOnly        bool `mapstructure:"read_only"`
   108  	Restart         string
   109  	SecurityOpt     []string       `mapstructure:"security_opt"`
   110  	StdinOpen       bool           `mapstructure:"stdin_open"`
   111  	StopGracePeriod *time.Duration `mapstructure:"stop_grace_period"`
   112  	StopSignal      string         `mapstructure:"stop_signal"`
   113  	Tmpfs           []string       `compose:"string_or_list"`
   114  	Tty             bool           `mapstructure:"tty"`
   115  	Ulimits         map[string]*UlimitsConfig
   116  	User            string
   117  	Volumes         []string
   118  	WorkingDir      string `mapstructure:"working_dir"`
   119  }
   120  
   121  // LoggingConfig the logging configuration for a service
   122  type LoggingConfig struct {
   123  	Driver  string
   124  	Options map[string]string
   125  }
   126  
   127  // DeployConfig the deployment configuration for a service
   128  type DeployConfig struct {
   129  	Mode          string
   130  	Replicas      *uint64
   131  	Labels        map[string]string `compose:"list_or_dict_equals"`
   132  	UpdateConfig  *UpdateConfig     `mapstructure:"update_config"`
   133  	Resources     Resources
   134  	RestartPolicy *RestartPolicy `mapstructure:"restart_policy"`
   135  	Placement     Placement
   136  }
   137  
   138  // HealthCheckConfig the healthcheck configuration for a service
   139  type HealthCheckConfig struct {
   140  	Test     []string `compose:"healthcheck"`
   141  	Timeout  string
   142  	Interval string
   143  	Retries  *uint64
   144  	Disable  bool
   145  }
   146  
   147  // UpdateConfig the service update configuration
   148  type UpdateConfig struct {
   149  	Parallelism     *uint64
   150  	Delay           time.Duration
   151  	FailureAction   string `mapstructure:"failure_action"`
   152  	Monitor         time.Duration
   153  	MaxFailureRatio float32 `mapstructure:"max_failure_ratio"`
   154  }
   155  
   156  // Resources the resource limits and reservations
   157  type Resources struct {
   158  	Limits       *Resource
   159  	Reservations *Resource
   160  }
   161  
   162  // Resource is a resource to be limited or reserved
   163  type Resource struct {
   164  	// TODO: types to convert from units and ratios
   165  	NanoCPUs    string    `mapstructure:"cpus"`
   166  	MemoryBytes UnitBytes `mapstructure:"memory"`
   167  }
   168  
   169  // UnitBytes is the bytes type
   170  type UnitBytes int64
   171  
   172  // RestartPolicy the service restart policy
   173  type RestartPolicy struct {
   174  	Condition   string
   175  	Delay       *time.Duration
   176  	MaxAttempts *uint64 `mapstructure:"max_attempts"`
   177  	Window      *time.Duration
   178  }
   179  
   180  // Placement constraints for the service
   181  type Placement struct {
   182  	Constraints []string
   183  }
   184  
   185  // ServiceNetworkConfig is the network configuration for a service
   186  type ServiceNetworkConfig struct {
   187  	Aliases     []string
   188  	Ipv4Address string `mapstructure:"ipv4_address"`
   189  	Ipv6Address string `mapstructure:"ipv6_address"`
   190  }
   191  
   192  // UlimitsConfig the ulimit configuration
   193  type UlimitsConfig struct {
   194  	Single int
   195  	Soft   int
   196  	Hard   int
   197  }
   198  
   199  // NetworkConfig for a network
   200  type NetworkConfig struct {
   201  	Driver     string
   202  	DriverOpts map[string]string `mapstructure:"driver_opts"`
   203  	Ipam       IPAMConfig
   204  	External   External
   205  	Labels     map[string]string `compose:"list_or_dict_equals"`
   206  }
   207  
   208  // IPAMConfig for a network
   209  type IPAMConfig struct {
   210  	Driver string
   211  	Config []*IPAMPool
   212  }
   213  
   214  // IPAMPool for a network
   215  type IPAMPool struct {
   216  	Subnet string
   217  }
   218  
   219  // VolumeConfig for a volume
   220  type VolumeConfig struct {
   221  	Driver     string
   222  	DriverOpts map[string]string `mapstructure:"driver_opts"`
   223  	External   External
   224  	Labels     map[string]string `compose:"list_or_dict_equals"`
   225  }
   226  
   227  // External identifies a Volume or Network as a reference to a resource that is
   228  // not managed, and should already exist.
   229  type External struct {
   230  	Name     string
   231  	External bool
   232  }