diff --git a/ecs/cmd/main/main.go b/ecs/cmd/main/main.go index ab365bd40..7b3d1d6aa 100644 --- a/ecs/cmd/main/main.go +++ b/ecs/cmd/main/main.go @@ -140,13 +140,27 @@ func DownCommand(clusteropts *clusterOptions, projectOpts *compose.ProjectOption opts := downOptions{} cmd := &cobra.Command{ Use: "down", - RunE: compose.WithProject(projectOpts, func(project *compose.Project, args []string) error { + RunE: func(cmd *cobra.Command, args []string) error { client, err := amazon.NewClient(clusteropts.profile, clusteropts.cluster, clusteropts.region) if err != nil { return err } - return client.ComposeDown(project, opts.KeepLoadBalancer, opts.DeleteCluster) - }), + if len(args) == 0 { + project, err := compose.ProjectFromOptions(projectOpts) + if err != nil { + return err + } + return client.ComposeDown(&project.Name, opts.KeepLoadBalancer, opts.DeleteCluster) + } + // project names passed as parameters + for _, name := range args { + err := client.ComposeDown(&name, opts.KeepLoadBalancer, opts.DeleteCluster) + if err != nil { + return err + } + } + return nil + }, } cmd.Flags().BoolVar(&opts.KeepLoadBalancer, "keep-load-balancer", false, "Keep Load Balancer for further use") cmd.Flags().BoolVar(&opts.DeleteCluster, "delete-cluster", false, "Delete cluster") diff --git a/ecs/pkg/amazon/down.go b/ecs/pkg/amazon/down.go index a7b44892e..4dfdff4a3 100644 --- a/ecs/pkg/amazon/down.go +++ b/ecs/pkg/amazon/down.go @@ -5,18 +5,17 @@ import ( "github.com/aws/aws-sdk-go/service/cloudformation" cf "github.com/aws/aws-sdk-go/service/cloudformation" - "github.com/docker/ecs-plugin/pkg/compose" ) -func (c *client) ComposeDown(project *compose.Project, keepLoadBalancer, deleteCluster bool) error { +func (c *client) ComposeDown(projectName *string, keepLoadBalancer, deleteCluster bool) error { _, err := c.CF.DeleteStack(&cloudformation.DeleteStackInput{ - StackName: &project.Name, + StackName: projectName, }) if err != nil { return err } fmt.Printf("Delete stack ") - if err = c.CF.WaitUntilStackDeleteComplete(&cf.DescribeStacksInput{StackName: &project.Name}); err != nil { + if err = c.CF.WaitUntilStackDeleteComplete(&cf.DescribeStacksInput{StackName: projectName}); err != nil { return err } fmt.Printf("... done.\n") diff --git a/ecs/pkg/compose/api.go b/ecs/pkg/compose/api.go index 4218de767..b30750824 100644 --- a/ecs/pkg/compose/api.go +++ b/ecs/pkg/compose/api.go @@ -5,5 +5,5 @@ import "github.com/awslabs/goformation/v4/cloudformation" type API interface { Convert(project *Project, loadBalancerArn *string) (*cloudformation.Template, error) ComposeUp(project *Project, loadBalancerArn *string) error - ComposeDown(project *Project, keepLoadBalancer, deleteCluster bool) error + ComposeDown(projectName *string, keepLoadBalancer, deleteCluster bool) error } diff --git a/ecs/pkg/compose/opts.go b/ecs/pkg/compose/opts.go index 390ccaa69..9e9bdeee0 100644 --- a/ecs/pkg/compose/opts.go +++ b/ecs/pkg/compose/opts.go @@ -20,7 +20,7 @@ type ProjectFunc func(project *Project, args []string) error // WithProject wrap a ProjectFunc into a cobra command func WithProject(options *ProjectOptions, f ProjectFunc) func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error { - project, err := projectFromOptions(options) + project, err := ProjectFromOptions(options) if err != nil { return err } diff --git a/ecs/pkg/compose/project.go b/ecs/pkg/compose/project.go index 6f2ef98e9..e17e22527 100644 --- a/ecs/pkg/compose/project.go +++ b/ecs/pkg/compose/project.go @@ -34,7 +34,7 @@ func NewProject(config types.ConfigDetails, name string) (*Project, error) { } // projectFromOptions load a compose project based on command line options -func projectFromOptions(options *ProjectOptions) (*Project, error) { +func ProjectFromOptions(options *ProjectOptions) (*Project, error) { configPath, err := getConfigPathFromOptions(options) if err != nil { return nil, err