mirror of
https://github.com/docker/compose.git
synced 2025-07-27 07:34:10 +02:00
Merge pull request #1544 from docker/race_condition
This commit is contained in:
commit
6941445868
@ -43,6 +43,9 @@ func (s *composeService) getContainers(ctx context.Context, project string, oneO
|
|||||||
f := filters.NewArgs(
|
f := filters.NewArgs(
|
||||||
projectFilter(project),
|
projectFilter(project),
|
||||||
)
|
)
|
||||||
|
if len(selectedServices) == 1 {
|
||||||
|
f.Add("label", fmt.Sprintf("%s=%s", serviceLabel, selectedServices[0]))
|
||||||
|
}
|
||||||
switch oneOff {
|
switch oneOff {
|
||||||
case oneOffOnly:
|
case oneOffOnly:
|
||||||
f.Add("label", fmt.Sprintf("%s=%s", oneoffLabel, "True"))
|
f.Add("label", fmt.Sprintf("%s=%s", oneoffLabel, "True"))
|
||||||
@ -57,7 +60,7 @@ func (s *composeService) getContainers(ctx context.Context, project string, oneO
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(selectedServices) > 0 {
|
if len(selectedServices) > 1 {
|
||||||
containers = containers.filter(isService(selectedServices...))
|
containers = containers.filter(isService(selectedServices...))
|
||||||
}
|
}
|
||||||
return containers, nil
|
return containers, nil
|
||||||
|
@ -337,16 +337,14 @@ func (s *composeService) connectContainerToNetwork(ctx context.Context, id strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *composeService) isServiceHealthy(ctx context.Context, project *types.Project, service string) (bool, error) {
|
func (s *composeService) isServiceHealthy(ctx context.Context, project *types.Project, service string) (bool, error) {
|
||||||
containers, err := s.apiClient.ContainerList(ctx, moby.ContainerListOptions{
|
containers, err := s.getContainers(ctx, project.Name, oneOffExclude, false, service)
|
||||||
Filters: filters.NewArgs(
|
|
||||||
projectFilter(project.Name),
|
|
||||||
serviceFilter(service),
|
|
||||||
),
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(containers) == 0 {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
for _, c := range containers {
|
for _, c := range containers {
|
||||||
container, err := s.apiClient.ContainerInspect(ctx, c.ID)
|
container, err := s.apiClient.ContainerInspect(ctx, c.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -355,10 +353,7 @@ func (s *composeService) isServiceHealthy(ctx context.Context, project *types.Pr
|
|||||||
if container.State == nil || container.State.Health == nil {
|
if container.State == nil || container.State.Health == nil {
|
||||||
return false, fmt.Errorf("container for service %q has no healthcheck configured", service)
|
return false, fmt.Errorf("container for service %q has no healthcheck configured", service)
|
||||||
}
|
}
|
||||||
switch container.State.Health.Status {
|
if container.State.Health.Status != moby.Healthy {
|
||||||
case "starting":
|
|
||||||
return false, nil
|
|
||||||
case "unhealthy":
|
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ func (s *composeService) Exec(ctx context.Context, project *types.Project, opts
|
|||||||
defer resp.Close()
|
defer resp.Close()
|
||||||
|
|
||||||
if opts.Tty {
|
if opts.Tty {
|
||||||
err := s.monitorTTySize(ctx, exec.ID, s.apiClient.ContainerExecResize)
|
s.monitorTTySize(ctx, exec.ID, s.apiClient.ContainerExecResize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -28,13 +28,13 @@ import (
|
|||||||
"github.com/docker/docker/pkg/signal"
|
"github.com/docker/docker/pkg/signal"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *composeService) monitorTTySize(ctx context.Context, container string, resize func(context.Context, string, moby.ResizeOptions) error) error {
|
func (s *composeService) monitorTTySize(ctx context.Context, container string, resize func(context.Context, string, moby.ResizeOptions) error) {
|
||||||
err := resize(ctx, container, moby.ResizeOptions{ // nolint:errcheck
|
err := resize(ctx, container, moby.ResizeOptions{ // nolint:errcheck
|
||||||
Height: uint(goterm.Height()),
|
Height: uint(goterm.Height()),
|
||||||
Width: uint(goterm.Width()),
|
Width: uint(goterm.Width()),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
sigchan := make(chan os.Signal, 1)
|
sigchan := make(chan os.Signal, 1)
|
||||||
@ -71,5 +71,4 @@ func (s *composeService) monitorTTySize(ctx context.Context, container string, r
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
@ -89,17 +89,15 @@ func (s *composeService) RunOneOffContainer(ctx context.Context, project *types.
|
|||||||
}
|
}
|
||||||
defer restore()
|
defer restore()
|
||||||
|
|
||||||
|
statusC, errC := s.apiClient.ContainerWait(context.Background(), oneoffContainer.ID, container.WaitConditionNextExit)
|
||||||
|
|
||||||
err = s.apiClient.ContainerStart(ctx, containerID, apitypes.ContainerStartOptions{})
|
err = s.apiClient.ContainerStart(ctx, containerID, apitypes.ContainerStartOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.monitorTTySize(ctx, containerID, s.apiClient.ContainerResize)
|
s.monitorTTySize(ctx, containerID, s.apiClient.ContainerResize)
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
statusC, errC := s.apiClient.ContainerWait(context.Background(), oneoffContainer.ID, container.WaitConditionNotRunning)
|
|
||||||
select {
|
select {
|
||||||
case status := <-statusC:
|
case status := <-statusC:
|
||||||
return int(status.StatusCode), nil
|
return int(status.StatusCode), nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user