mirror of
https://github.com/docker/compose.git
synced 2025-07-31 01:24:15 +02:00
use log API for containers we didn't attached to
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
038ea8441a
commit
2c12ad19db
@ -28,7 +28,6 @@ import (
|
|||||||
|
|
||||||
"github.com/compose-spec/compose-go/v2/types"
|
"github.com/compose-spec/compose-go/v2/types"
|
||||||
"github.com/docker/docker/api/types/filters"
|
"github.com/docker/docker/api/types/filters"
|
||||||
"golang.org/x/sync/errgroup"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *composeService) Start(ctx context.Context, projectName string, options api.StartOptions) error {
|
func (s *composeService) Start(ctx context.Context, projectName string, options api.StartOptions) error {
|
||||||
@ -52,18 +51,6 @@ func (s *composeService) start(ctx context.Context, projectName string, options
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// use an independent context tied to the errgroup for background attach operations
|
|
||||||
// the primary context is still used for other operations
|
|
||||||
// this means that once any attach operation fails, all other attaches are cancelled,
|
|
||||||
// but an attach failing won't interfere with the rest of the start
|
|
||||||
eg, attachCtx := errgroup.WithContext(ctx)
|
|
||||||
if listener != nil {
|
|
||||||
_, err := s.attach(attachCtx, project, listener, options.AttachTo)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var containers Containers
|
var containers Containers
|
||||||
containers, err := s.apiClient().ContainerList(ctx, containerType.ListOptions{
|
containers, err := s.apiClient().ContainerList(ctx, containerType.ListOptions{
|
||||||
Filters: filters.NewArgs(
|
Filters: filters.NewArgs(
|
||||||
@ -111,7 +98,7 @@ func (s *composeService) start(ctx context.Context, projectName string, options
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return eg.Wait()
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// getDependencyCondition checks if service is depended on by other services
|
// getDependencyCondition checks if service is depended on by other services
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"slices"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
@ -34,6 +35,7 @@ import (
|
|||||||
"github.com/eiannone/keyboard"
|
"github.com/eiannone/keyboard"
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *composeService) Up(ctx context.Context, project *types.Project, options api.UpOptions) error { //nolint:gocyclo
|
func (s *composeService) Up(ctx context.Context, project *types.Project, options api.UpOptions) error { //nolint:gocyclo
|
||||||
@ -205,11 +207,27 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// use an independent context tied to the errgroup for background attach operations
|
||||||
|
// the primary context is still used for other operations
|
||||||
|
// this means that once any attach operation fails, all other attaches are cancelled,
|
||||||
|
// but an attach failing won't interfere with the rest of the start
|
||||||
|
_, attachCtx := errgroup.WithContext(ctx)
|
||||||
|
containers, err := s.attach(attachCtx, project, printer.HandleEvent, options.Start.AttachTo)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
attached := make([]string, len(containers))
|
||||||
|
for i, ctr := range containers {
|
||||||
|
attached[i] = ctr.ID
|
||||||
|
}
|
||||||
|
|
||||||
monitor.withListener(func(event api.ContainerEvent) {
|
monitor.withListener(func(event api.ContainerEvent) {
|
||||||
if event.Type != api.ContainerEventStarted {
|
if event.Type != api.ContainerEventStarted {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if event.Restarting || event.Container.Labels[api.ContainerReplaceLabel] != "" {
|
if slices.Contains(attached, event.ID) {
|
||||||
|
return
|
||||||
|
}
|
||||||
eg.Go(func() error {
|
eg.Go(func() error {
|
||||||
ctr, err := s.apiClient().ContainerInspect(ctx, event.ID)
|
ctr, err := s.apiClient().ContainerInspect(ctx, event.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -227,7 +245,6 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
eg.Go(func() error {
|
eg.Go(func() error {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user