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