فهرست منبع

Adjust commands to latest compose-go

Signed-off-by: Nicolas De Loof <[email protected]>
Nicolas De Loof 5 سال پیش
والد
کامیت
cfbd963c3d
8فایلهای تغییر یافته به همراه54 افزوده شده و 25 حذف شده
  1. 1 1
      aci/backend.go
  2. 16 0
      cli/cmd/compose/compose.go
  3. 8 5
      cli/cmd/compose/down.go
  4. 8 5
      cli/cmd/compose/logs.go
  5. 8 5
      cli/cmd/compose/ps.go
  6. 8 5
      cli/cmd/compose/up.go
  7. 4 4
      ecs/backend.go
  8. 1 0
      example/backend.go

+ 1 - 1
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 (

+ 16 - 0
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{

+ 8 - 5
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)
 }

+ 8 - 5
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)
 }

+ 8 - 5
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
 	}

+ 8 - 5
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)
 	})
 }

+ 4 - 4
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 {

+ 1 - 0
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 {