types.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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 MappingWithEquals
  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 []string
  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. // MappingWithColon is a mapping type that can be converted from alist of
  126. // 'key: value' strings
  127. type MappingWithColon map[string]string
  128. // LoggingConfig the logging configuration for a service
  129. type LoggingConfig struct {
  130. Driver string
  131. Options map[string]string
  132. }
  133. // DeployConfig the deployment configuration for a service
  134. type DeployConfig struct {
  135. Mode string
  136. Replicas *uint64
  137. Labels MappingWithEquals
  138. UpdateConfig *UpdateConfig `mapstructure:"update_config"`
  139. Resources Resources
  140. RestartPolicy *RestartPolicy `mapstructure:"restart_policy"`
  141. Placement Placement
  142. }
  143. // HealthCheckConfig the healthcheck configuration for a service
  144. type HealthCheckConfig struct {
  145. Test HealthCheckTest
  146. Timeout string
  147. Interval string
  148. Retries *uint64
  149. Disable bool
  150. }
  151. // HealthCheckTest is the command run to test the health of a service
  152. type HealthCheckTest []string
  153. // UpdateConfig the service update configuration
  154. type UpdateConfig struct {
  155. Parallelism *uint64
  156. Delay time.Duration
  157. FailureAction string `mapstructure:"failure_action"`
  158. Monitor time.Duration
  159. MaxFailureRatio float32 `mapstructure:"max_failure_ratio"`
  160. }
  161. // Resources the resource limits and reservations
  162. type Resources struct {
  163. Limits *Resource
  164. Reservations *Resource
  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. // UnitBytes is the bytes type
  173. type UnitBytes int64
  174. // RestartPolicy the service restart policy
  175. type RestartPolicy struct {
  176. Condition string
  177. Delay *time.Duration
  178. MaxAttempts *uint64 `mapstructure:"max_attempts"`
  179. Window *time.Duration
  180. }
  181. // Placement constraints for the service
  182. type Placement struct {
  183. Constraints []string
  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. // ServicePortConfig is the port configuration for a service
  192. type ServicePortConfig struct {
  193. Mode string
  194. Target uint32
  195. Published uint32
  196. Protocol string
  197. }
  198. // ServiceSecretConfig is the secret configuration for a service
  199. type ServiceSecretConfig struct {
  200. Source string
  201. Target string
  202. UID string
  203. GID string
  204. Mode uint32
  205. }
  206. // UlimitsConfig the ulimit configuration
  207. type UlimitsConfig struct {
  208. Single int
  209. Soft int
  210. Hard int
  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. Attachable bool
  220. Labels MappingWithEquals
  221. }
  222. // IPAMConfig for a network
  223. type IPAMConfig struct {
  224. Driver string
  225. Config []*IPAMPool
  226. }
  227. // IPAMPool for a network
  228. type IPAMPool struct {
  229. Subnet string
  230. }
  231. // VolumeConfig for a volume
  232. type VolumeConfig struct {
  233. Driver string
  234. DriverOpts map[string]string `mapstructure:"driver_opts"`
  235. External External
  236. Labels MappingWithEquals
  237. }
  238. // External identifies a Volume or Network as a reference to a resource that is
  239. // not managed, and should already exist.
  240. type External struct {
  241. Name string
  242. External bool
  243. }
  244. // SecretConfig for a secret
  245. type SecretConfig struct {
  246. File string
  247. External External
  248. Labels MappingWithEquals
  249. }