types.go 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. // ConfigFile is a filename and the contents of the file as a Dict
  49. type ConfigFile struct {
  50. Filename string
  51. Config map[string]interface{}
  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. Secrets map[string]SecretConfig
  65. }
  66. // ServiceConfig is the configuration of one service
  67. type ServiceConfig struct {
  68. Name string
  69. CapAdd []string `mapstructure:"cap_add"`
  70. CapDrop []string `mapstructure:"cap_drop"`
  71. CgroupParent string `mapstructure:"cgroup_parent"`
  72. Command ShellCommand
  73. ContainerName string `mapstructure:"container_name"`
  74. DependsOn []string `mapstructure:"depends_on"`
  75. Deploy DeployConfig
  76. Devices []string
  77. DNS StringList
  78. DNSSearch StringList `mapstructure:"dns_search"`
  79. DomainName string `mapstructure:"domainname"`
  80. Entrypoint ShellCommand
  81. Environment MappingWithEquals
  82. EnvFile StringList `mapstructure:"env_file"`
  83. Expose StringOrNumberList
  84. ExternalLinks []string `mapstructure:"external_links"`
  85. ExtraHosts MappingWithColon `mapstructure:"extra_hosts"`
  86. Hostname string
  87. HealthCheck *HealthCheckConfig
  88. Image string
  89. Ipc string
  90. Labels Labels
  91. Links []string
  92. Logging *LoggingConfig
  93. MacAddress string `mapstructure:"mac_address"`
  94. NetworkMode string `mapstructure:"network_mode"`
  95. Networks map[string]*ServiceNetworkConfig
  96. Pid string
  97. Ports []ServicePortConfig
  98. Privileged bool
  99. ReadOnly bool `mapstructure:"read_only"`
  100. Restart string
  101. Secrets []ServiceSecretConfig
  102. SecurityOpt []string `mapstructure:"security_opt"`
  103. StdinOpen bool `mapstructure:"stdin_open"`
  104. StopGracePeriod *time.Duration `mapstructure:"stop_grace_period"`
  105. StopSignal string `mapstructure:"stop_signal"`
  106. Tmpfs StringList
  107. Tty bool `mapstructure:"tty"`
  108. Ulimits map[string]*UlimitsConfig
  109. User string
  110. Volumes []ServiceVolumeConfig
  111. WorkingDir string `mapstructure:"working_dir"`
  112. }
  113. // ShellCommand is a string or list of string args
  114. type ShellCommand []string
  115. // StringList is a type for fields that can be a string or list of strings
  116. type StringList []string
  117. // StringOrNumberList is a type for fields that can be a list of strings or
  118. // numbers
  119. type StringOrNumberList []string
  120. // MappingWithEquals is a mapping type that can be converted from a list of
  121. // key[=value] strings.
  122. // For the key with an empty value (`key=`), the mapped value is set to a pointer to `""`.
  123. // For the key without value (`key`), the mapped value is set to nil.
  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 `mapstructure:"endpoint_mode"`
  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. StartPeriod string
  153. Disable bool
  154. }
  155. // HealthCheckTest is the command run to test the health of a service
  156. type HealthCheckTest []string
  157. // UpdateConfig the service update configuration
  158. type UpdateConfig struct {
  159. Parallelism *uint64
  160. Delay time.Duration
  161. FailureAction string `mapstructure:"failure_action"`
  162. Monitor time.Duration
  163. MaxFailureRatio float32 `mapstructure:"max_failure_ratio"`
  164. }
  165. // Resources the resource limits and reservations
  166. type Resources struct {
  167. Limits *Resource
  168. Reservations *Resource
  169. }
  170. // Resource is a resource to be limited or reserved
  171. type Resource struct {
  172. // TODO: types to convert from units and ratios
  173. NanoCPUs string `mapstructure:"cpus"`
  174. MemoryBytes UnitBytes `mapstructure:"memory"`
  175. }
  176. // UnitBytes is the bytes type
  177. type UnitBytes int64
  178. // RestartPolicy the service restart policy
  179. type RestartPolicy struct {
  180. Condition string
  181. Delay *time.Duration
  182. MaxAttempts *uint64 `mapstructure:"max_attempts"`
  183. Window *time.Duration
  184. }
  185. // Placement constraints for the service
  186. type Placement struct {
  187. Constraints []string
  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. // ServicePortConfig is the port configuration for a service
  196. type ServicePortConfig struct {
  197. Mode string
  198. Target uint32
  199. Published uint32
  200. Protocol string
  201. }
  202. // ServiceVolumeConfig are references to a volume used by a service
  203. type ServiceVolumeConfig struct {
  204. Type string
  205. Source string
  206. Target string
  207. ReadOnly bool `mapstructure:"read_only"`
  208. Consistency string
  209. Bind *ServiceVolumeBind
  210. Volume *ServiceVolumeVolume
  211. }
  212. // ServiceVolumeBind are options for a service volume of type bind
  213. type ServiceVolumeBind struct {
  214. Propagation string
  215. }
  216. // ServiceVolumeVolume are options for a service volume of type volume
  217. type ServiceVolumeVolume struct {
  218. NoCopy bool `mapstructure:"nocopy"`
  219. }
  220. // ServiceSecretConfig is the secret configuration for a service
  221. type ServiceSecretConfig struct {
  222. Source string
  223. Target string
  224. UID string
  225. GID string
  226. Mode *uint32
  227. }
  228. // UlimitsConfig the ulimit configuration
  229. type UlimitsConfig struct {
  230. Single int
  231. Soft int
  232. Hard int
  233. }
  234. // NetworkConfig for a network
  235. type NetworkConfig struct {
  236. Driver string
  237. DriverOpts map[string]string `mapstructure:"driver_opts"`
  238. Ipam IPAMConfig
  239. External External
  240. Internal bool
  241. Attachable bool
  242. Labels Labels
  243. }
  244. // IPAMConfig for a network
  245. type IPAMConfig struct {
  246. Driver string
  247. Config []*IPAMPool
  248. }
  249. // IPAMPool for a network
  250. type IPAMPool struct {
  251. Subnet string
  252. }
  253. // VolumeConfig for a volume
  254. type VolumeConfig struct {
  255. Driver string
  256. DriverOpts map[string]string `mapstructure:"driver_opts"`
  257. External External
  258. Labels Labels
  259. }
  260. // External identifies a Volume or Network as a reference to a resource that is
  261. // not managed, and should already exist.
  262. type External struct {
  263. Name string
  264. External bool
  265. }
  266. // SecretConfig for a secret
  267. type SecretConfig struct {
  268. File string
  269. External External
  270. Labels Labels
  271. }