mirror of https://github.com/docker/compose.git
Introduce "down" command
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
fc7266f3f7
commit
7763de47eb
|
@ -71,6 +71,7 @@ func ComposeCommand(clusteropts *clusterOptions) *cobra.Command {
|
|||
|
||||
cmd.AddCommand(
|
||||
UpCommand(clusteropts, opts),
|
||||
DownCommand(clusteropts, opts),
|
||||
)
|
||||
return cmd
|
||||
}
|
||||
|
@ -87,4 +88,18 @@ func UpCommand(clusteropts *clusterOptions, opts *compose.ProjectOptions) *cobra
|
|||
}),
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func DownCommand(clusteropts *clusterOptions, opts *compose.ProjectOptions) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "down",
|
||||
RunE: compose.WithProject(opts, func(project *compose.Project, args []string) error {
|
||||
client, err := amazon.NewClient(clusteropts.profile, clusteropts.cluster, clusteropts.region)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return client.ComposeDown(project)
|
||||
}),
|
||||
}
|
||||
return cmd
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package amazon
|
||||
|
||||
import (
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/aws/aws-sdk-go/service/ecs"
|
||||
"github.com/docker/ecs-plugin/pkg/compose"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func (c *client) ComposeDown(project *compose.Project) error {
|
||||
services := []*string{}
|
||||
// FIXME we should be able to retrieve services by tags, so we don't need the initial compose file to run "down"
|
||||
for _, service := range project.Services {
|
||||
logrus.Debugf("Deleting service %q\n", service.Name)
|
||||
out, err := c.ECS.DeleteService(&ecs.DeleteServiceInput{
|
||||
// Force to true so that we don't have to scale down to 0
|
||||
// before deleting
|
||||
Force: aws.Bool(true),
|
||||
Cluster: aws.String(c.Cluster),
|
||||
Service: aws.String(service.Name),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Debugf("Service deleted %q\n", *out.Service.ServiceName)
|
||||
services = append(services, out.Service.ServiceName)
|
||||
}
|
||||
logrus.Info("All services stopped")
|
||||
|
||||
err := c.ECS.WaitUntilServicesInactive(&ecs.DescribeServicesInput{
|
||||
Services: services,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Debug("Deleting security groups")
|
||||
groups, err := c.EC2.DescribeSecurityGroups(&ec2.DescribeSecurityGroupsInput{
|
||||
Filters: []*ec2.Filter{
|
||||
{
|
||||
Name: aws.String("tag:" + ProjectTag),
|
||||
Values: aws.StringSlice([]string{project.Name}),
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, g := range groups.SecurityGroups {
|
||||
_, err = c.EC2.DeleteSecurityGroup(&ec2.DeleteSecurityGroupInput{
|
||||
GroupId: g.GroupId,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -2,4 +2,5 @@ package compose
|
|||
|
||||
type API interface {
|
||||
ComposeUp(project *Project) error
|
||||
ComposeDown(project *Project) error
|
||||
}
|
Loading…
Reference in New Issue