compatibility.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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.entrypoint",
  23. "services.environment",
  24. "service.image",
  25. "services.init",
  26. "services.healthcheck",
  27. "services.healthcheck.interval",
  28. "services.healthcheck.start_period",
  29. "services.healthcheck.test",
  30. "services.healthcheck.timeout",
  31. "services.networks",
  32. "services.ports",
  33. "services.ports.mode",
  34. "services.ports.target",
  35. "services.ports.protocol",
  36. "services.user",
  37. "services.working_dir",
  38. }
  39. func (c *FargateCompatibilityChecker) CheckImage(service *types.ServiceConfig) {
  40. if service.Image == "" {
  41. c.Incompatible("service %s doesn't define a Docker image to run", service.Name)
  42. }
  43. }
  44. func (c *FargateCompatibilityChecker) CheckPortsPublished(p *types.ServicePortConfig) {
  45. if p.Published == 0 {
  46. p.Published = p.Target
  47. }
  48. if p.Published != p.Target {
  49. c.Incompatible("published port can't be set to a distinct value than container port")
  50. }
  51. }
  52. func (c *FargateCompatibilityChecker) CheckCapAdd(service *types.ServiceConfig) {
  53. add := []string{}
  54. for _, cap := range service.CapAdd {
  55. switch cap {
  56. case "SYS_PTRACE":
  57. add = append(add, cap)
  58. default:
  59. c.Incompatible("ECS doesn't allow to add capability %s", cap)
  60. }
  61. }
  62. service.CapAdd = add
  63. }