Skip to content

test: support docker-compose v1 & debian bookworm #2584

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

Merged
merged 3 commits into from
Feb 9, 2025

Conversation

pini-gh
Copy link
Contributor

@pini-gh pini-gh commented Jan 31, 2025

Fix #2582 #2583 .

@pini-gh pini-gh changed the title Sopports docker-compose v1 and Debian bookwom (current stable) Sopport docker-compose v1 and Debian bookwom (current stable) Jan 31, 2025
@pini-gh pini-gh changed the title Sopport docker-compose v1 and Debian bookwom (current stable) Support docker-compose v1 and Debian bookwom (current stable) Jan 31, 2025
Copy link
Contributor

@SchoNie SchoNie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right there is something wrong with the cleanup logic if an exception occurs. I experienced the same thing no teardown happens and it leaves all ghost containers and networks. Especially in the host-network-mode tests like you also have. I had the same issue on KeyboardInterrupt but I had no time to dig into this. So thanks for also pointing this out.

My first investigation suspects is pytest.fail from L328 and L336
I think this exits the DockerComposer ContextManager and no _down teardown is executed.

But instead of doing docker_compose_down if an exception happens I would recommend to fix the ContextManager.

Sorry I cannot test this right now but my recommendations are:

  1. Change the pytest.fail from docker_compose_up and docker_compose_down to a logging.error
  2. Improve the compose function in the ContextManager with a try except block to make sure teardown happens. And also move the self. declarations up so we are sure they are set even if an exception occurs. (else they are None in _down)
    def compose(self, docker_compose_files: List[str], project_name: str):
        if docker_compose_files == self._docker_compose_files and project_name == self._project_name:
            return
        self._down()
        if docker_compose_files is None or project_name is None:
            return
        #Move these states to early top, because we are sure it is set. It never reached it on exception.         
        self._docker_compose_files = docker_compose_files
        self._project_name = project_name
        
        try:
            docker_compose_up(docker_compose_files, project_name)
            self._networks = connect_to_all_networks()
            wait_for_nginxproxy_to_be_ready()
            time.sleep(3)  # give time to containers to be ready

        except KeyboardInterrupt:
            logging.warning("KeyboardInterrupt detected! Cleaning up...")
            self._down()  # Always teardown
            raise  # Re-raise to allow pytest to exit cleanly

        except:
            logging.error(f"Docker Compose setup failed")
            self._down()  # Always teardown
            pytest.fail("Docker Compose setup failed")
  1. L487 self._docker_compose_file = None >> self._docker_compose_files = None (files)
  2. Should we make sure self._networks = [] is set in _down ?

@pini-gh
Copy link
Contributor Author

pini-gh commented Feb 1, 2025

Sorry I cannot test this right now but my recommendations are:

Well, take your time :)

As said before my Python skills are limited. I came up with my rudimentary fix, but I won't be able to do this the right way (tm) as easily as you would.

@buchdag buchdag linked an issue Feb 2, 2025 that may be closed by this pull request
@SchoNie
Copy link
Contributor

SchoNie commented Feb 5, 2025

I am working on this, but I have some new unexpected issues coming up.
In test_fallback the docker_compose_files is set in the parametrize test. Running all the different compose setups in 1 module scope without leaving the contextmanager, and essentially not stopping the compose projects.
This gives ghost containers as the services differ in the compose files.

@buchdag You refactored this a couple of months ago. Do you have a smart hint to solve this? I tried setting the docker_composer fixture to "function" scope which seems to work but huge performance impact.

Debian bookworm (current stable) still has python3-docker 5.0.3. The
reverted commit prevented the test-suite to run natively on this distro.

The version check could be bumped again when the next Debian stable (trixie)
will be released (by fall 2025 hopefully).
This is to prevent the below error with docker-compose v1:

ERROR: for nginx-proxy  "host" network_mode is incompatible with port_bindings
@pini-gh pini-gh force-pushed the pini-debian-docker branch from 3aef586 to ab49d65 Compare February 8, 2025 14:28
@buchdag
Copy link
Member

buchdag commented Feb 9, 2025

@SchoNie I had issues with the way things where setup in test_fallback too, I almost refactored it to avoid using a self defined docker_compose_files as I'm not certain it adds much. Unless I'm missing something I don't see why this test module would necessitate running multiple checks over multiple Docker Compose setups in one gigantic parameterized test case.

@pini-gh could we focus this PR on fixing the test suite on Debian / with Docker Compose v1 ? I think the error handling issue is a separate problem and should be handled in a separate PR, allowing this one to be merged.

@buchdag buchdag added the type/test PR that add missing tests or correct existing tests label Feb 9, 2025
@pini-gh pini-gh force-pushed the pini-debian-docker branch from ab49d65 to c1f1c85 Compare February 9, 2025 12:08
@buchdag
Copy link
Member

buchdag commented Feb 9, 2025

@pini-gh just to be sure, the PR in its current state fixes both #2582 and #2583 on your Debian running host ?

@buchdag buchdag changed the title Support docker-compose v1 and Debian bookwom (current stable) test: support docker-compose v1 & debian bookworm Feb 9, 2025
@pini-gh
Copy link
Contributor Author

pini-gh commented Feb 9, 2025

@pini-gh just to be sure, the PR in its current state fixes both #2582 and #2583 on your Debian running host ?

Yes

@buchdag buchdag merged commit 8f864e3 into nginx-proxy:main Feb 9, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/test PR that add missing tests or correct existing tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Please revert 142a159 - ci: bump python module docker version check Please keep the test suite compatible with docker-compose v1
3 participants