compatibility.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package backend
  2. import (
  3. "github.com/compose-spec/compose-go/compatibility"
  4. "github.com/compose-spec/compose-go/types"
  5. )
  6. type FargateCompatibilityChecker struct {
  7. compatibility.AllowList
  8. }
  9. var compatibleComposeAttributes = []string{
  10. "services.command",
  11. "services.container_name",
  12. "services.cap_drop",
  13. "services.depends_on",
  14. "services.deploy",
  15. "services.deploy.replicas",
  16. "services.deploy.resources.limits",
  17. "services.deploy.resources.limits.cpus",
  18. "services.deploy.resources.limits.memory",
  19. "services.deploy.resources.reservations",
  20. "services.deploy.resources.reservations.cpus",
  21. "services.deploy.resources.reservations.memory",
  22. "services.deploy.update_config",
  23. "services.deploy.update_config.parallelism",
  24. "services.entrypoint",
  25. "services.environment",
  26. "services.env_file",
  27. "services.healthcheck",
  28. "services.healthcheck.interval",
  29. "services.healthcheck.retries",
  30. "services.healthcheck.start_period",
  31. "services.healthcheck.test",
  32. "services.healthcheck.timeout",
  33. "services.image",
  34. "services.init",
  35. "services.logging",
  36. "services.logging.options",
  37. "services.networks",
  38. "services.ports",
  39. "services.ports.mode",
  40. "services.ports.target",
  41. "services.ports.protocol",
  42. "services.secrets",
  43. "services.secrets.source",
  44. "services.secrets.target",
  45. "services.user",
  46. "services.working_dir",
  47. "secrets.external",
  48. "secrets.name",
  49. "secrets.file",
  50. }
  51. func (c *FargateCompatibilityChecker) CheckImage(service *types.ServiceConfig) {
  52. if service.Image == "" {
  53. c.Incompatible("service %s doesn't define a Docker image to run", service.Name)
  54. }
  55. }
  56. func (c *FargateCompatibilityChecker) CheckPortsPublished(p *types.ServicePortConfig) {
  57. if p.Published == 0 {
  58. p.Published = p.Target
  59. }
  60. if p.Published != p.Target {
  61. c.Incompatible("published port can't be set to a distinct value than container port")
  62. }
  63. }
  64. func (c *FargateCompatibilityChecker) CheckCapAdd(service *types.ServiceConfig) {
  65. add := []string{}
  66. for _, cap := range service.CapAdd {
  67. switch cap {
  68. case "SYS_PTRACE":
  69. add = append(add, cap)
  70. default:
  71. c.Incompatible("ECS doesn't allow to add capability %s", cap)
  72. }
  73. }
  74. service.CapAdd = add
  75. }
  76. func (c *FargateCompatibilityChecker) CheckLoggingDriver(config *types.LoggingConfig) {
  77. if config.Driver != "" && config.Driver != "awslogs" {
  78. c.Unsupported("services.logging.driver %s is not supported", config.Driver)
  79. }
  80. }