2020-08-18 11:38:23 +02:00
|
|
|
/*
|
2020-09-22 12:13:00 +02:00
|
|
|
Copyright 2020 Docker Compose CLI authors
|
2020-08-18 11:38:23 +02:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-08-17 17:48:52 +02:00
|
|
|
package ecs
|
2020-06-11 19:22:12 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2020-07-27 16:23:46 +02:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
2020-06-11 19:22:12 +02:00
|
|
|
|
2020-06-17 14:48:42 +02:00
|
|
|
"github.com/compose-spec/compose-go/types"
|
2020-06-11 19:22:12 +02:00
|
|
|
)
|
|
|
|
|
2020-08-20 16:42:37 +02:00
|
|
|
func (b *ecsAPIService) Up(ctx context.Context, project *types.Project) error {
|
|
|
|
err := b.SDK.CheckRequirements(ctx, b.Region)
|
2020-07-15 11:42:16 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-09-08 10:33:06 +02:00
|
|
|
template, err := b.Convert(ctx, project)
|
2020-06-11 19:22:12 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-08-17 17:48:52 +02:00
|
|
|
update, err := b.SDK.StackExists(ctx, project.Name)
|
2020-06-11 19:22:12 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-18 16:56:42 +02:00
|
|
|
operation := stackCreate
|
2020-07-16 16:07:26 +02:00
|
|
|
if update {
|
2020-08-18 16:56:42 +02:00
|
|
|
operation = stackUpdate
|
2020-09-24 16:11:08 +02:00
|
|
|
changeset, err := b.SDK.CreateChangeSet(ctx, project.Name, template)
|
2020-07-16 16:07:26 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-17 17:48:52 +02:00
|
|
|
err = b.SDK.UpdateStack(ctx, changeset)
|
2020-07-16 16:07:26 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
2020-09-24 16:11:08 +02:00
|
|
|
err = b.SDK.CreateStack(ctx, project.Name, template)
|
2020-07-16 16:07:26 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-06-11 19:22:12 +02:00
|
|
|
|
2020-07-27 16:23:46 +02:00
|
|
|
signalChan := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
go func() {
|
|
|
|
<-signalChan
|
|
|
|
fmt.Println("user interrupted deployment. Deleting stack...")
|
2020-08-20 16:42:37 +02:00
|
|
|
b.Down(ctx, project.Name) // nolint:errcheck
|
2020-07-27 16:23:46 +02:00
|
|
|
}()
|
|
|
|
|
2020-08-11 10:43:11 +02:00
|
|
|
err = b.WaitStackCompletion(ctx, project.Name, operation)
|
|
|
|
return err
|
2020-06-11 19:22:12 +02:00
|
|
|
}
|