up.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. )
  22. func (b *ecsAPIService) Up(ctx context.Context, project *types.Project, detach bool) error {
  23. err := b.SDK.CheckRequirements(ctx, b.Region)
  24. if err != nil {
  25. return err
  26. }
  27. template, err := b.Convert(ctx, project)
  28. if err != nil {
  29. return err
  30. }
  31. update, err := b.SDK.StackExists(ctx, project.Name)
  32. if err != nil {
  33. return err
  34. }
  35. operation := stackCreate
  36. if update {
  37. operation = stackUpdate
  38. changeset, err := b.SDK.CreateChangeSet(ctx, project.Name, template)
  39. if err != nil {
  40. return err
  41. }
  42. err = b.SDK.UpdateStack(ctx, changeset)
  43. if err != nil {
  44. return err
  45. }
  46. } else {
  47. err = b.SDK.CreateStack(ctx, project.Name, template)
  48. if err != nil {
  49. return err
  50. }
  51. }
  52. if detach {
  53. return nil
  54. }
  55. signalChan := make(chan os.Signal, 1)
  56. signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
  57. go func() {
  58. <-signalChan
  59. fmt.Println("user interrupted deployment. Deleting stack...")
  60. b.Down(ctx, project.Name) // nolint:errcheck
  61. }()
  62. err = b.WaitStackCompletion(ctx, project.Name, operation)
  63. return err
  64. }