validate.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package amazon
  2. import (
  3. "fmt"
  4. "github.com/compose-spec/compose-go/types"
  5. "github.com/docker/ecs-plugin/pkg/compose"
  6. )
  7. // Validate check the compose model do not use unsupported features and inject sane defaults for ECS deployment
  8. func Validate(project *compose.Project) error {
  9. if len(project.Networks) == 0 {
  10. // Compose application model implies a default network if none is explicitly set.
  11. // FIXME move this to compose-go
  12. project.Networks["default"] = types.NetworkConfig{
  13. Name: "default",
  14. }
  15. }
  16. for i, service := range project.Services {
  17. if len(service.Networks) == 0 {
  18. // Service without explicit network attachment are implicitly exposed on default network
  19. // FIXME move this to compose-go
  20. service.Networks = map[string]*types.ServiceNetworkConfig{"default": nil}
  21. project.Services[i] = service
  22. }
  23. if service.NetworkMode != "" && service.NetworkMode != "awsvpc" {
  24. return fmt.Errorf("ECS do not support NetworkMode %q", service.NetworkMode)
  25. }
  26. }
  27. // Here we can check for incompatible attributes, inject sane defaults, etc
  28. return nil
  29. }