up: handle various attach use cases better #10910
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What I did
By default,
compose up
attaches to all services (i.e. shows log output from every associated container). If a service is specified, e.g.compose up foo
, then onlyfoo
's logs are tailed. The--attach-dependencies
flag can also be used, so that iffoo
depended uponbar
, thenbar
's logs would also be followed. It's also possible to use--no-attach
to filter out one or more services explicitly, e.g.compose up --no-attach=noisy
would launch all services, includingnoisy
, and would show log output from every service exceptnoisy
. Lastly, it's possible to useup --attach
to explicitly restrict to a subset of services (or their dependencies).How these flags interact with each other is also worth thinking through.
There were a few different connected issues here, but the primary issue was that running
compose up foo
was always attaching dependencies regardless of--attach-dependencies
.The filtering logic here has been updated so that it behaves predictably both when launching all services (
compose up
) or a subset (compose up foo
) as well as various flag combinations on top of those.Notably, this required making some changes to how it watches containers. The logic here between attaching for logs and monitoring for lifecycle changes is
tightly coupled, so some changes were needed to ensure that the full set of services being
up
'd are watched and the subset that should have logs shown are attached. (This does mean faking the attach with an event but not actually doing it.)While handling that, I adjusted the context lifetimes here, which improves error handling that gets shown to the user and should help avoid potential leaks by getting rid of a
context.Background()
.Related issue
Fixes:
(not mandatory) A picture of a cute animal, if possible in relation to what you did
