types.go 8.5 KB

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