introduce ability to select service to be stopped by compose down#10552
introduce ability to select service to be stopped by compose down#10552
compose down#10552Conversation
glours
left a comment
There was a problem hiding this comment.
LGTM, I think you need to update the doc also
370590e to
d1f890f
Compare
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## v2 #10552 +/- ##
==========================================
+ Coverage 59.45% 59.57% +0.12%
==========================================
Files 107 107
Lines 9364 9437 +73
==========================================
+ Hits 5567 5622 +55
- Misses 3220 3239 +19
+ Partials 577 576 -1
☔ View full report in Codecov by Sentry. |
milas
left a comment
There was a problem hiding this comment.
Current code looks like a good starting point, but I think we'll have some special cases to look at.
For example:
services:
a:
image: nginx
b:
image: nginx
depends_on: [a]First, docker compose down b will fail because it'll try to remove the network:
❯ ~/dev/compose/bin/build/docker-compose up -d && ~/dev/compose/bin/build/docker-compose down b
[+] Building 0.0s (0/0)
[+] Running 2/2
✔ Container network-a-1 Running 0.0s
✔ Container network-b-1 Started 0.4s
[+] Running 2/1
✔ Container network-b-1 Removed 0.1s
✘ Network network_default Error 0.0s
failed to remove network network_default: Error response from daemon: error while removing network: network network_default id 0a59b1a2a52def0193fd82617668d734ebfb33fc433cf80862e1db012c44ee1f has active endpoints
But also, what should happen if you docker compose down a? Currently, it'll just stop a even though b depends upon it 🤔
yes, this is why this PR depends on #10555
good point. For symmetry with |
|
#10555 has been merged 🎉 implemented complimentary support for dependent services, walking the dependency graph from specified service nodes (actually walking the whole graph, but skipping nodes which aren't relevant for requested operation) I haven't introduced |
7591270 to
d6aad14
Compare
| // Check requested services exists in model | ||
| var services []string | ||
| for _, service := range options.Services { | ||
| _, err := project.GetService(service) | ||
| if err != nil { | ||
| if options.Project != nil { | ||
| // ran with an explicit compose.yaml file, so we should not ignore | ||
| return err | ||
| } | ||
| } else { | ||
| services = append(services, service) | ||
| } | ||
| } | ||
| options.Services = services |
There was a problem hiding this comment.
Can we extract this as a function, this way we won't need the //nolint:gocyclo and will make this code reusable elsewhere? WDYT?
There was a problem hiding this comment.
unfortunately, even with this extracted into a func, cyclomatic complexity still is 17
There was a problem hiding this comment.
moved to checkSelectedServices
Signed-off-by: Nicolas De Loof <[email protected]>
… and down Signed-off-by: Nicolas De Loof <[email protected]>
milas
left a comment
There was a problem hiding this comment.
No issues with the code as-is, and stopping a service is depended upon by other services properly brings those down as well.
Volumes and --rmi flag are problematic, however:
name: pr10552
services:
parent:
image: nginx
volumes:
- aa:/a
child:
depends_on: [parent]
image: nginx
volumes:
- aa:/a
- bb:/b
other:
image: nginx
volumes:
- bb:/b
volumes:
aa:
bb:Assume you've run compose up --wait first:
Images
$ compose down other --rmi=all
[+] Running 2/1
✔ Container pr10552-other-1 Removed 0.1s
⠋ Image nginx:latest Removing 0.0s
! Network pr10552_default Resource is still in use 0.0s
Error response from daemon: conflict: unable to remove repository reference "nginx:latest" (must force) - container 9e9979562577 is using its referenced image b005e88565d7Volumes
$ compose down child --volumes
[+] Running 3/1
✔ Container pr10552-child-1 Removed 0.1s
✔ Volume pr10552_bb Removed 0.0s
⠋ Volume pr10552_aa Removing 0.0s
! Network pr10552_default Resource is still in use 0.0s
Error response from daemon: remove pr10552_aa: volume is in use - [8199008ae17b920f984648b9d3f03bbd620c052007157413a0a7a4d8ae37ed2c]For now, what do you think about blocking the usage of the --rmi and --volumes flags if len(services) != 0?
Signed-off-by: Nicolas De Loof <[email protected]>
|
@milas good point. We can rely on pushed abc9081 for this purpose: |
|
I just tried out v2.19.0. This feature is waaay cool. I really like the way it takes account of container dependency chains and cleans up dangling networks. 👏👏👏👏👏 |
What I did
introduce ability to select service to be stopped by
compose downRelated issue
closes #10230
require #10555
(not mandatory) A picture of a cute animal, if possible in relation to what you did