mirror of https://github.com/docker/compose.git
match docker/api signature for up and down methods
Signed-off-by: aiordache <anca.iordache@docker.com> Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
9e8ddb63cc
commit
1bb95134f0
|
@ -75,16 +75,12 @@ func UpCommand(dockerCli command.Cli, projectOpts *compose.ProjectOptions) *cobr
|
|||
opts := upOptions{}
|
||||
cmd := &cobra.Command{
|
||||
Use: "up",
|
||||
RunE: compose.WithProject(projectOpts, func(project *compose.Project, args []string) error {
|
||||
clusteropts, err := docker.GetAwsContext(dockerCli)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
RunE: docker.WithAwsContext(dockerCli, func(clusteropts docker.AwsContext, args []string) error {
|
||||
backend, err := amazon.NewBackend(clusteropts.Profile, clusteropts.Cluster, clusteropts.Region)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return backend.ComposeUp(context.Background(), project)
|
||||
return backend.Up(context.Background(), *projectOpts)
|
||||
}),
|
||||
}
|
||||
cmd.Flags().StringVar(&opts.loadBalancerArn, "load-balancer", "", "")
|
||||
|
@ -104,7 +100,7 @@ func PsCommand(dockerCli command.Cli, projectOpts *compose.ProjectOptions) *cobr
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tasks, err := backend.ComposePs(context.Background(), project)
|
||||
tasks, err := backend.Ps(context.Background(), project)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -133,21 +129,7 @@ func DownCommand(dockerCli command.Cli, projectOpts *compose.ProjectOptions) *co
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(args) == 0 {
|
||||
project, err := compose.ProjectFromOptions(projectOpts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return backend.ComposeDown(context.Background(), project.Name, opts.DeleteCluster)
|
||||
}
|
||||
// project names passed as parameters
|
||||
for _, name := range args {
|
||||
err := backend.ComposeDown(context.Background(), name, opts.DeleteCluster)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return backend.Down(context.Background(), *projectOpts)
|
||||
}),
|
||||
}
|
||||
cmd.Flags().BoolVar(&opts.DeleteCluster, "delete-cluster", false, "Delete cluster")
|
||||
|
@ -173,7 +155,7 @@ func LogsCommand(dockerCli command.Cli, projectOpts *compose.ProjectOptions) *co
|
|||
} else {
|
||||
name = args[0]
|
||||
}
|
||||
return backend.ComposeLogs(context.Background(), name)
|
||||
return backend.Logs(context.Background(), name)
|
||||
}),
|
||||
}
|
||||
return cmd
|
||||
|
|
|
@ -2,30 +2,25 @@ package backend
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/docker/ecs-plugin/pkg/amazon/types"
|
||||
"github.com/docker/ecs-plugin/pkg/compose"
|
||||
)
|
||||
|
||||
func (b *Backend) ComposeDown(ctx context.Context, projectName string, deleteCluster bool) error {
|
||||
err := b.api.DeleteStack(ctx, projectName)
|
||||
func (b *Backend) Down(ctx context.Context, options compose.ProjectOptions) error {
|
||||
project, err := compose.ProjectFromOptions(&options)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = b.WaitStackCompletion(ctx, projectName, types.StackDelete)
|
||||
err = b.api.DeleteStack(ctx, project.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !deleteCluster {
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Printf("Delete cluster %s", b.Cluster)
|
||||
if err = b.api.DeleteCluster(ctx, b.Cluster); err != nil {
|
||||
err = b.WaitStackCompletion(ctx, project.Name, types.StackDelete)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("... done. \n")
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -6,10 +6,11 @@ import (
|
|||
|
||||
"github.com/docker/ecs-plugin/pkg/amazon/sdk"
|
||||
btypes "github.com/docker/ecs-plugin/pkg/amazon/types"
|
||||
"github.com/docker/ecs-plugin/pkg/compose"
|
||||
"github.com/golang/mock/gomock"
|
||||
)
|
||||
|
||||
func TestDownDontDeleteCluster(t *testing.T) {
|
||||
func TestDown(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
m := sdk.NewMockAPI(ctrl)
|
||||
|
@ -25,26 +26,8 @@ func TestDownDontDeleteCluster(t *testing.T) {
|
|||
recorder.WaitStackComplete(ctx, "stack-123", btypes.StackDelete).Return(nil)
|
||||
recorder.DescribeStackEvents(ctx, "stack-123").Return(nil, nil)
|
||||
|
||||
c.ComposeDown(ctx, "test_project", false)
|
||||
}
|
||||
|
||||
func TestDownDeleteCluster(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
m := sdk.NewMockAPI(ctrl)
|
||||
c := &Backend{
|
||||
Cluster: "test_cluster",
|
||||
Region: "region",
|
||||
api: m,
|
||||
}
|
||||
|
||||
ctx := context.TODO()
|
||||
recorder := m.EXPECT()
|
||||
recorder.DeleteStack(ctx, "test_project").Return(nil)
|
||||
recorder.GetStackID(ctx, "test_project").Return("stack-123", nil)
|
||||
recorder.WaitStackComplete(ctx, "stack-123", btypes.StackDelete).Return(nil)
|
||||
recorder.DescribeStackEvents(ctx, "stack-123").Return(nil, nil)
|
||||
recorder.DeleteCluster(ctx, "test_cluster").Return(nil)
|
||||
|
||||
c.ComposeDown(ctx, "test_project", true)
|
||||
c.Down(ctx, compose.ProjectOptions{
|
||||
ConfigPaths: []string{},
|
||||
Name: "test_project",
|
||||
})
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/docker/ecs-plugin/pkg/compose"
|
||||
)
|
||||
|
||||
func (b *Backend) ComposePs(ctx context.Context, project *compose.Project) ([]types.TaskStatus, error) {
|
||||
func (b *Backend) Ps(ctx context.Context, project *compose.Project) ([]types.TaskStatus, error) {
|
||||
cluster := b.Cluster
|
||||
if cluster == "" {
|
||||
cluster = project.Name
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"github.com/docker/ecs-plugin/pkg/console"
|
||||
)
|
||||
|
||||
func (b *Backend) ComposeLogs(ctx context.Context, projectName string) error {
|
||||
func (b *Backend) Logs(ctx context.Context, projectName string) error {
|
||||
err := b.api.GetLogs(ctx, projectName, &logConsumer{
|
||||
colors: map[string]console.ColorFunc{},
|
||||
width: 0,
|
||||
|
|
|
@ -8,7 +8,12 @@ import (
|
|||
"github.com/docker/ecs-plugin/pkg/compose"
|
||||
)
|
||||
|
||||
func (b *Backend) ComposeUp(ctx context.Context, project *compose.Project) error {
|
||||
func (b *Backend) Up(ctx context.Context, options compose.ProjectOptions) error {
|
||||
project, err := compose.ProjectFromOptions(&options)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if b.Cluster != "" {
|
||||
ok, err := b.api.ClusterExists(ctx, b.Cluster)
|
||||
if err != nil {
|
||||
|
|
|
@ -8,14 +8,15 @@ import (
|
|||
)
|
||||
|
||||
type API interface {
|
||||
Up(ctx context.Context, options ProjectOptions) error
|
||||
Down(ctx context.Context, options ProjectOptions) error
|
||||
|
||||
Convert(project *Project) (*cloudformation.Template, error)
|
||||
ComposeUp(ctx context.Context, project *Project) error
|
||||
ComposeDown(ctx context.Context, projectName string, deleteCluster bool) error
|
||||
ComposeLogs(ctx context.Context, projectName string) error
|
||||
Logs(ctx context.Context, projectName string) error
|
||||
Ps(background context.Context, project *Project) ([]types.TaskStatus, error)
|
||||
|
||||
CreateSecret(ctx context.Context, secret types.Secret) (string, error)
|
||||
InspectSecret(ctx context.Context, id string) (types.Secret, error)
|
||||
ListSecrets(ctx context.Context) ([]types.Secret, error)
|
||||
DeleteSecret(ctx context.Context, id string, recover bool) error
|
||||
ComposePs(background context.Context, project *Project) ([]types.TaskStatus, error)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue