types.go 7.2 KB

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