compose/pkg/compose
Milas Bowman caad72713b up: handle various attach use cases better
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
only `foo`'s logs are tailed. The `--attach-dependencies`
flag can also be used, so that if `foo` depended upon
`bar`, then `bar`'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, including `noisy`, and would
show log output from every service _except_ `noisy`.
Lastly, it's possible to use `up --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()`.

Signed-off-by: Milas Bowman <milas.bowman@docker.com>
2023-08-18 12:38:38 +02:00
..
testdata prefer canonical `compose.yaml` file name 2021-06-22 11:23:57 +02:00
attach.go detect replacement container is created and inform printer so it attach and don't stop 2023-02-06 11:23:13 +01:00
build.go build: use correct values for proxy variables (#10908) 2023-08-17 14:25:28 -04:00
build_buildkit.go Improve buildkit node creation (#10843) 2023-08-03 15:11:16 -04:00
build_classic.go build: fix missing proxy build args for classic builder (#10887) 2023-08-10 08:57:28 -04:00
build_test.go prevent buildkt's progress to render `Building` when no built is needed 2023-05-26 15:04:37 +02:00
compose.go watch: batch & de-duplicate file events (#10865) 2023-08-03 14:53:02 -04:00
container.go lint: add `nolintlint` and clean up `nolint` directives (#9738) 2022-08-09 16:43:58 -04:00
containers.go when --index is not set select first service container 2023-07-07 14:08:24 +02:00
convergence.go up: do not warn on successful optional dependency complete (#10870) 2023-08-03 21:00:49 +00:00
convergence_test.go add support of depends_on.required attribute 2023-07-18 23:13:47 +02:00
convert.go Move compose v2 implementation under pkg/compose with dependencies 2021-06-15 15:52:48 +02:00
cp.go ci: upgrade to Go 1.20.5 and Moby v24.x 2023-06-07 10:41:49 -04:00
create.go warn user secret uid/gid/mode is not supported 2023-08-16 19:17:28 +02:00
create_test.go add support of depends_on.required attribute 2023-07-18 23:13:47 +02:00
dependencies.go add support of depends_on.required attribute 2023-07-18 23:13:47 +02:00
dependencies_test.go up should not silently ignore missing depends_on service 2023-05-26 21:59:29 +02:00
down.go detect network conflict as name is not guaranteed to be unique (#10612) 2023-05-31 14:46:23 -04:00
down_test.go ci: upgrade to Go 1.20.5 and Moby v24.x 2023-06-07 10:41:49 -04:00
envresolver.go config: case-insensitive env vars on Windows (#9438) 2022-08-02 14:56:09 -04:00
envresolver_test.go ci: remove uses of deprecated gotest.tools v2 (#9935) 2022-11-07 14:07:41 -05:00
errors.go Move compose v2 implementation under pkg/compose with dependencies 2021-06-15 15:52:48 +02:00
events.go detect new container from project have started when running `compose logs` with no explicit services 2023-05-26 14:15:48 +02:00
exec.go align cp command index management with exec command 2022-05-10 10:50:40 +02:00
filters.go detect network conflict as name is not guaranteed to be unique (#10612) 2023-05-31 14:46:23 -04:00
hash.go compute service hash with a default DeployConfig 2023-05-26 14:15:33 +02:00
hash_test.go service hash MUST exclude replicas 2022-12-21 08:45:41 +01:00
image_pruner.go fix local image removal when `compose down` is ran with `--project-name` (#10558) 2023-05-11 12:41:14 -04:00
images.go fix parsing of repository:tag 2022-12-14 09:23:07 +01:00
kill.go cli: option to write status messages on stdout (#10549) 2023-05-11 12:45:00 -04:00
kill_test.go ci: upgrade to Go 1.20.5 and Moby v24.x 2023-06-07 10:41:49 -04:00
logs.go e2e test to cover logs -f managing service being added/scaled 2023-05-26 14:51:23 +02:00
logs_test.go assume we receive logs by lines and don't ignore those without EOL 2023-06-07 10:40:37 +02:00
ls.go only consider containers with config_hash labels (i.e, created by compose) 2023-03-01 15:46:50 +01:00
ls_test.go Add unit tests for combinedConfigFiles logic 2022-02-18 16:37:35 +01:00
metrics.go Add gocritic to linters 2022-07-13 19:33:03 +02:00
pause.go cli: option to write status messages on stdout (#10549) 2023-05-11 12:45:00 -04:00
port.go when --index is not set select first service container 2023-07-07 14:08:24 +02:00
printer.go detect replacement container is created and inform printer so it attach and don't stop 2023-02-06 11:23:13 +01:00
ps.go don't filter by services if no filter was set 2023-01-09 11:49:08 +01:00
ps_test.go progress writer uses dockercli.Err stream 2023-03-15 09:47:13 +01:00
pull.go build: do not attempt to push unnamed service images 2023-07-19 09:58:37 +02:00
push.go cli: option to write status messages on stdout (#10549) 2023-05-11 12:45:00 -04:00
remove.go rm: remove debugging output (#10554) 2023-05-11 16:32:29 -04:00
restart.go add support of depends_on.required attribute 2023-07-18 23:13:47 +02:00
run.go pkg/compose: RunOneOffContainer: don't use NewStartOptions() 2023-07-19 12:13:40 +02:00
secrets.go check secret target is an absolute windows path 2023-07-19 10:57:22 +02:00
start.go up: handle various attach use cases better 2023-08-18 12:38:38 +02:00
stop.go cli: option to write status messages on stdout (#10549) 2023-05-11 12:45:00 -04:00
stop_test.go ci: upgrade to Go 1.20.5 and Moby v24.x 2023-06-07 10:41:49 -04:00
top.go project name MUST be lowercase 2022-04-13 09:49:01 +02:00
up.go trace: instrument `compose up` at a high-level 2023-07-19 11:26:12 +02:00
viz.go build: do not attempt to push unnamed service images 2023-07-19 09:58:37 +02:00
viz_test.go Fixed issue when project name contains dashes (`-`) 2023-04-24 12:18:37 +02:00
wait.go Add `docker compose wait` 2023-06-30 16:07:03 +02:00
watch.go watch: enable tar-based syncer by default (#10877) 2023-08-04 16:58:01 -04:00
watch_test.go watch: batch & de-duplicate file events (#10865) 2023-08-03 14:53:02 -04:00