Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2021-02-11 10:45:11 +01:00
parent d9fe745cc0
commit 8b90814de6
No known key found for this signature in database
GPG Key ID: 9858809D6F8F6E7E
4 changed files with 20 additions and 14 deletions

View File

@ -65,7 +65,7 @@ type CreateOptions struct {
// StartOptions group options of the Start API
type StartOptions struct {
// Attach will attach to service containers and pipe stdout/stderr to channel
// Attach will attach to service containers and send container logs and events
Attach ContainerEventListener
}

View File

@ -133,6 +133,13 @@ func runCreateStart(ctx context.Context, opts upOptions, services []string) erro
return err
}
if opts.exitCodeFrom != "" {
_, err := project.GetService(opts.exitCodeFrom)
if err != nil {
return err
}
}
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
err := c.ComposeService().Create(ctx, project, compose.CreateOptions{
RemoveOrphans: opts.removeOrphans,

View File

@ -30,20 +30,19 @@ func TestCascadeStop(t *testing.T) {
const projectName = "compose-e2e-logs"
t.Run("abort-on-container-exit", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-f", "./fixtures/cascade-stop-test/compose.yaml", "--project-name", projectName, "up", "--abort-on-container-exit")
res.Assert(t, icmd.Expected{Out: `/does_not_exist: No such file or directory`})
res.Assert(t, icmd.Expected{Out: `should_fail_1 exited with code 1`})
res.Assert(t, icmd.Expected{Out: `Aborting on container exit...`})
res.Assert(t, icmd.Expected{Out: `ERROR 1`})
res.Assert(t, icmd.Expected{ExitCode: 1})
res := c.RunDockerOrExitError("compose", "-f", "./fixtures/cascade-stop-test/compose.yaml", "--project-name", projectName, "up", "--abort-on-container-exit")
res.Assert(t, icmd.Expected{ExitCode: 1, Out: `should_fail_1 exited with code 1`})
res.Assert(t, icmd.Expected{ExitCode: 1, Out: `Aborting on container exit...`})
})
t.Run("exit-code-from", func(t *testing.T) {
res := c.RunDockerCmd("compose", "-f", "./fixtures/cascade-stop-test/compose.yaml", "--project-name", projectName, "up", "--exit-code-from=sleep")
res.Assert(t, icmd.Expected{Out: `/does_not_exist: No such file or directory`})
res.Assert(t, icmd.Expected{Out: `should_fail_1 exited with code 1`})
res.Assert(t, icmd.Expected{Out: `Aborting on container exit...`})
res.Assert(t, icmd.Expected{Out: `ERROR 143`})
res.Assert(t, icmd.Expected{ExitCode: 143})
res := c.RunDockerOrExitError("compose", "-f", "./fixtures/cascade-stop-test/compose.yaml", "--project-name", projectName, "up", "--exit-code-from=sleep")
res.Assert(t, icmd.Expected{ExitCode: 137, Out: `should_fail_1 exited with code 1`})
res.Assert(t, icmd.Expected{ExitCode: 137, Out: `Aborting on container exit...`})
})
t.Run("exit-code-from unknown", func(t *testing.T) {
res := c.RunDockerOrExitError("compose", "-f", "./fixtures/cascade-stop-test/compose.yaml", "--project-name", projectName, "up", "--exit-code-from=unknown")
res.Assert(t, icmd.Expected{ExitCode: 1, Err: `no such service: unknown`})
})
}

View File

@ -4,4 +4,4 @@ services:
command: ls /does_not_exist
sleep: # will be killed
image: busybox:1.27.2
command: sleep 10
command: ping localhost