up.go 2.6 KB

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