Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions api/client/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (cli *DockerCli) CmdComposeRun(args ...string) error {
Context: project.Context{
ComposeFiles: []string{*composeFile},
ProjectName: *projectName,
Autoremove: *rm,
},
ClientFactory: cli,
})
Expand All @@ -69,15 +70,15 @@ func (cli *DockerCli) CmdComposeRun(args ...string) error {
if err != nil {
return err
}
if status != 0 {
return Cli.StatusError{StatusCode: status}
}
if *rm {
opts := options.Delete{RemoveVolume: true}
if err = project.Delete(opts, service); err != nil {
return err
}
}
if status != 0 {
return Cli.StatusError{StatusCode: status}
}

return nil
}
Expand Down
48 changes: 42 additions & 6 deletions vendor/src/github.com/hyperhq/libcompose/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ import (
"os"
"strings"

"golang.org/x/net/context"

"github.com/Sirupsen/logrus"
"github.com/docker/engine-api/client"
"github.com/docker/engine-api/types"
"github.com/docker/engine-api/types/container"
"github.com/docker/go-connections/nat"
"github.com/hyperhq/hypercli/pkg/promise"
"github.com/hyperhq/hypercli/pkg/stdcopy"
"github.com/hyperhq/hypercli/pkg/stringid"
"github.com/hyperhq/hypercli/pkg/term"
"github.com/hyperhq/libcompose/config"
"github.com/hyperhq/libcompose/labels"
"github.com/hyperhq/libcompose/logger"
"github.com/hyperhq/libcompose/project"
"github.com/hyperhq/libcompose/project/events"
util "github.com/hyperhq/libcompose/utils"
"golang.org/x/net/context"
)

// Container holds information about a docker container and the service it is tied on.
Expand Down Expand Up @@ -325,12 +325,48 @@ func (c *Container) Run(ctx context.Context, imageName string, configOverride *c
return -1, err
}

exitedContainer, err := c.client.ContainerInspect(ctx, container.ID)
if err != nil {
return -1, err
var status int
// Attached mode
if c.service.context.Autoremove {
// Warn user if they detached us
js, err := c.client.ContainerInspect(ctx, container.ID)
if err != nil {
return -1, err
}
if js.State.Running == true || js.State.Paused == true {
logrus.Infof("Detached from %s, awaiting its termination in order to uphold \"--rm\".\n",
stringid.TruncateID(container.ID))
}

// Autoremove: wait for the container to finish, retrieve
// the exit code and remove the container
if status, err = c.client.ContainerWait(ctx, container.ID); err != nil {
return -1, err
}
exitedContainer, err := c.client.ContainerInspect(ctx, container.ID)
if err != nil {
return -1, err
}
status = exitedContainer.State.ExitCode
} else {
// No Autoremove: Simply retrieve the exit code
if !configOverride.Tty {
// In non-TTY mode, we can't detach, so we must wait for container exit
if status, err = c.client.ContainerWait(ctx, container.ID); err != nil {
return -1, err
}
} else {
// In TTY mode, there is a race: if the process dies too slowly, the state could
// be updated after the getExitCode call and result in the wrong exit code being reported
exitedContainer, err := c.client.ContainerInspect(ctx, container.ID)
if err != nil {
return -1, err
}
status = exitedContainer.State.ExitCode
}
}

return exitedContainer.State.ExitCode, nil
return status, nil
}

func holdHijackedConnection(tty bool, inputStream io.ReadCloser, outputStream, errorStream io.Writer, resp types.HijackedResponse) error {
Expand Down
2 changes: 2 additions & 0 deletions vendor/src/github.com/hyperhq/libcompose/project/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type Context struct {
LoggerFactory logger.Factory
IgnoreMissingConfig bool
Project *Project

Autoremove bool
}

func (c *Context) readComposeFiles() error {
Expand Down