compatibility.go 1.5 KB

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