up.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. Copyright 2020 Docker Compose CLI authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package ecs
  14. import (
  15. "context"
  16. "fmt"
  17. "os"
  18. "os/signal"
  19. "syscall"
  20. "github.com/compose-spec/compose-go/types"
  21. "github.com/docker/compose-cli/errdefs"
  22. )
  23. func (b *ecsAPIService) Build(ctx context.Context, project *types.Project) error {
  24. return errdefs.ErrNotImplemented
  25. }
  26. func (b *ecsAPIService) Push(ctx context.Context, project *types.Project) error {
  27. return errdefs.ErrNotImplemented
  28. }
  29. func (b *ecsAPIService) Up(ctx context.Context, project *types.Project, detach bool) error {
  30. err := b.aws.CheckRequirements(ctx, b.Region)
  31. if err != nil {
  32. return err
  33. }
  34. template, err := b.Convert(ctx, project, "yaml")
  35. if err != nil {
  36. return err
  37. }
  38. update, err := b.aws.StackExists(ctx, project.Name)
  39. if err != nil {
  40. return err
  41. }
  42. operation := stackCreate
  43. if update {
  44. operation = stackUpdate
  45. changeset, err := b.aws.CreateChangeSet(ctx, project.Name, b.Region, template)
  46. if err != nil {
  47. return err
  48. }
  49. err = b.aws.UpdateStack(ctx, changeset)
  50. if err != nil {
  51. return err
  52. }
  53. } else {
  54. err = b.aws.CreateStack(ctx, project.Name, b.Region, template)
  55. if err != nil {
  56. return err
  57. }
  58. }
  59. if detach {
  60. return nil
  61. }
  62. signalChan := make(chan os.Signal, 1)
  63. signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
  64. go func() {
  65. <-signalChan
  66. fmt.Println("user interrupted deployment. Deleting stack...")
  67. b.Down(ctx, project.Name) // nolint:errcheck
  68. }()
  69. err = b.WaitStackCompletion(ctx, project.Name, operation)
  70. return err
  71. }