зеркало из https://github.com/docker/compose-cli.git
Refactor ProjectName
This separate project name and service name for command `run` Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
Родитель
b560f0cbe9
Коммит
cef7a2d4ce
|
@ -71,7 +71,7 @@ type ConvertOptions struct {
|
||||||
|
|
||||||
// RunOptions options to execute compose run
|
// RunOptions options to execute compose run
|
||||||
type RunOptions struct {
|
type RunOptions struct {
|
||||||
Name string
|
Service string
|
||||||
Command []string
|
Command []string
|
||||||
Detach bool
|
Detach bool
|
||||||
AutoRemove bool
|
AutoRemove bool
|
||||||
|
|
|
@ -28,7 +28,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type composeOptions struct {
|
type composeOptions struct {
|
||||||
Name string
|
ProjectName string
|
||||||
DomainName string
|
DomainName string
|
||||||
WorkingDir string
|
WorkingDir string
|
||||||
ConfigPaths []string
|
ConfigPaths []string
|
||||||
|
@ -40,14 +40,14 @@ type composeOptions struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func addComposeCommonFlags(f *pflag.FlagSet, opts *composeOptions) {
|
func addComposeCommonFlags(f *pflag.FlagSet, opts *composeOptions) {
|
||||||
f.StringVarP(&opts.Name, "project-name", "p", "", "Project name")
|
f.StringVarP(&opts.ProjectName, "project-name", "p", "", "Project name")
|
||||||
f.StringVar(&opts.Format, "format", "", "Format the output. Values: [pretty | json]. (Default: pretty)")
|
f.StringVar(&opts.Format, "format", "", "Format the output. Values: [pretty | json]. (Default: pretty)")
|
||||||
f.BoolVarP(&opts.Quiet, "quiet", "q", false, "Only display IDs")
|
f.BoolVarP(&opts.Quiet, "quiet", "q", false, "Only display IDs")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *composeOptions) toProjectName() (string, error) {
|
func (o *composeOptions) toProjectName() (string, error) {
|
||||||
if o.Name != "" {
|
if o.ProjectName != "" {
|
||||||
return o.Name, nil
|
return o.ProjectName, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
options, err := o.toProjectOptions()
|
options, err := o.toProjectOptions()
|
||||||
|
@ -68,7 +68,7 @@ func (o *composeOptions) toProjectOptions() (*cli.ProjectOptions, error) {
|
||||||
cli.WithDotEnv,
|
cli.WithDotEnv,
|
||||||
cli.WithEnv(o.Environment),
|
cli.WithEnv(o.Environment),
|
||||||
cli.WithWorkingDirectory(o.WorkingDir),
|
cli.WithWorkingDirectory(o.WorkingDir),
|
||||||
cli.WithName(o.Name))
|
cli.WithName(o.ProjectName))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Command returns the compose command with its child commands
|
// Command returns the compose command with its child commands
|
||||||
|
|
|
@ -37,7 +37,7 @@ func convertCommand() *cobra.Command {
|
||||||
return runConvert(cmd.Context(), opts)
|
return runConvert(cmd.Context(), opts)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
convertCmd.Flags().StringVarP(&opts.Name, "project-name", "p", "", "Project name")
|
convertCmd.Flags().StringVarP(&opts.ProjectName, "project-name", "p", "", "Project name")
|
||||||
convertCmd.Flags().StringVar(&opts.WorkingDir, "workdir", "", "Work dir")
|
convertCmd.Flags().StringVar(&opts.WorkingDir, "workdir", "", "Work dir")
|
||||||
convertCmd.Flags().StringArrayVarP(&opts.ConfigPaths, "file", "f", []string{}, "Compose configuration files")
|
convertCmd.Flags().StringArrayVarP(&opts.ConfigPaths, "file", "f", []string{}, "Compose configuration files")
|
||||||
convertCmd.Flags().StringArrayVarP(&opts.Environment, "environment", "e", []string{}, "Environment variables")
|
convertCmd.Flags().StringArrayVarP(&opts.Environment, "environment", "e", []string{}, "Environment variables")
|
||||||
|
|
|
@ -36,7 +36,7 @@ func downCommand() *cobra.Command {
|
||||||
return runDown(cmd.Context(), opts)
|
return runDown(cmd.Context(), opts)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
downCmd.Flags().StringVarP(&opts.Name, "project-name", "p", "", "Project name")
|
downCmd.Flags().StringVarP(&opts.ProjectName, "project-name", "p", "", "Project name")
|
||||||
downCmd.Flags().StringVar(&opts.WorkingDir, "workdir", "", "Work dir")
|
downCmd.Flags().StringVar(&opts.WorkingDir, "workdir", "", "Work dir")
|
||||||
downCmd.Flags().StringArrayVarP(&opts.ConfigPaths, "file", "f", []string{}, "Compose configuration files")
|
downCmd.Flags().StringArrayVarP(&opts.ConfigPaths, "file", "f", []string{}, "Compose configuration files")
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ func runList(ctx context.Context, opts composeOptions) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
stackList, err := c.ComposeService().List(ctx, opts.Name)
|
stackList, err := c.ComposeService().List(ctx, opts.ProjectName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,10 +20,11 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/docker/compose-cli/api/client"
|
"github.com/docker/compose-cli/api/client"
|
||||||
"github.com/docker/compose-cli/api/compose"
|
"github.com/docker/compose-cli/api/compose"
|
||||||
"github.com/docker/compose-cli/formatter"
|
"github.com/docker/compose-cli/formatter"
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func logsCommand() *cobra.Command {
|
func logsCommand() *cobra.Command {
|
||||||
|
@ -35,7 +36,7 @@ func logsCommand() *cobra.Command {
|
||||||
return runLogs(cmd.Context(), opts, args)
|
return runLogs(cmd.Context(), opts, args)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
logsCmd.Flags().StringVarP(&opts.Name, "project-name", "p", "", "Project name")
|
logsCmd.Flags().StringVarP(&opts.ProjectName, "project-name", "p", "", "Project name")
|
||||||
logsCmd.Flags().StringVar(&opts.WorkingDir, "workdir", "", "Work dir")
|
logsCmd.Flags().StringVar(&opts.WorkingDir, "workdir", "", "Work dir")
|
||||||
logsCmd.Flags().StringArrayVarP(&opts.ConfigPaths, "file", "f", []string{}, "Compose configuration files")
|
logsCmd.Flags().StringArrayVarP(&opts.ConfigPaths, "file", "f", []string{}, "Compose configuration files")
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ import (
|
||||||
|
|
||||||
type runOptions struct {
|
type runOptions struct {
|
||||||
Name string
|
Name string
|
||||||
|
Service string
|
||||||
Command []string
|
Command []string
|
||||||
WorkingDir string
|
WorkingDir string
|
||||||
ConfigPaths []string
|
ConfigPaths []string
|
||||||
|
@ -48,7 +49,7 @@ func runCommand() *cobra.Command {
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
opts.Command = args[1:]
|
opts.Command = args[1:]
|
||||||
}
|
}
|
||||||
opts.Name = args[0]
|
opts.Service = args[0]
|
||||||
return runRun(cmd.Context(), opts)
|
return runRun(cmd.Context(), opts)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -68,14 +69,14 @@ func runRun(ctx context.Context, opts runOptions) error {
|
||||||
WorkingDir: opts.WorkingDir,
|
WorkingDir: opts.WorkingDir,
|
||||||
Environment: opts.Environment,
|
Environment: opts.Environment,
|
||||||
}
|
}
|
||||||
c, project, err := setup(ctx, projectOpts, []string{opts.Name})
|
c, project, err := setup(ctx, projectOpts, []string{opts.Service})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
originalServices := project.Services
|
originalServices := project.Services
|
||||||
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
||||||
return "", startDependencies(ctx, c, project, opts.Name)
|
return "", startDependencies(ctx, c, project, opts.Service)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -84,7 +85,7 @@ func runRun(ctx context.Context, opts runOptions) error {
|
||||||
project.Services = originalServices
|
project.Services = originalServices
|
||||||
// start container and attach to container streams
|
// start container and attach to container streams
|
||||||
runOpts := compose.RunOptions{
|
runOpts := compose.RunOptions{
|
||||||
Name: opts.Name,
|
Service: opts.Service,
|
||||||
Command: opts.Command,
|
Command: opts.Command,
|
||||||
Detach: opts.Detach,
|
Detach: opts.Detach,
|
||||||
AutoRemove: opts.Remove,
|
AutoRemove: opts.Remove,
|
||||||
|
|
|
@ -47,7 +47,7 @@ func upCommand(contextType string) *cobra.Command {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
upCmd.Flags().StringVarP(&opts.Name, "project-name", "p", "", "Project name")
|
upCmd.Flags().StringVarP(&opts.ProjectName, "project-name", "p", "", "Project name")
|
||||||
upCmd.Flags().StringVar(&opts.WorkingDir, "workdir", "", "Work dir")
|
upCmd.Flags().StringVar(&opts.WorkingDir, "workdir", "", "Work dir")
|
||||||
upCmd.Flags().StringArrayVarP(&opts.ConfigPaths, "file", "f", []string{}, "Compose configuration files")
|
upCmd.Flags().StringArrayVarP(&opts.ConfigPaths, "file", "f", []string{}, "Compose configuration files")
|
||||||
upCmd.Flags().StringArrayVarP(&opts.Environment, "environment", "e", []string{}, "Environment variables")
|
upCmd.Flags().StringArrayVarP(&opts.Environment, "environment", "e", []string{}, "Environment variables")
|
||||||
|
|
|
@ -21,11 +21,12 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/types"
|
"github.com/compose-spec/compose-go/types"
|
||||||
"github.com/docker/compose-cli/api/compose"
|
|
||||||
apitypes "github.com/docker/docker/api/types"
|
apitypes "github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
|
|
||||||
|
"github.com/docker/compose-cli/api/compose"
|
||||||
|
|
||||||
moby "github.com/docker/docker/pkg/stringid"
|
moby "github.com/docker/docker/pkg/stringid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -33,7 +34,7 @@ func (s *composeService) RunOneOffContainer(ctx context.Context, project *types.
|
||||||
originalServices := project.Services
|
originalServices := project.Services
|
||||||
var requestedService types.ServiceConfig
|
var requestedService types.ServiceConfig
|
||||||
for _, service := range originalServices {
|
for _, service := range originalServices {
|
||||||
if service.Name == opts.Name {
|
if service.Name == opts.Service {
|
||||||
requestedService = service
|
requestedService = service
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,11 +66,11 @@ func (p *proxy) Services(ctx context.Context, request *composev1.ComposeServices
|
||||||
/* FIXME need to create `docker service ls` command to re-introduce this feature
|
/* FIXME need to create `docker service ls` command to re-introduce this feature
|
||||||
for _, service := range services {
|
for _, service := range services {
|
||||||
response = append(response, &composev1.Service{
|
response = append(response, &composev1.Service{
|
||||||
Id: service.ID,
|
Id: service.ID,
|
||||||
Name: service.Name,
|
ProjectName: service.ProjectName,
|
||||||
Replicas: uint32(service.Replicas),
|
Replicas: uint32(service.Replicas),
|
||||||
Desired: uint32(service.Desired),
|
Desired: uint32(service.Desired),
|
||||||
Ports: service.Ports,
|
Ports: service.Ports,
|
||||||
})
|
})
|
||||||
}*/
|
}*/
|
||||||
return &composev1.ComposeServicesResponse{Services: response}, nil
|
return &composev1.ComposeServicesResponse{Services: response}, nil
|
||||||
|
|
Загрузка…
Ссылка в новой задаче