mirror of
https://github.com/docker/compose.git
synced 2025-07-27 07:34:10 +02:00
Collect events while waiting for stack to complete
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
41aaf802e3
commit
678f4018f0
@ -6,7 +6,8 @@ package mock
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
context "context"
|
context "context"
|
||||||
cloudformation "github.com/awslabs/goformation/v4/cloudformation"
|
cloudformation "github.com/aws/aws-sdk-go/service/cloudformation"
|
||||||
|
cloudformation0 "github.com/awslabs/goformation/v4/cloudformation"
|
||||||
gomock "github.com/golang/mock/gomock"
|
gomock "github.com/golang/mock/gomock"
|
||||||
reflect "reflect"
|
reflect "reflect"
|
||||||
)
|
)
|
||||||
@ -65,7 +66,7 @@ func (mr *MockAPIMockRecorder) CreateCluster(arg0, arg1 interface{}) *gomock.Cal
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateStack mocks base method
|
// CreateStack mocks base method
|
||||||
func (m *MockAPI) CreateStack(arg0 context.Context, arg1 string, arg2 *cloudformation.Template) error {
|
func (m *MockAPI) CreateStack(arg0 context.Context, arg1 string, arg2 *cloudformation0.Template) error {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "CreateStack", arg0, arg1, arg2)
|
ret := m.ctrl.Call(m, "CreateStack", arg0, arg1, arg2)
|
||||||
ret0, _ := ret[0].(error)
|
ret0, _ := ret[0].(error)
|
||||||
@ -107,11 +108,12 @@ func (mr *MockAPIMockRecorder) DeleteStack(arg0, arg1 interface{}) *gomock.Call
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DescribeStackEvents mocks base method
|
// DescribeStackEvents mocks base method
|
||||||
func (m *MockAPI) DescribeStackEvents(arg0 context.Context, arg1 string) error {
|
func (m *MockAPI) DescribeStackEvents(arg0 context.Context, arg1 string) ([]*cloudformation.StackEvent, error) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
ret := m.ctrl.Call(m, "DescribeStackEvents", arg0, arg1)
|
ret := m.ctrl.Call(m, "DescribeStackEvents", arg0, arg1)
|
||||||
ret0, _ := ret[0].(error)
|
ret0, _ := ret[0].([]*cloudformation.StackEvent)
|
||||||
return ret0
|
ret1, _ := ret[1].(error)
|
||||||
|
return ret0, ret1
|
||||||
}
|
}
|
||||||
|
|
||||||
// DescribeStackEvents indicates an expected call of DescribeStackEvents
|
// DescribeStackEvents indicates an expected call of DescribeStackEvents
|
||||||
@ -209,3 +211,17 @@ func (mr *MockAPIMockRecorder) VpcExists(arg0, arg1 interface{}) *gomock.Call {
|
|||||||
mr.mock.ctrl.T.Helper()
|
mr.mock.ctrl.T.Helper()
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "VpcExists", reflect.TypeOf((*MockAPI)(nil).VpcExists), arg0, arg1)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "VpcExists", reflect.TypeOf((*MockAPI)(nil).VpcExists), arg0, arg1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WaitStackComplete mocks base method
|
||||||
|
func (m *MockAPI) WaitStackComplete(arg0 context.Context, arg1 string, arg2 func() error) error {
|
||||||
|
m.ctrl.T.Helper()
|
||||||
|
ret := m.ctrl.Call(m, "WaitStackComplete", arg0, arg1, arg2)
|
||||||
|
ret0, _ := ret[0].(error)
|
||||||
|
return ret0
|
||||||
|
}
|
||||||
|
|
||||||
|
// WaitStackComplete indicates an expected call of WaitStackComplete
|
||||||
|
func (mr *MockAPIMockRecorder) WaitStackComplete(arg0, arg1, arg2 interface{}) *gomock.Call {
|
||||||
|
mr.mock.ctrl.T.Helper()
|
||||||
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WaitStackComplete", reflect.TypeOf((*MockAPI)(nil).WaitStackComplete), arg0, arg1, arg2)
|
||||||
|
}
|
||||||
|
@ -3,6 +3,8 @@ package amazon
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/aws/session"
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
@ -183,13 +185,47 @@ func (s sdk) CreateStack(ctx context.Context, name string, template *cf.Template
|
|||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
func (s sdk) WaitStackComplete(ctx context.Context, name string, fn func() error) error {
|
||||||
|
for i := 0; i < 120; i++ {
|
||||||
|
stacks, err := s.CF.DescribeStacks(&cloudformation.DescribeStacksInput{
|
||||||
|
StackName: aws.String(name),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (s sdk) DescribeStackEvents(ctx context.Context, name string) error {
|
err = fn()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
status := *stacks.Stacks[0].StackStatus
|
||||||
|
if strings.HasSuffix(status, "_COMPLETE") || strings.HasSuffix(status, "_FAILED") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("120s timeout waiting for CloudFormation stack %s to complete", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s sdk) DescribeStackEvents(ctx context.Context, name string) ([]*cloudformation.StackEvent, error) {
|
||||||
// Fixme implement Paginator on Events and return as a chan(events)
|
// Fixme implement Paginator on Events and return as a chan(events)
|
||||||
_, err := s.CF.DescribeStackEventsWithContext(aws.Context(ctx), &cloudformation.DescribeStackEventsInput{
|
events := []*cloudformation.StackEvent{}
|
||||||
StackName: aws.String(name),
|
var nextToken *string
|
||||||
})
|
for {
|
||||||
return err
|
resp, err := s.CF.DescribeStackEventsWithContext(aws.Context(ctx), &cloudformation.DescribeStackEventsInput{
|
||||||
|
StackName: aws.String(name),
|
||||||
|
NextToken: nextToken,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
events = append(events, resp.StackEvents...)
|
||||||
|
if resp.NextToken == nil {
|
||||||
|
return events, nil
|
||||||
|
}
|
||||||
|
nextToken = resp.NextToken
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s sdk) DeleteStack(ctx context.Context, name string) error {
|
func (s sdk) DeleteStack(ctx context.Context, name string) error {
|
||||||
|
@ -4,6 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
cf "github.com/aws/aws-sdk-go/service/cloudformation"
|
||||||
|
|
||||||
"github.com/awslabs/goformation/v4/cloudformation"
|
"github.com/awslabs/goformation/v4/cloudformation"
|
||||||
"github.com/docker/ecs-plugin/pkg/compose"
|
"github.com/docker/ecs-plugin/pkg/compose"
|
||||||
)
|
)
|
||||||
@ -34,7 +36,26 @@ func (c *client) ComposeUp(ctx context.Context, project *compose.Project) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.api.DescribeStackEvents(ctx, project.Name)
|
known := map[string]struct{}{}
|
||||||
|
err = c.api.WaitStackComplete(ctx, project.Name, func() error {
|
||||||
|
events, err := c.api.DescribeStackEvents(ctx, project.Name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, event := range events {
|
||||||
|
if _, ok := known[*event.EventId]; ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
known[*event.EventId] = struct{}{}
|
||||||
|
|
||||||
|
description := "-"
|
||||||
|
if event.ResourceStatusReason != nil {
|
||||||
|
description = *event.ResourceStatusReason
|
||||||
|
}
|
||||||
|
fmt.Printf("%s %q %s %s\n", *event.ResourceType, *event.LogicalResourceId, *event.ResourceStatus, description)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -48,5 +69,6 @@ type upAPI interface {
|
|||||||
CreateCluster(ctx context.Context, name string) (string, error)
|
CreateCluster(ctx context.Context, name string) (string, error)
|
||||||
StackExists(ctx context.Context, name string) (bool, error)
|
StackExists(ctx context.Context, name string) (bool, error)
|
||||||
CreateStack(ctx context.Context, name string, template *cloudformation.Template) error
|
CreateStack(ctx context.Context, name string, template *cloudformation.Template) error
|
||||||
DescribeStackEvents(ctx context.Context, stack string) error
|
WaitStackComplete(ctx context.Context, name string, fn func() error) error
|
||||||
|
DescribeStackEvents(ctx context.Context, stack string) ([]*cf.StackEvent, error)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user