compose/pkg/compose
Milas Bowman bc806da712 build: label built images for reliable cleanup on `down`
When running `compose down`, the `--rmi` flag can be passed,
which currently supports two values:
 * `local`: remove any _implicitly-named_ images that Compose
            built
 * `all`  : remove any named images (locally-built or fetched
            from a remote repo)

Removing images in the `local` case can be problematic, as it's
historically been done via a fair amount of inference over the
Compose model. Additionally, when using the "project-model"
(by passing `--project-name` instead of using a Compose file),
we're even more limited: if no containers for the project are
running, there's nothing to derive state from to perform the
inference on.

As a first pass, we started labeling _containers_ with the name
of the locally-built image associated with it (if any) in #9715.
Unfortunately, this still suffers from the aforementioned problems
around using actual state (i.e. the containers might no longer
exist) and meant that when operating in file mode (the default),
things did not behave as expected: the label is not available
in the project since it only exists at runtime.

Now, with these changes, Compose will label any images it builds
with project metadata. Upon cleanup during `down`, the engine
image API is queried for related images and matched up with the
services for the project. As a fallback for images built with
prior versions of Compose, the previous approach is still taken.

See also:
 * https://github.com/docker/compose/issues/9655
 * https://github.com/docker/compose/pull/9715

Signed-off-by: Milas Bowman <milas.bowman@docker.com>
2022-09-07 17:57:29 -04:00
..
testdata prefer canonical `compose.yaml` file name 2021-06-22 11:23:57 +02:00
attach.go Fix nolint issues 2022-07-13 19:33:06 +02:00
build.go build: label built images for reliable cleanup on `down` 2022-09-07 17:57:29 -04:00
build_buildkit.go build: label built images for reliable cleanup on `down` 2022-09-07 17:57:29 -04:00
build_classic.go build: label built images for reliable cleanup on `down` 2022-09-07 17:57:29 -04:00
compose.go build: label built images for reliable cleanup on `down` 2022-09-07 17:57:29 -04:00
container.go lint: add `nolintlint` and clean up `nolint` directives (#9738) 2022-08-09 16:43:58 -04:00
containers.go align cp command index management with exec command 2022-05-10 10:50:40 +02:00
convergence.go up/start/run: don't wait for disabled service 2022-08-17 12:32:10 -05:00
convergence_test.go prevent getCanonicalContainerName to crash 2022-03-07 14:58:39 +01:00
convert.go Move compose v2 implementation under pkg/compose with dependencies 2021-06-15 15:52:48 +02:00
cp.go Add "style" tag to gocritic 2022-07-13 19:33:06 +02:00
create.go create: pull all services logic out of loop; add DependsOn deps 2022-08-17 11:48:45 -05:00
create_test.go use '-' as separator by default for image name 2022-07-29 18:55:22 +02:00
dependencies.go fixed some spelling mistakes 2022-06-14 21:33:36 +02:00
dependencies_test.go lint: add `nolintlint` and clean up `nolint` directives (#9738) 2022-08-09 16:43:58 -04:00
down.go build: label built images for reliable cleanup on `down` 2022-09-07 17:57:29 -04:00
down_test.go build: label built images for reliable cleanup on `down` 2022-09-07 17:57:29 -04:00
envresolver.go config: case-insensitive env vars on Windows (#9438) 2022-08-02 14:56:09 -04:00
envresolver_test.go config: case-insensitive env vars on Windows (#9438) 2022-08-02 14:56:09 -04:00
errors.go Move compose v2 implementation under pkg/compose with dependencies 2021-06-15 15:52:48 +02:00
events.go project name MUST be lowercase 2022-04-13 09:49:01 +02:00
exec.go align cp command index management with exec command 2022-05-10 10:50:40 +02:00
filters.go move compose-cli code into docker/compose/v2 2021-08-31 19:09:19 +02:00
hash.go update usage strings for consistency 2022-08-02 13:32:29 +02:00
images.go project name MUST be lowercase 2022-04-13 09:49:01 +02:00
kill.go Apply compose model on `compose kill`, add `--remove-orphans` 2022-08-19 04:26:08 +02:00
kill_test.go build: label built images for reliable cleanup on `down` 2022-09-07 17:57:29 -04:00
logs.go lint: add `nolintlint` and clean up `nolint` directives (#9738) 2022-08-09 16:43:58 -04:00
ls.go Add gocritic to linters 2022-07-13 19:33:03 +02: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 if command is ran with a compose file, apply the compose model, not just project name 2022-08-02 22:33:26 +02:00
port.go project name MUST be lowercase 2022-04-13 09:49:01 +02:00
printer.go Only capture exit codes from `exit` events 2022-08-28 21:01:40 +02:00
ps.go Filter `compose ps` output by provided compose model 2022-08-02 22:33:26 +02:00
ps_test.go Filter `compose ps` output by provided compose model 2022-08-02 22:33:26 +02:00
pull.go Pull image regardless of whether it exists locally if `tag=latest` 2022-08-23 16:57:40 +02:00
push.go composeService to use dockerCli's In/Out/Err streams 2022-03-03 16:34:57 +01:00
remove.go if command is ran with a compose file, apply the compose model, not just project name 2022-08-02 22:33:26 +02:00
restart.go if command is ran with a compose file, apply the compose model, not just project name 2022-08-02 22:33:26 +02:00
run.go config: case-insensitive env vars on Windows (#9438) 2022-08-02 14:56:09 -04:00
secrets.go Add "opinionated" tag to gocritic 2022-07-13 19:33:06 +02:00
start.go Use appropriate dependency condition for one-shot containers when running `compose up --wait` 2022-06-18 01:20:40 +02:00
stop.go if command is ran with a compose file, apply the compose model, not just project name 2022-08-02 22:33:26 +02:00
stop_test.go if command is ran with a compose file, apply the compose model, not just project name 2022-08-02 22:33:26 +02:00
top.go project name MUST be lowercase 2022-04-13 09:49:01 +02:00
up.go up: do not stop dependency containers (#9701) 2022-08-02 15:25:59 -04:00