mirror of https://github.com/docker/compose.git
ecs cluster create
Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
parent
0972776e6d
commit
30fd37b6ca
|
@ -12,7 +12,7 @@ func (c *client) ComposeDown(project *compose.Project, keepLoadBalancer bool) er
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.DeleteCluster()
|
||||
// TODO monitor progress
|
||||
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()
|
||||
}
|
||||
template, err := c.Convert(project, loadBalancerArn)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue