-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
introduce ability to select service to be stopped by compose down
#10552
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
pkg/compose/down.go
Outdated
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfortunately, even with this extracted into a func, cyclomatic complexity still is 17
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to checkSelectedServices
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
… and down Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 b005e88565d7
Volumes
$ 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 <nicolas.deloof@gmail.com>
@milas good point. We can rely on pushed abc9081 for this purpose:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥳
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 down
Related issue
closes #10230
require #10555
(not mandatory) A picture of a cute animal, if possible in relation to what you did