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"
|
2020-10-02 14:08:23 +02:00
|
|
|
|
|
|
|
"github.com/docker/compose-cli/progress"
|
2020-06-11 19:22:12 +02:00
|
|
|
)
|
|
|
|
|
2020-08-20 16:42:37 +02:00
|
|
|
func (b *ecsAPIService) Down(ctx context.Context, project string) error {
|
2020-10-02 14:08:23 +02:00
|
|
|
resources, err := b.SDK.ListStackResources(ctx, project)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = resources.apply(awsTypeCapacityProvider, delete(ctx, b.SDK.DeleteCapacityProvider))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = resources.apply(awsTypeAutoscalingGroup, delete(ctx, b.SDK.DeleteAutoscalingGroup))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
previousEvents, err := b.previousStackEvents(ctx, project)
|
2020-06-11 19:22:12 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-10-02 14:08:23 +02:00
|
|
|
|
|
|
|
err = b.SDK.DeleteStack(ctx, project)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return b.WaitStackCompletion(ctx, project, stackDelete, previousEvents...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *ecsAPIService) previousStackEvents(ctx context.Context, project string) ([]string, error) {
|
|
|
|
events, err := b.SDK.DescribeStackEvents(ctx, project)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var previousEvents []string
|
|
|
|
for _, e := range events {
|
|
|
|
previousEvents = append(previousEvents, *e.EventId)
|
|
|
|
}
|
|
|
|
return previousEvents, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func delete(ctx context.Context, delete func(ctx context.Context, arn string) error) func(r stackResource) error {
|
|
|
|
return func(r stackResource) error {
|
|
|
|
w := progress.ContextWriter(ctx)
|
|
|
|
w.Event(progress.Event{
|
|
|
|
ID: r.LogicalID,
|
|
|
|
Status: progress.Working,
|
|
|
|
StatusText: "DELETE_IN_PROGRESS",
|
|
|
|
})
|
|
|
|
return delete(ctx, r.ARN)
|
|
|
|
}
|
2020-07-15 16:27:24 +02:00
|
|
|
}
|