Project name parameter as alternative to compose file on down

Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
aiordache 2020-04-24 17:25:29 +02:00 committed by Nicolas De loof
parent f8bf0078aa
commit d612a4ab89
5 changed files with 23 additions and 10 deletions

View File

@ -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")

View File

@ -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")

View File

@ -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
}

View File

@ -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
}

View File

@ -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