gabrieldemarmiesse / python-on-whales

An awesome Python wrapper for an awesome Docker CLI!
MIT License
537 stars 100 forks source link

Function docker.compose.down does not accept optional list of service names #570 #571

Closed MisterOwlPT closed 5 months ago

MisterOwlPT commented 5 months ago

Hi 😃

Here follow the proposed changes regarding issue #570. Now the following calls are possible:

from python_on_whales import docker

# ...

docker.compose.down(services=[])  # no-op - does nothing
docker.compose.down(services="a")  # stops service "a"
docker.compose.down(services=["b", "c"])  # stops services "b" and "c"
docker.compose.down()  # default - stops all services
MisterOwlPT commented 5 months ago

Hi @gabrieldemarmiesse,

I encountered a problem while submitting this PR. In essence, the tests I implemented are passing on my local machine but are failing inside the runner.

Initially I thought the tests were failing due to some unexpected service and container naming inside the runner and committed some extra "safety" changes that ended up not solving anything (I can revert these later). Upon investigating a bit further, I found that the CI/CD pipeline configuration enforces a specific version of the Docker Compose plugin (v2.15.1), which does not support service names on the down command.

For sanity check I tried running my tests on a brand new virtual machine provisioned with the exact same version of the Compose plugin as the runner.

# Inside VM - using same plugin version as runner
$ docker compose version
Docker Compose version v2.15.1

# Plugin does not support SERVICES
$ docker compose down --help
Usage:  docker compose down [OPTIONS]
Stop and remove containers, networks

Running my tests on said VM I was able to replicate the error (check below).

# Extracted from pytest command
Container alpine  Running
Container busybox  Running
unknown command "busybox" for "docker compose down"

Here is the output of docker info on my machine. You can see I am using a newer version of said plugin:

$ docker info
Client: Docker Engine - Community
 Version:    25.0.4
 ...
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.13.0
  compose: Docker Compose (Docker Inc.)
    Version:  v2.24.7

As this dependency constraint is beyond my control, I wanted to bring it to your attention. Is there a particular reason for using that version? Can it be upgraded?

gabrieldemarmiesse commented 5 months ago

You can upgrade the version in the CI to the latest one. We are pinning the version to make sure that we don't end up with failing tests because of automatic upgrade. So our CI is reproducible. Feel free to change the version in the bash file.

MisterOwlPT commented 5 months ago

Thanks for the feedback! I updated to the latest version (v2.26.0).

I also add to fix test test_config_complexe_compose as it was affected by the plugin version update (command config prints distinct outputs for field build.context).

# Using old version v2.15.1
$ docker compose -f tests/python_on_whales/components/complexe-compose.yml config
name: components
services:
  my_service:
    build:
      context: my_service_build
      dockerfile: Dockerfile
# Using latest version v2.26.0
$ docker compose -f tests/python_on_whales/components/complexe-compose.yml config
name: components
services:
  my_service:
    build:
      context: /home/ubuntu/python-on-whales/tests/python_on_whales/components/my_service_build
      dockerfile: Dockerfile

Now the tests are passing 😃