From cfbd963c3d6912f7150fbd44654479d25ea6d434 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Tue, 18 Aug 2020 09:40:57 +0200 Subject: [PATCH] Adjust commands to latest compose-go Signed-off-by: Nicolas De Loof --- aci/backend.go | 2 +- cli/cmd/compose/compose.go | 16 ++++++++++++++++ cli/cmd/compose/down.go | 13 ++++++++----- cli/cmd/compose/logs.go | 13 ++++++++----- cli/cmd/compose/ps.go | 13 ++++++++----- cli/cmd/compose/up.go | 13 ++++++++----- ecs/backend.go | 8 ++++---- example/backend.go | 1 + 8 files changed, 54 insertions(+), 25 deletions(-) diff --git a/aci/backend.go b/aci/backend.go index 275d7d911..982a1faf5 100644 --- a/aci/backend.go +++ b/aci/backend.go @@ -19,7 +19,6 @@ package aci import ( "context" "fmt" - "github.com/docker/api/secrets" "io" "net/http" "strconv" @@ -42,6 +41,7 @@ import ( "github.com/docker/api/context/cloud" "github.com/docker/api/context/store" "github.com/docker/api/errdefs" + "github.com/docker/api/secrets" ) const ( diff --git a/cli/cmd/compose/compose.go b/cli/cmd/compose/compose.go index f2afad296..b37a4ba67 100644 --- a/cli/cmd/compose/compose.go +++ b/cli/cmd/compose/compose.go @@ -18,6 +18,7 @@ package compose import ( "context" + "github.com/compose-spec/compose-go/cli" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -28,6 +29,21 @@ import ( "github.com/docker/api/errdefs" ) +type composeOptions struct { + Name string + WorkingDir string + ConfigPaths []string + Environment []string +} + +func (o *composeOptions) toProjectOptions() (*cli.ProjectOptions, error) { + return cli.NewProjectOptions(o.ConfigPaths, + cli.WithOsEnv, + cli.WithEnv(o.Environment), + cli.WithWorkingDirectory(o.WorkingDir), + cli.WithName(o.Name)) +} + // Command returns the compose command with its child commands func Command() *cobra.Command { command := &cobra.Command{ diff --git a/cli/cmd/compose/down.go b/cli/cmd/compose/down.go index 7389dadcc..56052f28f 100644 --- a/cli/cmd/compose/down.go +++ b/cli/cmd/compose/down.go @@ -20,18 +20,17 @@ import ( "context" "errors" - "github.com/compose-spec/compose-go/cli" "github.com/spf13/cobra" "github.com/docker/api/client" ) func downCommand() *cobra.Command { - opts := cli.ProjectOptions{} + opts := composeOptions{} downCmd := &cobra.Command{ Use: "down", RunE: func(cmd *cobra.Command, args []string) error { - return runDown(cmd.Context(), &opts) + return runDown(cmd.Context(), opts) }, } downCmd.Flags().StringVarP(&opts.Name, "project-name", "p", "", "Project name") @@ -41,7 +40,7 @@ func downCommand() *cobra.Command { return downCmd } -func runDown(ctx context.Context, opts *cli.ProjectOptions) error { +func runDown(ctx context.Context, opts composeOptions) error { c, err := client.New(ctx) if err != nil { return err @@ -52,5 +51,9 @@ func runDown(ctx context.Context, opts *cli.ProjectOptions) error { return errors.New("compose not implemented in current context") } - return composeService.Down(ctx, opts) + options, err := opts.toProjectOptions() + if err != nil { + return err + } + return composeService.Down(ctx, options) } diff --git a/cli/cmd/compose/logs.go b/cli/cmd/compose/logs.go index 84ddda0e3..aa22e63d5 100644 --- a/cli/cmd/compose/logs.go +++ b/cli/cmd/compose/logs.go @@ -21,18 +21,17 @@ import ( "errors" "os" - "github.com/compose-spec/compose-go/cli" "github.com/spf13/cobra" "github.com/docker/api/client" ) func logsCommand() *cobra.Command { - opts := cli.ProjectOptions{} + opts := composeOptions{} logsCmd := &cobra.Command{ Use: "logs", RunE: func(cmd *cobra.Command, args []string) error { - return runLogs(cmd.Context(), &opts) + return runLogs(cmd.Context(), opts) }, } logsCmd.Flags().StringVarP(&opts.Name, "project-name", "p", "", "Project name") @@ -42,7 +41,7 @@ func logsCommand() *cobra.Command { return logsCmd } -func runLogs(ctx context.Context, opts *cli.ProjectOptions) error { +func runLogs(ctx context.Context, opts composeOptions) error { c, err := client.New(ctx) if err != nil { return err @@ -53,5 +52,9 @@ func runLogs(ctx context.Context, opts *cli.ProjectOptions) error { return errors.New("compose not implemented in current context") } - return composeService.Logs(ctx, opts, os.Stdout) + options, err := opts.toProjectOptions() + if err != nil { + return err + } + return composeService.Logs(ctx, options, os.Stdout) } diff --git a/cli/cmd/compose/ps.go b/cli/cmd/compose/ps.go index ee152e233..109e31908 100644 --- a/cli/cmd/compose/ps.go +++ b/cli/cmd/compose/ps.go @@ -25,18 +25,17 @@ import ( "strings" "text/tabwriter" - "github.com/compose-spec/compose-go/cli" "github.com/spf13/cobra" "github.com/docker/api/client" ) func psCommand() *cobra.Command { - opts := cli.ProjectOptions{} + opts := composeOptions{} psCmd := &cobra.Command{ Use: "ps", RunE: func(cmd *cobra.Command, args []string) error { - return runPs(cmd.Context(), &opts) + return runPs(cmd.Context(), opts) }, } psCmd.Flags().StringVarP(&opts.Name, "project-name", "p", "", "Project name") @@ -46,7 +45,7 @@ func psCommand() *cobra.Command { return psCmd } -func runPs(ctx context.Context, opts *cli.ProjectOptions) error { +func runPs(ctx context.Context, opts composeOptions) error { c, err := client.New(ctx) if err != nil { return err @@ -57,7 +56,11 @@ func runPs(ctx context.Context, opts *cli.ProjectOptions) error { return errors.New("compose not implemented in current context") } - serviceList, err := composeService.Ps(ctx, opts) + options, err := opts.toProjectOptions() + if err != nil { + return err + } + serviceList, err := composeService.Ps(ctx, options) if err != nil { return err } diff --git a/cli/cmd/compose/up.go b/cli/cmd/compose/up.go index 91e7bf25b..0cd28e9cf 100644 --- a/cli/cmd/compose/up.go +++ b/cli/cmd/compose/up.go @@ -20,7 +20,6 @@ import ( "context" "errors" - "github.com/compose-spec/compose-go/cli" "github.com/spf13/cobra" "github.com/docker/api/client" @@ -28,11 +27,11 @@ import ( ) func upCommand() *cobra.Command { - opts := cli.ProjectOptions{} + opts := composeOptions{} upCmd := &cobra.Command{ Use: "up", RunE: func(cmd *cobra.Command, args []string) error { - return runUp(cmd.Context(), &opts) + return runUp(cmd.Context(), opts) }, } upCmd.Flags().StringVarP(&opts.Name, "project-name", "p", "", "Project name") @@ -44,7 +43,7 @@ func upCommand() *cobra.Command { return upCmd } -func runUp(ctx context.Context, opts *cli.ProjectOptions) error { +func runUp(ctx context.Context, opts composeOptions) error { c, err := client.New(ctx) if err != nil { return err @@ -56,6 +55,10 @@ func runUp(ctx context.Context, opts *cli.ProjectOptions) error { } return progress.Run(ctx, func(ctx context.Context) error { - return composeService.Up(ctx, opts) + options, err := opts.toProjectOptions() + if err != nil { + return err + } + return composeService.Up(ctx, options) }) } diff --git a/ecs/backend.go b/ecs/backend.go index a152f1a0e..4997ecb9c 100644 --- a/ecs/backend.go +++ b/ecs/backend.go @@ -69,16 +69,16 @@ func getEcsAPIService(ecsCtx store.EcsContext) (*ecsAPIService, error) { } return &ecsAPIService{ - ctx: ecsCtx, + ctx: ecsCtx, Region: ecsCtx.Region, - SDK: NewSDK(sess), + SDK: NewSDK(sess), }, nil } type ecsAPIService struct { - ctx store.EcsContext + ctx store.EcsContext Region string - SDK sdk + SDK sdk } func (a *ecsAPIService) ContainerService() containers.Service { diff --git a/example/backend.go b/example/backend.go index 2b2e9273a..9ddd0573a 100644 --- a/example/backend.go +++ b/example/backend.go @@ -31,6 +31,7 @@ import ( "github.com/docker/api/containers" "github.com/docker/api/context/cloud" "github.com/docker/api/errdefs" + "github.com/docker/api/secrets" ) type apiService struct {