Adjust commands to latest compose-go

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2020-08-18 09:40:57 +02:00
parent 6e6a11aa73
commit cfbd963c3d
No known key found for this signature in database
GPG Key ID: 9858809D6F8F6E7E
8 changed files with 54 additions and 25 deletions

View File

@ -19,7 +19,6 @@ package aci
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/docker/api/secrets"
"io" "io"
"net/http" "net/http"
"strconv" "strconv"
@ -42,6 +41,7 @@ import (
"github.com/docker/api/context/cloud" "github.com/docker/api/context/cloud"
"github.com/docker/api/context/store" "github.com/docker/api/context/store"
"github.com/docker/api/errdefs" "github.com/docker/api/errdefs"
"github.com/docker/api/secrets"
) )
const ( const (

View File

@ -18,6 +18,7 @@ package compose
import ( import (
"context" "context"
"github.com/compose-spec/compose-go/cli"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -28,6 +29,21 @@ import (
"github.com/docker/api/errdefs" "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 // Command returns the compose command with its child commands
func Command() *cobra.Command { func Command() *cobra.Command {
command := &cobra.Command{ command := &cobra.Command{

View File

@ -20,18 +20,17 @@ import (
"context" "context"
"errors" "errors"
"github.com/compose-spec/compose-go/cli"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/api/client" "github.com/docker/api/client"
) )
func downCommand() *cobra.Command { func downCommand() *cobra.Command {
opts := cli.ProjectOptions{} opts := composeOptions{}
downCmd := &cobra.Command{ downCmd := &cobra.Command{
Use: "down", Use: "down",
RunE: func(cmd *cobra.Command, args []string) error { 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") downCmd.Flags().StringVarP(&opts.Name, "project-name", "p", "", "Project name")
@ -41,7 +40,7 @@ func downCommand() *cobra.Command {
return downCmd return downCmd
} }
func runDown(ctx context.Context, opts *cli.ProjectOptions) error { func runDown(ctx context.Context, opts composeOptions) error {
c, err := client.New(ctx) c, err := client.New(ctx)
if err != nil { if err != nil {
return err 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 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)
} }

View File

@ -21,18 +21,17 @@ import (
"errors" "errors"
"os" "os"
"github.com/compose-spec/compose-go/cli"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/api/client" "github.com/docker/api/client"
) )
func logsCommand() *cobra.Command { func logsCommand() *cobra.Command {
opts := cli.ProjectOptions{} opts := composeOptions{}
logsCmd := &cobra.Command{ logsCmd := &cobra.Command{
Use: "logs", Use: "logs",
RunE: func(cmd *cobra.Command, args []string) error { 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") logsCmd.Flags().StringVarP(&opts.Name, "project-name", "p", "", "Project name")
@ -42,7 +41,7 @@ func logsCommand() *cobra.Command {
return logsCmd return logsCmd
} }
func runLogs(ctx context.Context, opts *cli.ProjectOptions) error { func runLogs(ctx context.Context, opts composeOptions) error {
c, err := client.New(ctx) c, err := client.New(ctx)
if err != nil { if err != nil {
return err 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 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)
} }

View File

@ -25,18 +25,17 @@ import (
"strings" "strings"
"text/tabwriter" "text/tabwriter"
"github.com/compose-spec/compose-go/cli"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/api/client" "github.com/docker/api/client"
) )
func psCommand() *cobra.Command { func psCommand() *cobra.Command {
opts := cli.ProjectOptions{} opts := composeOptions{}
psCmd := &cobra.Command{ psCmd := &cobra.Command{
Use: "ps", Use: "ps",
RunE: func(cmd *cobra.Command, args []string) error { 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") psCmd.Flags().StringVarP(&opts.Name, "project-name", "p", "", "Project name")
@ -46,7 +45,7 @@ func psCommand() *cobra.Command {
return psCmd return psCmd
} }
func runPs(ctx context.Context, opts *cli.ProjectOptions) error { func runPs(ctx context.Context, opts composeOptions) error {
c, err := client.New(ctx) c, err := client.New(ctx)
if err != nil { if err != nil {
return err return err
@ -57,7 +56,11 @@ func runPs(ctx context.Context, opts *cli.ProjectOptions) error {
return errors.New("compose not implemented in current context") 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 { if err != nil {
return err return err
} }

View File

@ -20,7 +20,6 @@ import (
"context" "context"
"errors" "errors"
"github.com/compose-spec/compose-go/cli"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/docker/api/client" "github.com/docker/api/client"
@ -28,11 +27,11 @@ import (
) )
func upCommand() *cobra.Command { func upCommand() *cobra.Command {
opts := cli.ProjectOptions{} opts := composeOptions{}
upCmd := &cobra.Command{ upCmd := &cobra.Command{
Use: "up", Use: "up",
RunE: func(cmd *cobra.Command, args []string) error { 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") upCmd.Flags().StringVarP(&opts.Name, "project-name", "p", "", "Project name")
@ -44,7 +43,7 @@ func upCommand() *cobra.Command {
return upCmd return upCmd
} }
func runUp(ctx context.Context, opts *cli.ProjectOptions) error { func runUp(ctx context.Context, opts composeOptions) error {
c, err := client.New(ctx) c, err := client.New(ctx)
if err != nil { if err != nil {
return err 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 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)
}) })
} }

View File

@ -69,16 +69,16 @@ func getEcsAPIService(ecsCtx store.EcsContext) (*ecsAPIService, error) {
} }
return &ecsAPIService{ return &ecsAPIService{
ctx: ecsCtx, ctx: ecsCtx,
Region: ecsCtx.Region, Region: ecsCtx.Region,
SDK: NewSDK(sess), SDK: NewSDK(sess),
}, nil }, nil
} }
type ecsAPIService struct { type ecsAPIService struct {
ctx store.EcsContext ctx store.EcsContext
Region string Region string
SDK sdk SDK sdk
} }
func (a *ecsAPIService) ContainerService() containers.Service { func (a *ecsAPIService) ContainerService() containers.Service {

View File

@ -31,6 +31,7 @@ import (
"github.com/docker/api/containers" "github.com/docker/api/containers"
"github.com/docker/api/context/cloud" "github.com/docker/api/context/cloud"
"github.com/docker/api/errdefs" "github.com/docker/api/errdefs"
"github.com/docker/api/secrets"
) )
type apiService struct { type apiService struct {