mirror of
https://github.com/docker/compose.git
synced 2025-07-23 21:54:40 +02:00
Project name parameter as alternative to compose file on down
Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
parent
f8bf0078aa
commit
d612a4ab89
@ -140,13 +140,27 @@ func DownCommand(clusteropts *clusterOptions, projectOpts *compose.ProjectOption
|
|||||||
opts := downOptions{}
|
opts := downOptions{}
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "down",
|
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)
|
client, err := amazon.NewClient(clusteropts.profile, clusteropts.cluster, clusteropts.region)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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.KeepLoadBalancer, "keep-load-balancer", false, "Keep Load Balancer for further use")
|
||||||
cmd.Flags().BoolVar(&opts.DeleteCluster, "delete-cluster", false, "Delete cluster")
|
cmd.Flags().BoolVar(&opts.DeleteCluster, "delete-cluster", false, "Delete cluster")
|
||||||
|
@ -5,18 +5,17 @@ import (
|
|||||||
|
|
||||||
"github.com/aws/aws-sdk-go/service/cloudformation"
|
"github.com/aws/aws-sdk-go/service/cloudformation"
|
||||||
cf "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{
|
_, err := c.CF.DeleteStack(&cloudformation.DeleteStackInput{
|
||||||
StackName: &project.Name,
|
StackName: projectName,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Printf("Delete stack ")
|
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
|
return err
|
||||||
}
|
}
|
||||||
fmt.Printf("... done.\n")
|
fmt.Printf("... done.\n")
|
||||||
|
@ -5,5 +5,5 @@ import "github.com/awslabs/goformation/v4/cloudformation"
|
|||||||
type API interface {
|
type API interface {
|
||||||
Convert(project *Project, loadBalancerArn *string) (*cloudformation.Template, error)
|
Convert(project *Project, loadBalancerArn *string) (*cloudformation.Template, error)
|
||||||
ComposeUp(project *Project, loadBalancerArn *string) error
|
ComposeUp(project *Project, loadBalancerArn *string) error
|
||||||
ComposeDown(project *Project, keepLoadBalancer, deleteCluster bool) error
|
ComposeDown(projectName *string, keepLoadBalancer, deleteCluster bool) error
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ type ProjectFunc func(project *Project, args []string) error
|
|||||||
// WithProject wrap a ProjectFunc into a cobra command
|
// WithProject wrap a ProjectFunc into a cobra command
|
||||||
func WithProject(options *ProjectOptions, f ProjectFunc) func(cmd *cobra.Command, args []string) error {
|
func WithProject(options *ProjectOptions, f ProjectFunc) func(cmd *cobra.Command, args []string) error {
|
||||||
return 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ func NewProject(config types.ConfigDetails, name string) (*Project, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// projectFromOptions load a compose project based on command line options
|
// 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)
|
configPath, err := getConfigPathFromOptions(options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user