diff --git a/ecs/cmd/commands/compose.go b/ecs/cmd/commands/compose.go index 75a9555f8..f4262fd4e 100644 --- a/ecs/cmd/commands/compose.go +++ b/ecs/cmd/commands/compose.go @@ -18,7 +18,7 @@ func ComposeCommand(dockerCli command.Cli) *cobra.Command { cmd := &cobra.Command{ Use: "compose", } - opts := &cli.ProjectOptions{} + opts := &composeOptions{} AddFlags(opts, cmd.Flags()) cmd.AddCommand( @@ -42,12 +42,15 @@ func (o upOptions) LoadBalancerArn() *string { return &o.loadBalancerArn } -func ConvertCommand(dockerCli command.Cli, options *cli.ProjectOptions) *cobra.Command { +func ConvertCommand(dockerCli command.Cli, options *composeOptions) *cobra.Command { cmd := &cobra.Command{ Use: "convert", RunE: WithAwsContext(dockerCli, func(ctx docker.AwsContext, backend *amazon.Backend, args []string) error { - opts := options.WithOsEnv() - project, err := cli.ProjectFromOptions(&opts) + opts, err := options.toProjectOptions() + if err != nil { + return err + } + project, err := cli.ProjectFromOptions(opts) if err != nil { return err } @@ -68,24 +71,32 @@ func ConvertCommand(dockerCli command.Cli, options *cli.ProjectOptions) *cobra.C return cmd } -func UpCommand(dockerCli command.Cli, options *cli.ProjectOptions) *cobra.Command { +func UpCommand(dockerCli command.Cli, options *composeOptions) *cobra.Command { opts := upOptions{} cmd := &cobra.Command{ Use: "up", RunE: WithAwsContext(dockerCli, func(clusteropts docker.AwsContext, backend *amazon.Backend, args []string) error { - return backend.Up(context.Background(), *options) + opts, err := options.toProjectOptions() + if err != nil { + return err + } + return backend.Up(context.Background(), opts) }), } cmd.Flags().StringVar(&opts.loadBalancerArn, "load-balancer", "", "") return cmd } -func PsCommand(dockerCli command.Cli, options *cli.ProjectOptions) *cobra.Command { +func PsCommand(dockerCli command.Cli, options *composeOptions) *cobra.Command { opts := upOptions{} cmd := &cobra.Command{ Use: "ps", - RunE: WithAwsContext(dockerCli, func(ctx docker.AwsContext, backend *amazon.Backend, args []string) error { - status, err := backend.Ps(context.Background(), *options) + RunE: WithAwsContext(dockerCli, func(clusteropts docker.AwsContext, backend *amazon.Backend, args []string) error { + opts, err := options.toProjectOptions() + if err != nil { + return err + } + status, err := backend.Ps(context.Background(), opts) if err != nil { return err } @@ -105,23 +116,31 @@ type downOptions struct { DeleteCluster bool } -func DownCommand(dockerCli command.Cli, projectOpts *cli.ProjectOptions) *cobra.Command { +func DownCommand(dockerCli command.Cli, options *composeOptions) *cobra.Command { opts := downOptions{} cmd := &cobra.Command{ Use: "down", - RunE: WithAwsContext(dockerCli, func(ctx docker.AwsContext, backend *amazon.Backend, args []string) error { - return backend.Down(context.Background(), *projectOpts) + RunE: WithAwsContext(dockerCli, func(clusteropts docker.AwsContext, backend *amazon.Backend, args []string) error { + opts, err := options.toProjectOptions() + if err != nil { + return err + } + return backend.Down(context.Background(), opts) }), } cmd.Flags().BoolVar(&opts.DeleteCluster, "delete-cluster", false, "Delete cluster") return cmd } -func LogsCommand(dockerCli command.Cli, projectOpts *cli.ProjectOptions) *cobra.Command { +func LogsCommand(dockerCli command.Cli, options *composeOptions) *cobra.Command { cmd := &cobra.Command{ Use: "logs [PROJECT NAME]", RunE: WithAwsContext(dockerCli, func(clusteropts docker.AwsContext, backend *amazon.Backend, args []string) error { - return backend.Logs(context.Background(), *projectOpts) + opts, err := options.toProjectOptions() + if err != nil { + return err + } + return backend.Logs(context.Background(), opts) }), } return cmd diff --git a/ecs/cmd/commands/opts.go b/ecs/cmd/commands/opts.go index bb63ec383..2124ca247 100644 --- a/ecs/cmd/commands/opts.go +++ b/ecs/cmd/commands/opts.go @@ -5,7 +5,24 @@ import ( "github.com/spf13/pflag" ) -func AddFlags(o *cli.ProjectOptions, flags *pflag.FlagSet) { +type composeOptions struct { + Name string + WorkingDir string + ConfigPaths []string + Environment []string +} + +func AddFlags(o *composeOptions, flags *pflag.FlagSet) { flags.StringArrayVarP(&o.ConfigPaths, "file", "f", nil, "Specify an alternate compose file") flags.StringVarP(&o.Name, "project-name", "n", "", "Specify an alternate project name (default: directory name)") + flags.StringVarP(&o.WorkingDir, "workdir", "w", "", "Working directory") + flags.StringSliceVarP(&o.Environment, "environment", "e", []string{}, "Environment variables") +} + +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)) } diff --git a/ecs/go.mod b/ecs/go.mod index aa1145ba2..f3e2949d5 100644 --- a/ecs/go.mod +++ b/ecs/go.mod @@ -14,7 +14,7 @@ require ( github.com/bugsnag/panicwrap v1.2.0 // indirect github.com/cenkalti/backoff v2.2.1+incompatible // indirect github.com/cloudflare/cfssl v1.4.1 // indirect - github.com/compose-spec/compose-go v0.0.0-20200710075715-6fcc35384ee1 + github.com/compose-spec/compose-go v0.0.0-20200716130117-e87e4f7839e3 github.com/containerd/containerd v1.3.2 // indirect github.com/containerd/continuity v0.0.0-20200413184840-d3ef23f19fbb // indirect github.com/docker/cli v0.0.0-20200130152716-5d0cf8839492 diff --git a/ecs/go.sum b/ecs/go.sum index 2d32a6692..296309a32 100644 --- a/ecs/go.sum +++ b/ecs/go.sum @@ -66,6 +66,8 @@ github.com/compose-spec/compose-go v0.0.0-20200709084333-492a50989a5a h1:pIiSz5j github.com/compose-spec/compose-go v0.0.0-20200709084333-492a50989a5a/go.mod h1:ArodJ6gsEB7iWKrbV3fSHZ08LlBvSVB0Oqg04fX86t4= github.com/compose-spec/compose-go v0.0.0-20200710075715-6fcc35384ee1 h1:F+YIkKDMHdgZBacawhFY1P9RAIgO+6uv2te6hjsjzF0= github.com/compose-spec/compose-go v0.0.0-20200710075715-6fcc35384ee1/go.mod h1:ArodJ6gsEB7iWKrbV3fSHZ08LlBvSVB0Oqg04fX86t4= +github.com/compose-spec/compose-go v0.0.0-20200716130117-e87e4f7839e3 h1:+ntlMTrEcScJjlnEOP8P1IIrusJaR93Eazr66YgUueA= +github.com/compose-spec/compose-go v0.0.0-20200716130117-e87e4f7839e3/go.mod h1:ArodJ6gsEB7iWKrbV3fSHZ08LlBvSVB0Oqg04fX86t4= github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f/go.mod h1:OApqhQ4XNSNC13gXIwDjhOQxjWa/NxkwZXJ1EvqT0ko= github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw= github.com/containerd/containerd v1.3.0-beta.2.0.20190828155532-0293cbd26c69/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA= diff --git a/ecs/pkg/amazon/backend/down.go b/ecs/pkg/amazon/backend/down.go index 31df94fca..fe89a9f2c 100644 --- a/ecs/pkg/amazon/backend/down.go +++ b/ecs/pkg/amazon/backend/down.go @@ -8,7 +8,7 @@ import ( "github.com/docker/ecs-plugin/pkg/console" ) -func (b *Backend) Down(ctx context.Context, options cli.ProjectOptions) error { +func (b *Backend) Down(ctx context.Context, options *cli.ProjectOptions) error { name, err := b.projectName(options) if err != nil { return err @@ -27,10 +27,10 @@ func (b *Backend) Down(ctx context.Context, options cli.ProjectOptions) error { return nil } -func (b *Backend) projectName(options cli.ProjectOptions) (string, error) { +func (b *Backend) projectName(options *cli.ProjectOptions) (string, error) { name := options.Name if name == "" { - project, err := cli.ProjectFromOptions(&options) + project, err := cli.ProjectFromOptions(options) if err != nil { return "", err } diff --git a/ecs/pkg/amazon/backend/list.go b/ecs/pkg/amazon/backend/list.go index 165241da9..59150314f 100644 --- a/ecs/pkg/amazon/backend/list.go +++ b/ecs/pkg/amazon/backend/list.go @@ -3,16 +3,13 @@ package backend import ( "context" "fmt" - "regexp" "strings" "github.com/compose-spec/compose-go/cli" "github.com/docker/ecs-plugin/pkg/compose" ) -var targetGroupLogicalName = regexp.MustCompile("(.*)(TCP|UDP)([0-9]+)TargetGroup") - -func (b *Backend) Ps(ctx context.Context, options cli.ProjectOptions) ([]compose.ServiceStatus, error) { +func (b *Backend) Ps(ctx context.Context, options *cli.ProjectOptions) ([]compose.ServiceStatus, error) { projectName, err := b.projectName(options) if err != nil { return nil, err diff --git a/ecs/pkg/amazon/backend/logs.go b/ecs/pkg/amazon/backend/logs.go index 00b8b2d4f..ef5c61e2f 100644 --- a/ecs/pkg/amazon/backend/logs.go +++ b/ecs/pkg/amazon/backend/logs.go @@ -13,10 +13,10 @@ import ( "github.com/docker/ecs-plugin/pkg/console" ) -func (b *Backend) Logs(ctx context.Context, options cli.ProjectOptions) error { +func (b *Backend) Logs(ctx context.Context, options *cli.ProjectOptions) error { name := options.Name if name == "" { - project, err := cli.ProjectFromOptions(&options) + project, err := cli.ProjectFromOptions(options) if err != nil { return err } diff --git a/ecs/pkg/amazon/backend/up.go b/ecs/pkg/amazon/backend/up.go index 6593f07b1..4bbe5bd06 100644 --- a/ecs/pkg/amazon/backend/up.go +++ b/ecs/pkg/amazon/backend/up.go @@ -13,8 +13,8 @@ import ( "github.com/docker/ecs-plugin/pkg/console" ) -func (b *Backend) Up(ctx context.Context, options cli.ProjectOptions) error { - project, err := cli.ProjectFromOptions(&options) +func (b *Backend) Up(ctx context.Context, options *cli.ProjectOptions) error { + project, err := cli.ProjectFromOptions(options) if err != nil { return err } diff --git a/ecs/pkg/compose/api.go b/ecs/pkg/compose/api.go index 66364703e..8e99b8ab6 100644 --- a/ecs/pkg/compose/api.go +++ b/ecs/pkg/compose/api.go @@ -9,14 +9,14 @@ import ( ) type API interface { - Up(ctx context.Context, options cli.ProjectOptions) error - Down(ctx context.Context, options cli.ProjectOptions) error + Up(ctx context.Context, options *cli.ProjectOptions) error + Down(ctx context.Context, options *cli.ProjectOptions) error CreateContextData(ctx context.Context, params map[string]string) (contextData interface{}, description string, err error) Convert(project *types.Project) (*cloudformation.Template, error) - Logs(ctx context.Context, projectName cli.ProjectOptions) error - Ps(background context.Context, options cli.ProjectOptions) ([]ServiceStatus, error) + Logs(ctx context.Context, options *cli.ProjectOptions) error + Ps(background context.Context, options *cli.ProjectOptions) ([]ServiceStatus, error) CreateSecret(ctx context.Context, secret Secret) (string, error) InspectSecret(ctx context.Context, id string) (Secret, error)