Repository navigation
Add ps subcommand to list project containers - #141
Conversation
|
Sorry for the slow response! I wasn't able to work on open source for most of the summer, but I'm catching up now. This is a useful addition. One issue: the name fallback can include a container whose labels identify it as belonging to another project. Can you limit that fallback to containers without project labels? Please add coverage for project filtering, service filtering, and stopped containers. |
|
I added the fallback to limit to those without compose labels. Also added tests for project filtering, service filtering, and stopped containers. I also noticed up/down's pre-start/stop cleanup has the same issue in regards to labels. We can address that in a future PR. |
Lists the compose project's containers in an aligned NAME/IMAGE/STATUS/PORTS table, showing only running containers unless -a/--all is passed. Containers are matched primarily by the com.docker.compose.project/service labels stamped since Mcrich23#126 (reliable across naming modes), falling back to the candidate container names for containers created before the labels existed. Resolves the project through the shared ComposeProjectOptions (Mcrich23#138) and fails fast on unknown service names with the noSuchService contract Mcrich23#139 established for up.
A container labeled for a different project could be included when its name collided with one of our candidate names (e.g. project demo + service web-x produce the candidate demo-web-x, which is also the name project demo-web gives its service x). Labels are now authoritative whenever present; the candidate-name fallback applies only to containers without compose labels (created before Mcrich23#126 stamped them). Extracts the selection into ComposePs.select, generic over the container representation, with unit coverage for project filtering, service filtering, the unlabeled fallback, and stopped-container visibility with and without --all.
893a178 to
71051e9
Compare
|
I just rebased onto current main (resolved the subcommand-registration conflict with #142) — the September changes addressing your review are unchanged: labels-authoritative matching plus the requested coverage. |
ps (Mcrich23#141) established the rule — labels are authoritative; candidate names identify only unlabeled pre-label containers — as a private helper inside ComposePs. Promote it to the shared layer so every command resolves containers the same way: ComposeProject.ownsContainer answers project ownership (the write-side guard stop/remove paths need), and ServiceTarget.matches answers service-level matching built on it (what listing and exec-style lookups need). ps now delegates to ServiceTarget.matches; behavior is unchanged, and the rule's unit coverage moves with it.
ps (Mcrich23#141) established the rule — labels are authoritative; candidate names identify only unlabeled pre-label containers — as a private helper inside ComposePs. Promote it to the shared layer so every command resolves containers the same way: ComposeProject.ownsContainer answers project ownership (the write-side guard stop/remove paths need), and ServiceTarget.matches answers service-level matching built on it (what listing and exec-style lookups need). ps now delegates to ServiceTarget.matches; behavior is unchanged, and the rule's unit coverage moves with it.
Lists the compose project's containers in an aligned NAME/IMAGE/STATUS/PORTS table, showing only running containers unless -a/--all is passed. Containers are matched primarily by the com.docker.compose.project/service labels stamped since #126 (reliable across naming modes), falling back to the candidate container names for containers created before the labels existed.
Resolves the project through the shared ComposeProjectOptions (#138) and fails fast on unknown service names with the noSuchService contract #139 established for up.