up.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package amazon
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/awslabs/goformation/v4/cloudformation"
  6. "github.com/docker/ecs-plugin/pkg/compose"
  7. )
  8. func (c *client) ComposeUp(ctx context.Context, project *compose.Project) error {
  9. ok, err := c.api.ClusterExists(ctx, c.Cluster)
  10. if err != nil {
  11. return err
  12. }
  13. if !ok {
  14. c.api.CreateCluster(ctx, c.Cluster)
  15. }
  16. update, err := c.api.StackExists(ctx, project.Name)
  17. if err != nil {
  18. return err
  19. }
  20. if update {
  21. return fmt.Errorf("we do not (yet) support updating an existing CloudFormation stack")
  22. }
  23. template, err := c.Convert(ctx, project)
  24. if err != nil {
  25. return err
  26. }
  27. err = c.api.CreateStack(ctx, project.Name, template)
  28. if err != nil {
  29. return err
  30. }
  31. return c.WaitStackCompletion(ctx, project.Name, StackCreate)
  32. }
  33. type upAPI interface {
  34. waitAPI
  35. ClusterExists(ctx context.Context, name string) (bool, error)
  36. CreateCluster(ctx context.Context, name string) (string, error)
  37. StackExists(ctx context.Context, name string) (bool, error)
  38. CreateStack(ctx context.Context, name string, template *cloudformation.Template) error
  39. }