diff --git a/api/compose/api.go b/api/compose/api.go index 3d3f063d1..417edd699 100644 --- a/api/compose/api.go +++ b/api/compose/api.go @@ -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 } diff --git a/cli/cmd/compose/up.go b/cli/cmd/compose/up.go index 537900e17..99719f43b 100644 --- a/cli/cmd/compose/up.go +++ b/cli/cmd/compose/up.go @@ -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, diff --git a/local/e2e/compose/cascade_stop_test.go b/local/e2e/compose/cascade_stop_test.go index 34c2e09a7..b25f54385 100644 --- a/local/e2e/compose/cascade_stop_test.go +++ b/local/e2e/compose/cascade_stop_test.go @@ -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`}) }) } diff --git a/local/e2e/compose/fixtures/cascade-stop-test/compose.yaml b/local/e2e/compose/fixtures/cascade-stop-test/compose.yaml index b6844afaa..5473670f7 100644 --- a/local/e2e/compose/fixtures/cascade-stop-test/compose.yaml +++ b/local/e2e/compose/fixtures/cascade-stop-test/compose.yaml @@ -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