mirror of https://github.com/docker/compose.git
Split API interface by required SDK func per command
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
3d8d982d4a
commit
4138dcfb5a
|
@ -98,7 +98,7 @@ func ConvertCommand(clusteropts *clusterOptions, projectOpts *compose.ProjectOpt
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
template, err := client.Convert(project, opts.LoadBalancerArn())
|
||||
template, err := client.Convert(project)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ func UpCommand(clusteropts *clusterOptions, projectOpts *compose.ProjectOptions)
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return client.ComposeUp(project, opts.LoadBalancerArn())
|
||||
return client.ComposeUp(project)
|
||||
}),
|
||||
}
|
||||
cmd.Flags().StringVar(&opts.loadBalancerArn, "load-balancer", "", "")
|
||||
|
|
|
@ -1,22 +1,7 @@
|
|||
package amazon
|
||||
|
||||
import (
|
||||
"github.com/awslabs/goformation/v4/cloudformation"
|
||||
)
|
||||
|
||||
type API interface {
|
||||
ClusterExists(name string) (bool, error)
|
||||
CreateCluster(name string) (string, error)
|
||||
DeleteCluster(name string) error
|
||||
|
||||
GetDefaultVPC() (string, error)
|
||||
GetSubNets(vpcId string) ([]string, error)
|
||||
|
||||
ListRolesForPolicy(policy string) ([]string, error)
|
||||
GetRoleArn(name string) (string, error)
|
||||
|
||||
StackExists(name string) (bool, error)
|
||||
CreateStack(name string, template *cloudformation.Template) error
|
||||
DescribeStackEvents(stack string) error
|
||||
DeleteStack(name string) error
|
||||
downAPI
|
||||
upAPI
|
||||
convertAPI
|
||||
}
|
||||
|
|
|
@ -2,9 +2,10 @@ package amazon
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
"github.com/sirupsen/logrus"
|
||||
"strings"
|
||||
|
||||
ecsapi "github.com/aws/aws-sdk-go/service/ecs"
|
||||
"github.com/awslabs/goformation/v4/cloudformation"
|
||||
|
@ -14,7 +15,7 @@ import (
|
|||
"github.com/docker/ecs-plugin/pkg/convert"
|
||||
)
|
||||
|
||||
func (c client) Convert(project *compose.Project, loadBalancerArn *string) (*cloudformation.Template, error) {
|
||||
func (c client) Convert(project *compose.Project) (*cloudformation.Template, error) {
|
||||
template := cloudformation.NewTemplate()
|
||||
vpc, err := c.api.GetDefaultVPC()
|
||||
if err != nil {
|
||||
|
@ -113,3 +114,10 @@ func (c client) GetEcsTaskExecutionRole(spec types.ServiceConfig) (string, error
|
|||
defaultTaskExecutionRole = arn
|
||||
return arn, nil
|
||||
}
|
||||
|
||||
type convertAPI interface {
|
||||
GetDefaultVPC() (string, error)
|
||||
GetSubNets(vpcId string) ([]string, error)
|
||||
ListRolesForPolicy(policy string) ([]string, error)
|
||||
GetRoleArn(name string) (string, error)
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ func (c *client) ComposeDown(projectName *string, keepLoadBalancer, deleteCluste
|
|||
}
|
||||
fmt.Printf("Delete stack ")
|
||||
|
||||
|
||||
if !deleteCluster {
|
||||
return nil
|
||||
}
|
||||
|
@ -23,3 +22,8 @@ func (c *client) ComposeDown(projectName *string, keepLoadBalancer, deleteCluste
|
|||
fmt.Printf("... done. \n")
|
||||
return nil
|
||||
}
|
||||
|
||||
type downAPI interface {
|
||||
DeleteStack(name string) error
|
||||
DeleteCluster(name string) error
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package amazon
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/docker/ecs-plugin/pkg/amazon/mock"
|
||||
"github.com/docker/ecs-plugin/pkg/compose"
|
||||
"github.com/golang/mock/gomock"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_down_dont_delete_cluster(t *testing.T) {
|
||||
|
@ -22,7 +23,7 @@ func Test_down_dont_delete_cluster(t *testing.T) {
|
|||
|
||||
c.ComposeDown(&compose.Project{
|
||||
Name: "test_project",
|
||||
}, false, false)
|
||||
}, false)
|
||||
}
|
||||
|
||||
func Test_down_delete_cluster(t *testing.T) {
|
||||
|
@ -41,5 +42,5 @@ func Test_down_delete_cluster(t *testing.T) {
|
|||
|
||||
c.ComposeDown(&compose.Project{
|
||||
Name: "test_project",
|
||||
}, false, true)
|
||||
}, true)
|
||||
}
|
||||
|
|
|
@ -2,10 +2,12 @@ package amazon
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/awslabs/goformation/v4/cloudformation"
|
||||
"github.com/docker/ecs-plugin/pkg/compose"
|
||||
)
|
||||
|
||||
func (c *client) ComposeUp(project *compose.Project, loadBalancerArn *string) error {
|
||||
func (c *client) ComposeUp(project *compose.Project) error {
|
||||
ok, err := c.api.ClusterExists(c.Cluster)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -18,7 +20,7 @@ func (c *client) ComposeUp(project *compose.Project, loadBalancerArn *string) er
|
|||
return fmt.Errorf("we do not (yet) support updating an existing CloudFormation stack")
|
||||
}
|
||||
|
||||
template, err := c.Convert(project, loadBalancerArn)
|
||||
template, err := c.Convert(project)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -33,3 +35,11 @@ func (c *client) ComposeUp(project *compose.Project, loadBalancerArn *string) er
|
|||
// TODO monitor progress
|
||||
return nil
|
||||
}
|
||||
|
||||
type upAPI interface {
|
||||
ClusterExists(name string) (bool, error)
|
||||
CreateCluster(name string) (string, error)
|
||||
StackExists(name string) (bool, error)
|
||||
CreateStack(name string, template *cloudformation.Template) error
|
||||
DescribeStackEvents(stack string) error
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue