diff --git a/ecs/cmd/main/main.go b/ecs/cmd/main/main.go index 7b3d1d6a..ad67ece0 100644 --- a/ecs/cmd/main/main.go +++ b/ecs/cmd/main/main.go @@ -98,7 +98,7 @@ func ConvertCommand(clusteropts *clusterOptions, projectOpts *compose.ProjectOpt if err != nil { return err } - template, err := client.Convert(project, opts.LoadBalancerArn()) + template, err := client.Convert(project) if err != nil { return err } @@ -124,7 +124,7 @@ func UpCommand(clusteropts *clusterOptions, projectOpts *compose.ProjectOptions) if err != nil { return err } - return client.ComposeUp(project, opts.LoadBalancerArn()) + return client.ComposeUp(project) }), } cmd.Flags().StringVar(&opts.loadBalancerArn, "load-balancer", "", "") diff --git a/ecs/pkg/amazon/api.go b/ecs/pkg/amazon/api.go index 954c1b45..54301404 100644 --- a/ecs/pkg/amazon/api.go +++ b/ecs/pkg/amazon/api.go @@ -1,22 +1,7 @@ package amazon -import ( - "github.com/awslabs/goformation/v4/cloudformation" -) - type API interface { - ClusterExists(name string) (bool, error) - CreateCluster(name string) (string, error) - DeleteCluster(name string) error - - GetDefaultVPC() (string, error) - GetSubNets(vpcId string) ([]string, error) - - ListRolesForPolicy(policy string) ([]string, error) - GetRoleArn(name string) (string, error) - - StackExists(name string) (bool, error) - CreateStack(name string, template *cloudformation.Template) error - DescribeStackEvents(stack string) error - DeleteStack(name string) error + downAPI + upAPI + convertAPI } diff --git a/ecs/pkg/amazon/cloudformation.go b/ecs/pkg/amazon/cloudformation.go index 91c8bca7..5f91d76e 100644 --- a/ecs/pkg/amazon/cloudformation.go +++ b/ecs/pkg/amazon/cloudformation.go @@ -2,9 +2,10 @@ package amazon import ( "fmt" + "strings" + "github.com/compose-spec/compose-go/types" "github.com/sirupsen/logrus" - "strings" ecsapi "github.com/aws/aws-sdk-go/service/ecs" "github.com/awslabs/goformation/v4/cloudformation" @@ -14,7 +15,7 @@ import ( "github.com/docker/ecs-plugin/pkg/convert" ) -func (c client) Convert(project *compose.Project, loadBalancerArn *string) (*cloudformation.Template, error) { +func (c client) Convert(project *compose.Project) (*cloudformation.Template, error) { template := cloudformation.NewTemplate() vpc, err := c.api.GetDefaultVPC() if err != nil { @@ -113,3 +114,10 @@ func (c client) GetEcsTaskExecutionRole(spec types.ServiceConfig) (string, error defaultTaskExecutionRole = arn return arn, nil } + +type convertAPI interface { + GetDefaultVPC() (string, error) + GetSubNets(vpcId string) ([]string, error) + ListRolesForPolicy(policy string) ([]string, error) + GetRoleArn(name string) (string, error) +} diff --git a/ecs/pkg/amazon/down.go b/ecs/pkg/amazon/down.go index 49583864..18557231 100644 --- a/ecs/pkg/amazon/down.go +++ b/ecs/pkg/amazon/down.go @@ -11,7 +11,6 @@ func (c *client) ComposeDown(projectName *string, keepLoadBalancer, deleteCluste } fmt.Printf("Delete stack ") - if !deleteCluster { return nil } @@ -23,3 +22,8 @@ func (c *client) ComposeDown(projectName *string, keepLoadBalancer, deleteCluste fmt.Printf("... done. \n") return nil } + +type downAPI interface { + DeleteStack(name string) error + DeleteCluster(name string) error +} diff --git a/ecs/pkg/amazon/down_test.go b/ecs/pkg/amazon/down_test.go index 3738e78d..161bdfe1 100644 --- a/ecs/pkg/amazon/down_test.go +++ b/ecs/pkg/amazon/down_test.go @@ -1,10 +1,11 @@ package amazon import ( + "testing" + "github.com/docker/ecs-plugin/pkg/amazon/mock" "github.com/docker/ecs-plugin/pkg/compose" "github.com/golang/mock/gomock" - "testing" ) func Test_down_dont_delete_cluster(t *testing.T) { @@ -22,7 +23,7 @@ func Test_down_dont_delete_cluster(t *testing.T) { c.ComposeDown(&compose.Project{ Name: "test_project", - }, false, false) + }, false) } func Test_down_delete_cluster(t *testing.T) { @@ -41,5 +42,5 @@ func Test_down_delete_cluster(t *testing.T) { c.ComposeDown(&compose.Project{ Name: "test_project", - }, false, true) + }, true) } diff --git a/ecs/pkg/amazon/up.go b/ecs/pkg/amazon/up.go index 4488cf67..493c8cba 100644 --- a/ecs/pkg/amazon/up.go +++ b/ecs/pkg/amazon/up.go @@ -2,10 +2,12 @@ package amazon import ( "fmt" + + "github.com/awslabs/goformation/v4/cloudformation" "github.com/docker/ecs-plugin/pkg/compose" ) -func (c *client) ComposeUp(project *compose.Project, loadBalancerArn *string) error { +func (c *client) ComposeUp(project *compose.Project) error { ok, err := c.api.ClusterExists(c.Cluster) if err != nil { return err @@ -18,7 +20,7 @@ func (c *client) ComposeUp(project *compose.Project, loadBalancerArn *string) er return fmt.Errorf("we do not (yet) support updating an existing CloudFormation stack") } - template, err := c.Convert(project, loadBalancerArn) + template, err := c.Convert(project) if err != nil { return err } @@ -33,3 +35,11 @@ func (c *client) ComposeUp(project *compose.Project, loadBalancerArn *string) er // TODO monitor progress return nil } + +type upAPI interface { + ClusterExists(name string) (bool, error) + CreateCluster(name string) (string, error) + StackExists(name string) (bool, error) + CreateStack(name string, template *cloudformation.Template) error + DescribeStackEvents(stack string) error +}