mirror of
https://github.com/docker/compose.git
synced 2025-07-25 22:54:54 +02:00
update compose-go and adopt NewProjectOptions and functional parameters
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
1a3c75fa29
commit
8582cb3928
@ -18,7 +18,7 @@ func ComposeCommand(dockerCli command.Cli) *cobra.Command {
|
|||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "compose",
|
Use: "compose",
|
||||||
}
|
}
|
||||||
opts := &cli.ProjectOptions{}
|
opts := &composeOptions{}
|
||||||
AddFlags(opts, cmd.Flags())
|
AddFlags(opts, cmd.Flags())
|
||||||
|
|
||||||
cmd.AddCommand(
|
cmd.AddCommand(
|
||||||
@ -42,12 +42,15 @@ func (o upOptions) LoadBalancerArn() *string {
|
|||||||
return &o.loadBalancerArn
|
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{
|
cmd := &cobra.Command{
|
||||||
Use: "convert",
|
Use: "convert",
|
||||||
RunE: WithAwsContext(dockerCli, func(ctx docker.AwsContext, backend *amazon.Backend, args []string) error {
|
RunE: WithAwsContext(dockerCli, func(ctx docker.AwsContext, backend *amazon.Backend, args []string) error {
|
||||||
opts := options.WithOsEnv()
|
opts, err := options.toProjectOptions()
|
||||||
project, err := cli.ProjectFromOptions(&opts)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
project, err := cli.ProjectFromOptions(opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -68,24 +71,32 @@ func ConvertCommand(dockerCli command.Cli, options *cli.ProjectOptions) *cobra.C
|
|||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpCommand(dockerCli command.Cli, options *cli.ProjectOptions) *cobra.Command {
|
func UpCommand(dockerCli command.Cli, options *composeOptions) *cobra.Command {
|
||||||
opts := upOptions{}
|
opts := upOptions{}
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "up",
|
Use: "up",
|
||||||
RunE: WithAwsContext(dockerCli, func(clusteropts docker.AwsContext, backend *amazon.Backend, args []string) error {
|
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", "", "")
|
cmd.Flags().StringVar(&opts.loadBalancerArn, "load-balancer", "", "")
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func PsCommand(dockerCli command.Cli, options *cli.ProjectOptions) *cobra.Command {
|
func PsCommand(dockerCli command.Cli, options *composeOptions) *cobra.Command {
|
||||||
opts := upOptions{}
|
opts := upOptions{}
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "ps",
|
Use: "ps",
|
||||||
RunE: WithAwsContext(dockerCli, func(ctx docker.AwsContext, backend *amazon.Backend, args []string) error {
|
RunE: WithAwsContext(dockerCli, func(clusteropts docker.AwsContext, backend *amazon.Backend, args []string) error {
|
||||||
status, err := backend.Ps(context.Background(), *options)
|
opts, err := options.toProjectOptions()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
status, err := backend.Ps(context.Background(), opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -105,23 +116,31 @@ type downOptions struct {
|
|||||||
DeleteCluster bool
|
DeleteCluster bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func DownCommand(dockerCli command.Cli, projectOpts *cli.ProjectOptions) *cobra.Command {
|
func DownCommand(dockerCli command.Cli, options *composeOptions) *cobra.Command {
|
||||||
opts := downOptions{}
|
opts := downOptions{}
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "down",
|
Use: "down",
|
||||||
RunE: WithAwsContext(dockerCli, func(ctx docker.AwsContext, backend *amazon.Backend, args []string) error {
|
RunE: WithAwsContext(dockerCli, func(clusteropts docker.AwsContext, backend *amazon.Backend, args []string) error {
|
||||||
return backend.Down(context.Background(), *projectOpts)
|
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")
|
cmd.Flags().BoolVar(&opts.DeleteCluster, "delete-cluster", false, "Delete cluster")
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func LogsCommand(dockerCli command.Cli, projectOpts *cli.ProjectOptions) *cobra.Command {
|
func LogsCommand(dockerCli command.Cli, options *composeOptions) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "logs [PROJECT NAME]",
|
Use: "logs [PROJECT NAME]",
|
||||||
RunE: WithAwsContext(dockerCli, func(clusteropts docker.AwsContext, backend *amazon.Backend, args []string) error {
|
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
|
return cmd
|
||||||
|
@ -5,7 +5,24 @@ import (
|
|||||||
"github.com/spf13/pflag"
|
"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.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.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))
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ require (
|
|||||||
github.com/bugsnag/panicwrap v1.2.0 // indirect
|
github.com/bugsnag/panicwrap v1.2.0 // indirect
|
||||||
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
|
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
|
||||||
github.com/cloudflare/cfssl v1.4.1 // 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/containerd v1.3.2 // indirect
|
||||||
github.com/containerd/continuity v0.0.0-20200413184840-d3ef23f19fbb // indirect
|
github.com/containerd/continuity v0.0.0-20200413184840-d3ef23f19fbb // indirect
|
||||||
github.com/docker/cli v0.0.0-20200130152716-5d0cf8839492
|
github.com/docker/cli v0.0.0-20200130152716-5d0cf8839492
|
||||||
|
@ -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-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 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-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/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/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=
|
github.com/containerd/containerd v1.3.0-beta.2.0.20190828155532-0293cbd26c69/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/docker/ecs-plugin/pkg/console"
|
"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)
|
name, err := b.projectName(options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -27,10 +27,10 @@ func (b *Backend) Down(ctx context.Context, options cli.ProjectOptions) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Backend) projectName(options cli.ProjectOptions) (string, error) {
|
func (b *Backend) projectName(options *cli.ProjectOptions) (string, error) {
|
||||||
name := options.Name
|
name := options.Name
|
||||||
if name == "" {
|
if name == "" {
|
||||||
project, err := cli.ProjectFromOptions(&options)
|
project, err := cli.ProjectFromOptions(options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -3,16 +3,13 @@ package backend
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/cli"
|
"github.com/compose-spec/compose-go/cli"
|
||||||
"github.com/docker/ecs-plugin/pkg/compose"
|
"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)
|
projectName, err := b.projectName(options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -13,10 +13,10 @@ import (
|
|||||||
"github.com/docker/ecs-plugin/pkg/console"
|
"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
|
name := options.Name
|
||||||
if name == "" {
|
if name == "" {
|
||||||
project, err := cli.ProjectFromOptions(&options)
|
project, err := cli.ProjectFromOptions(options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,8 @@ import (
|
|||||||
"github.com/docker/ecs-plugin/pkg/console"
|
"github.com/docker/ecs-plugin/pkg/console"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (b *Backend) Up(ctx context.Context, options cli.ProjectOptions) error {
|
func (b *Backend) Up(ctx context.Context, options *cli.ProjectOptions) error {
|
||||||
project, err := cli.ProjectFromOptions(&options)
|
project, err := cli.ProjectFromOptions(options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -9,14 +9,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type API interface {
|
type API interface {
|
||||||
Up(ctx context.Context, options cli.ProjectOptions) error
|
Up(ctx context.Context, options *cli.ProjectOptions) error
|
||||||
Down(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)
|
CreateContextData(ctx context.Context, params map[string]string) (contextData interface{}, description string, err error)
|
||||||
|
|
||||||
Convert(project *types.Project) (*cloudformation.Template, error)
|
Convert(project *types.Project) (*cloudformation.Template, error)
|
||||||
Logs(ctx context.Context, projectName cli.ProjectOptions) error
|
Logs(ctx context.Context, options *cli.ProjectOptions) error
|
||||||
Ps(background context.Context, options cli.ProjectOptions) ([]ServiceStatus, error)
|
Ps(background context.Context, options *cli.ProjectOptions) ([]ServiceStatus, error)
|
||||||
|
|
||||||
CreateSecret(ctx context.Context, secret Secret) (string, error)
|
CreateSecret(ctx context.Context, secret Secret) (string, error)
|
||||||
InspectSecret(ctx context.Context, id string) (Secret, error)
|
InspectSecret(ctx context.Context, id string) (Secret, error)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user