compatibility.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. Copyright 2020 Docker, Inc.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package ecs
  14. import (
  15. "github.com/compose-spec/compose-go/compatibility"
  16. "github.com/compose-spec/compose-go/types"
  17. )
  18. type fargateCompatibilityChecker struct {
  19. compatibility.AllowList
  20. }
  21. var compatibleComposeAttributes = []string{
  22. "services.command",
  23. "services.container_name",
  24. "services.cap_drop",
  25. "services.depends_on",
  26. "services.deploy",
  27. "services.deploy.replicas",
  28. "services.deploy.resources.limits",
  29. "services.deploy.resources.limits.cpus",
  30. "services.deploy.resources.limits.memory",
  31. "services.deploy.resources.reservations",
  32. "services.deploy.resources.reservations.cpus",
  33. "services.deploy.resources.reservations.memory",
  34. "services.deploy.update_config",
  35. "services.deploy.update_config.parallelism",
  36. "services.entrypoint",
  37. "services.environment",
  38. "services.env_file",
  39. "services.healthcheck",
  40. "services.healthcheck.interval",
  41. "services.healthcheck.retries",
  42. "services.healthcheck.start_period",
  43. "services.healthcheck.test",
  44. "services.healthcheck.timeout",
  45. "services.image",
  46. "services.init",
  47. "services.logging",
  48. "services.logging.options",
  49. "services.networks",
  50. "services.ports",
  51. "services.ports.mode",
  52. "services.ports.target",
  53. "services.ports.protocol",
  54. "services.secrets",
  55. "services.secrets.source",
  56. "services.secrets.target",
  57. "services.user",
  58. "services.volumes",
  59. "services.volumes.read_only",
  60. "services.volumes.source",
  61. "services.volumes.target",
  62. "services.working_dir",
  63. "secrets.external",
  64. "secrets.name",
  65. "secrets.file",
  66. "volumes",
  67. "volumes.external",
  68. }
  69. func (c *fargateCompatibilityChecker) CheckImage(service *types.ServiceConfig) {
  70. if service.Image == "" {
  71. c.Incompatible("service %s doesn't define a Docker image to run", service.Name)
  72. }
  73. }
  74. func (c *fargateCompatibilityChecker) CheckPortsPublished(p *types.ServicePortConfig) {
  75. if p.Published == 0 {
  76. p.Published = p.Target
  77. }
  78. if p.Published != p.Target {
  79. c.Incompatible("published port can't be set to a distinct value than container port")
  80. }
  81. }
  82. func (c *fargateCompatibilityChecker) CheckCapAdd(service *types.ServiceConfig) {
  83. add := []string{}
  84. for _, cap := range service.CapAdd {
  85. switch cap {
  86. case "SYS_PTRACE":
  87. add = append(add, cap)
  88. default:
  89. c.Incompatible("ECS doesn't allow to add capability %s", cap)
  90. }
  91. }
  92. service.CapAdd = add
  93. }
  94. func (c *fargateCompatibilityChecker) CheckLoggingDriver(config *types.LoggingConfig) {
  95. if config.Driver != "" && config.Driver != "awslogs" {
  96. c.Unsupported("services.logging.driver %s is not supported", config.Driver)
  97. }
  98. }
  99. func (c *fargateCompatibilityChecker) CheckVolumeConfigExternal(config *types.VolumeConfig) {
  100. if !config.External.External {
  101. c.Unsupported("non-external volumes are not supported")
  102. }
  103. }