mirror of https://github.com/docker/compose.git
Merge branch 'aiordache-cluster-create'
This commit is contained in:
commit
5be037dae1
|
@ -133,6 +133,7 @@ func UpCommand(clusteropts *clusterOptions, projectOpts *compose.ProjectOptions)
|
|||
|
||||
type downOptions struct {
|
||||
KeepLoadBalancer bool
|
||||
DeleteCluster bool
|
||||
}
|
||||
|
||||
func DownCommand(clusteropts *clusterOptions, projectOpts *compose.ProjectOptions) *cobra.Command {
|
||||
|
@ -144,9 +145,10 @@ func DownCommand(clusteropts *clusterOptions, projectOpts *compose.ProjectOption
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return client.ComposeDown(project, opts.KeepLoadBalancer)
|
||||
return client.ComposeDown(project, opts.KeepLoadBalancer, opts.DeleteCluster)
|
||||
}),
|
||||
}
|
||||
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")
|
||||
return cmd
|
||||
}
|
||||
|
|
|
@ -35,12 +35,14 @@ require (
|
|||
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
|
||||
github.com/miekg/pkcs11 v1.0.3 // indirect
|
||||
github.com/morikuni/aec v1.0.0 // indirect
|
||||
github.com/onsi/ginkgo v1.11.0 // indirect
|
||||
github.com/opencontainers/image-spec v1.0.1 // indirect
|
||||
github.com/sirupsen/logrus v1.5.0
|
||||
github.com/spf13/cobra v0.0.5
|
||||
github.com/spf13/pflag v1.0.3
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/theupdateframework/notary v0.6.1 // indirect
|
||||
github.com/xlab/handysort v0.0.0-20150421192137-fb3537ed64a1 // indirect
|
||||
golang.org/x/sys v0.0.0-20191022100944-742c48ecaeb7 // indirect
|
||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
|
||||
google.golang.org/grpc v1.27.0 // indirect
|
||||
gopkg.in/dancannon/gorethink.v3 v3.0.5 // indirect
|
||||
|
|
|
@ -210,6 +210,8 @@ github.com/onsi/ginkgo v1.5.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
|
|||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.10.1 h1:q/mM8GF/n0shIN8SaAZ0V+jnLPzen6WIVZdiwrRlMlo=
|
||||
github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.11.0 h1:JAKSXpt1YjtLA7YpPiqO9ss6sNXEsPfSGdwN0UHqzrw=
|
||||
github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/gomega v1.2.0/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
|
||||
github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME=
|
||||
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
|
@ -271,6 +273,8 @@ github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb6
|
|||
github.com/spf13/pflag v1.0.1-0.20171106142849-4c012f6dcd95/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
|
||||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/viper v1.3.2 h1:VUFqw5KcqRf7i70GOzW7N+Q7+gxVBkSSqiXB12+JQ4M=
|
||||
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
|
@ -360,6 +364,8 @@ golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3 h1:4y9KwBHBgBNwDbtu44R5o1fdO
|
|||
golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3 h1:7TYNF4UdlohbFwpNH04CoPMp1cHUZgO1Ebq5r2hIjfo=
|
||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191022100944-742c48ecaeb7 h1:HmbHVPwrPEKPGLAcHSrMe6+hqSUlvZU0rab6x5EXfGU=
|
||||
golang.org/x/sys v0.0.0-20191022100944-742c48ecaeb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||
|
|
|
@ -1,18 +1,34 @@
|
|||
package amazon
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"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 bool) error {
|
||||
func (c *client) ComposeDown(project *compose.Project, keepLoadBalancer, deleteCluster bool) error {
|
||||
_, err := c.CF.DeleteStack(&cloudformation.DeleteStackInput{
|
||||
StackName: &project.Name,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Delete stack ")
|
||||
if err = c.CF.WaitUntilStackDeleteComplete(&cf.DescribeStacksInput{StackName: &project.Name}); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("... done.\n")
|
||||
|
||||
// TODO monitor progress
|
||||
if !deleteCluster {
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Printf("Delete cluster %s", c.Cluster)
|
||||
if err = c.DeleteCluster(); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("... done. \n")
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package amazon
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/aws/aws-sdk-go/service/ecs"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
@ -13,3 +16,37 @@ func (c client) RegisterTaskDefinition(task *ecs.RegisterTaskDefinitionInput) (*
|
|||
}
|
||||
return def.TaskDefinition.TaskDefinitionArn, err
|
||||
}
|
||||
|
||||
func (c client) CreateCluster() (*string, error) {
|
||||
logrus.Debug("Create cluster ", c.Cluster)
|
||||
response, err := c.ECS.CreateCluster(&ecs.CreateClusterInput{ClusterName: &c.Cluster})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return response.Cluster.Status, nil
|
||||
}
|
||||
|
||||
func (c client) DeleteCluster() error {
|
||||
logrus.Debug("Delete cluster ", c.Cluster)
|
||||
response, err := c.ECS.DeleteCluster(&ecs.DeleteClusterInput{Cluster: &c.Cluster})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if *response.Cluster.Status == "INACTIVE" {
|
||||
return nil
|
||||
}
|
||||
return errors.New("Failed to delete cluster, status: " + *response.Cluster.Status)
|
||||
}
|
||||
|
||||
func (c client) ClusterExists() (bool, error) {
|
||||
logrus.Debug("Check if cluster was already created: ", c.Cluster)
|
||||
clusters, err := c.ECS.ListClusters(nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
found := false
|
||||
for _, arn := range clusters.ClusterArns {
|
||||
found = found || strings.HasSuffix(*arn, "/"+c.Cluster)
|
||||
}
|
||||
return found, nil
|
||||
}
|
||||
|
|
|
@ -10,6 +10,13 @@ import (
|
|||
)
|
||||
|
||||
func (c *client) ComposeUp(project *compose.Project, loadBalancerArn *string) error {
|
||||
ok, err := c.ClusterExists()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !ok {
|
||||
c.CreateCluster()
|
||||
}
|
||||
_, err := c.CF.DescribeStacks(&cloudformation.DescribeStacksInput{
|
||||
StackName: aws.String(project.Name),
|
||||
})
|
||||
|
|
|
@ -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 bool) error
|
||||
ComposeDown(project *Project, keepLoadBalancer, deleteCluster bool) error
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue