mirror of
https://github.com/docker/compose.git
synced 2025-07-23 05:34:36 +02:00
waitForContainer to ensure stopped before remove
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
abb2ddba88
commit
18059295f7
@ -21,11 +21,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/docker/compose/v2/pkg/api"
|
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/types"
|
"github.com/compose-spec/compose-go/types"
|
||||||
"github.com/docker/cli/cli/streams"
|
"github.com/docker/cli/cli/streams"
|
||||||
|
"github.com/docker/compose/v2/pkg/api"
|
||||||
moby "github.com/docker/docker/api/types"
|
moby "github.com/docker/docker/api/types"
|
||||||
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/pkg/ioutils"
|
"github.com/docker/docker/pkg/ioutils"
|
||||||
"github.com/docker/docker/pkg/stdcopy"
|
"github.com/docker/docker/pkg/stdcopy"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
@ -100,7 +100,10 @@ func (s *composeService) runInteractive(ctx context.Context, containerID string,
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case err := <-outputDone:
|
case err := <-outputDone:
|
||||||
return s.terminateRun(ctx, containerID, opts, err)
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return s.terminateRun(ctx, containerID, opts)
|
||||||
case err := <-inputDone:
|
case err := <-inputDone:
|
||||||
if _, ok := err.(term.EscapeError); ok {
|
if _, ok := err.(term.EscapeError); ok {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
@ -115,22 +118,18 @@ func (s *composeService) runInteractive(ctx context.Context, containerID string,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *composeService) terminateRun(ctx context.Context, containerID string, opts api.RunOptions, err error) (int, error) {
|
func (s *composeService) terminateRun(ctx context.Context, containerID string, opts api.RunOptions) (exitCode int, err error) {
|
||||||
if err != nil {
|
exitCh, errCh := s.apiClient.ContainerWait(ctx, containerID, container.WaitConditionNotRunning)
|
||||||
return 0, err
|
select {
|
||||||
}
|
case exit := <-exitCh:
|
||||||
inspect, err := s.apiClient.ContainerInspect(ctx, containerID)
|
exitCode = int(exit.StatusCode)
|
||||||
if err != nil {
|
case err = <-errCh:
|
||||||
return 0, err
|
return
|
||||||
}
|
|
||||||
exitCode := 0
|
|
||||||
if inspect.State != nil {
|
|
||||||
exitCode = inspect.State.ExitCode
|
|
||||||
}
|
}
|
||||||
if opts.AutoRemove {
|
if opts.AutoRemove {
|
||||||
err = s.apiClient.ContainerRemove(ctx, containerID, moby.ContainerRemoveOptions{})
|
err = s.apiClient.ContainerRemove(ctx, containerID, moby.ContainerRemoveOptions{})
|
||||||
}
|
}
|
||||||
return exitCode, err
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *composeService) prepareRun(ctx context.Context, project *types.Project, opts api.RunOptions) (string, error) {
|
func (s *composeService) prepareRun(ctx context.Context, project *types.Project, opts api.RunOptions) (string, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user