up.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. "io"
  18. "os"
  19. "os/signal"
  20. "syscall"
  21. "github.com/compose-spec/compose-go/types"
  22. "github.com/docker/compose-cli/errdefs"
  23. )
  24. func (b *ecsAPIService) Build(ctx context.Context, project *types.Project) error {
  25. return errdefs.ErrNotImplemented
  26. }
  27. func (b *ecsAPIService) Push(ctx context.Context, project *types.Project) error {
  28. return errdefs.ErrNotImplemented
  29. }
  30. func (b *ecsAPIService) Pull(ctx context.Context, project *types.Project) error {
  31. return errdefs.ErrNotImplemented
  32. }
  33. func (b *ecsAPIService) Create(ctx context.Context, project *types.Project) error {
  34. return errdefs.ErrNotImplemented
  35. }
  36. func (b *ecsAPIService) Start(ctx context.Context, project *types.Project, w io.Writer) error {
  37. return errdefs.ErrNotImplemented
  38. }
  39. func (b *ecsAPIService) Up(ctx context.Context, project *types.Project, detach bool) error {
  40. err := b.aws.CheckRequirements(ctx, b.Region)
  41. if err != nil {
  42. return err
  43. }
  44. template, err := b.Convert(ctx, project, "yaml")
  45. if err != nil {
  46. return err
  47. }
  48. update, err := b.aws.StackExists(ctx, project.Name)
  49. if err != nil {
  50. return err
  51. }
  52. operation := stackCreate
  53. if update {
  54. operation = stackUpdate
  55. changeset, err := b.aws.CreateChangeSet(ctx, project.Name, b.Region, template)
  56. if err != nil {
  57. return err
  58. }
  59. err = b.aws.UpdateStack(ctx, changeset)
  60. if err != nil {
  61. return err
  62. }
  63. } else {
  64. err = b.aws.CreateStack(ctx, project.Name, b.Region, template)
  65. if err != nil {
  66. return err
  67. }
  68. }
  69. if detach {
  70. return nil
  71. }
  72. signalChan := make(chan os.Signal, 1)
  73. signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
  74. go func() {
  75. <-signalChan
  76. fmt.Println("user interrupted deployment. Deleting stack...")
  77. b.Down(ctx, project.Name) // nolint:errcheck
  78. }()
  79. err = b.WaitStackCompletion(ctx, project.Name, operation)
  80. return err
  81. }