mirror of https://github.com/docker/compose.git
Merge pull request #1383 from ulyssessouza/attach-dependencies
Add --attach-dependencies
This commit is contained in:
commit
b6192f35f4
|
@ -93,6 +93,8 @@ type CreateOptions struct {
|
|||
type StartOptions struct {
|
||||
// Attach will attach to service containers and send container logs and events
|
||||
Attach ContainerEventListener
|
||||
// Services passed in the command line to be started
|
||||
Services []string
|
||||
}
|
||||
|
||||
// StopOptions group options of the Stop API
|
||||
|
|
|
@ -51,22 +51,23 @@ type composeOptions struct {
|
|||
|
||||
type upOptions struct {
|
||||
*composeOptions
|
||||
Detach bool
|
||||
Environment []string
|
||||
removeOrphans bool
|
||||
forceRecreate bool
|
||||
noRecreate bool
|
||||
recreateDeps bool
|
||||
noStart bool
|
||||
noDeps bool
|
||||
cascadeStop bool
|
||||
exitCodeFrom string
|
||||
scale []string
|
||||
noColor bool
|
||||
noPrefix bool
|
||||
timeChanged bool
|
||||
timeout int
|
||||
noInherit bool
|
||||
Detach bool
|
||||
Environment []string
|
||||
removeOrphans bool
|
||||
forceRecreate bool
|
||||
noRecreate bool
|
||||
recreateDeps bool
|
||||
noStart bool
|
||||
noDeps bool
|
||||
cascadeStop bool
|
||||
exitCodeFrom string
|
||||
scale []string
|
||||
noColor bool
|
||||
noPrefix bool
|
||||
timeChanged bool
|
||||
timeout int
|
||||
noInherit bool
|
||||
attachDependencies bool
|
||||
}
|
||||
|
||||
func (opts upOptions) recreateStrategy() string {
|
||||
|
@ -156,8 +157,8 @@ func upCommand(p *projectOptions, contextType string) *cobra.Command {
|
|||
if opts.Build && opts.noBuild {
|
||||
return fmt.Errorf("--build and --no-build are incompatible")
|
||||
}
|
||||
if opts.cascadeStop && opts.Detach {
|
||||
return fmt.Errorf("--abort-on-container-exit and --detach are incompatible")
|
||||
if opts.Detach && (opts.attachDependencies || opts.cascadeStop) {
|
||||
return fmt.Errorf("--detach cannot be combined with --abort-on-container-exit or --attach-dependencies")
|
||||
}
|
||||
if opts.forceRecreate && opts.noRecreate {
|
||||
return fmt.Errorf("--force-recreate and --no-recreate are incompatible")
|
||||
|
@ -194,6 +195,7 @@ func upCommand(p *projectOptions, contextType string) *cobra.Command {
|
|||
flags.BoolVar(&opts.noDeps, "no-deps", false, "Don't start linked services.")
|
||||
flags.BoolVar(&opts.recreateDeps, "always-recreate-deps", false, "Recreate dependent containers. Incompatible with --no-recreate.")
|
||||
flags.BoolVarP(&opts.noInherit, "renew-anon-volumes", "V", false, "Recreate anonymous volumes instead of retrieving data from the previous containers.")
|
||||
flags.BoolVar(&opts.attachDependencies, "attach-dependencies", false, "Attach to dependent containers.")
|
||||
}
|
||||
|
||||
return upCmd
|
||||
|
@ -254,6 +256,10 @@ func runCreateStart(ctx context.Context, opts upOptions, services []string) erro
|
|||
return nil
|
||||
}
|
||||
|
||||
if opts.attachDependencies {
|
||||
services = nil
|
||||
}
|
||||
|
||||
if opts.Detach {
|
||||
return nil
|
||||
}
|
||||
|
@ -295,6 +301,7 @@ func runCreateStart(ctx context.Context, opts upOptions, services []string) erro
|
|||
Attach: func(event compose.ContainerEvent) {
|
||||
queue <- event
|
||||
},
|
||||
Services: services,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -31,8 +31,8 @@ import (
|
|||
"github.com/docker/docker/pkg/stdcopy"
|
||||
)
|
||||
|
||||
func (s *composeService) attach(ctx context.Context, project *types.Project, consumer compose.ContainerEventListener) (Containers, error) {
|
||||
containers, err := s.getContainers(ctx, project, oneOffExclude)
|
||||
func (s *composeService) attach(ctx context.Context, project *types.Project, consumer compose.ContainerEventListener, selectedServices []string) (Containers, error) {
|
||||
containers, err := s.getContainers(ctx, project, oneOffExclude, selectedServices)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ const (
|
|||
oneOffOnly
|
||||
)
|
||||
|
||||
func (s *composeService) getContainers(ctx context.Context, project *types.Project, oneOff oneOff) (Containers, error) {
|
||||
func (s *composeService) getContainers(ctx context.Context, project *types.Project, oneOff oneOff, selectedServices []string) (Containers, error) {
|
||||
var containers Containers
|
||||
f := filters.NewArgs(
|
||||
projectFilter(project.Name),
|
||||
|
@ -56,7 +56,10 @@ func (s *composeService) getContainers(ctx context.Context, project *types.Proje
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
containers = containers.filter(isService(project.ServiceNames()...))
|
||||
if len(selectedServices) == 0 {
|
||||
selectedServices = project.ServiceNames()
|
||||
}
|
||||
containers = containers.filter(isService(selectedServices...))
|
||||
return containers, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ import (
|
|||
)
|
||||
|
||||
func (s *composeService) Pause(ctx context.Context, project *types.Project) error {
|
||||
containers, err := s.getContainers(ctx, project, oneOffExclude)
|
||||
containers, err := s.getContainers(ctx, project, oneOffExclude, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ func (s *composeService) Pause(ctx context.Context, project *types.Project) erro
|
|||
}
|
||||
|
||||
func (s *composeService) UnPause(ctx context.Context, project *types.Project) error {
|
||||
containers, err := s.getContainers(ctx, project, oneOffExclude)
|
||||
containers, err := s.getContainers(ctx, project, oneOffExclude, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ import (
|
|||
)
|
||||
|
||||
func (s *composeService) Remove(ctx context.Context, project *types.Project, options compose.RemoveOptions) ([]string, error) {
|
||||
containers, err := s.getContainers(ctx, project, oneOffInclude)
|
||||
containers, err := s.getContainers(ctx, project, oneOffInclude, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ import (
|
|||
func (s *composeService) Start(ctx context.Context, project *types.Project, options compose.StartOptions) error {
|
||||
var containers Containers
|
||||
if options.Attach != nil {
|
||||
c, err := s.attach(ctx, project, options.Attach)
|
||||
c, err := s.attach(ctx, project, options.Attach, options.Services)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue