From 51b5e5258b7f229b3bb090f561d78e64ef2737f8 Mon Sep 17 00:00:00 2001 From: Gilles Filippini Date: Fri, 31 Jan 2025 22:52:48 +0100 Subject: [PATCH 1/4] Revert commit 142a159 to support python docker 5 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). --- test/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index 56cda49..2b1ab44 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -616,5 +616,5 @@ try: except docker.errors.ImageNotFound: pytest.exit("The docker image 'nginxproxy/nginx-proxy:test' is missing") -if Version(docker.__version__) < Version("7.0.0"): - pytest.exit("This test suite is meant to work with the python docker module v7.0.0 or later") +if Version(docker.__version__) < Version("5.0.0"): + pytest.exit("This test suite is meant to work with the python docker module v5.0.0 or later") From 6e80ae7bc61e0c30bfac84d7ddcf71b5df39be05 Mon Sep 17 00:00:00 2001 From: Gilles Filippini Date: Fri, 31 Jan 2025 22:59:01 +0100 Subject: [PATCH 2/4] ci: fix a few tests to support docker-compose v1 --- test/test_custom/test_location-per-vhost.yml | 2 +- test/test_custom/test_per-vhost.yml | 2 +- test/test_htpasswd/test_htpasswd-regex-virtual-host.yml | 2 +- test/test_logs/test_log-disabled.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_custom/test_location-per-vhost.yml b/test/test_custom/test_location-per-vhost.yml index dd46a21..676712c 100644 --- a/test/test_custom/test_location-per-vhost.yml +++ b/test/test_custom/test_location-per-vhost.yml @@ -27,4 +27,4 @@ services: - "83" environment: WEB_PORTS: "83" - VIRTUAL_HOST: ~^regex.*\.nginx-proxy\.example$ + VIRTUAL_HOST: ~^regex.*\.nginx-proxy\.example$$ diff --git a/test/test_custom/test_per-vhost.yml b/test/test_custom/test_per-vhost.yml index 8813d5e..3680358 100644 --- a/test/test_custom/test_per-vhost.yml +++ b/test/test_custom/test_per-vhost.yml @@ -27,4 +27,4 @@ services: - "83" environment: WEB_PORTS: "83" - VIRTUAL_HOST: ~^regex.*\.nginx-proxy\.example$ + VIRTUAL_HOST: ~^regex.*\.nginx-proxy\.example$$ diff --git a/test/test_htpasswd/test_htpasswd-regex-virtual-host.yml b/test/test_htpasswd/test_htpasswd-regex-virtual-host.yml index b47236a..ba9d9ef 100644 --- a/test/test_htpasswd/test_htpasswd-regex-virtual-host.yml +++ b/test/test_htpasswd/test_htpasswd-regex-virtual-host.yml @@ -5,4 +5,4 @@ services: - "80" environment: WEB_PORTS: "80" - VIRTUAL_HOST: ~^regex.*\.nginx-proxy\.example$ + VIRTUAL_HOST: ~^regex.*\.nginx-proxy\.example$$ diff --git a/test/test_logs/test_log-disabled.yml b/test/test_logs/test_log-disabled.yml index 9e116d7..14b8e8b 100644 --- a/test/test_logs/test_log-disabled.yml +++ b/test/test_logs/test_log-disabled.yml @@ -1,7 +1,7 @@ services: nginx-proxy: environment: - DISABLE_ACCESS_LOGS: true + DISABLE_ACCESS_LOGS: "true" web1: image: web From 117b9d6824b071e634dfb8033f17aa7bfcf21bb6 Mon Sep 17 00:00:00 2001 From: Gilles Filippini Date: Fri, 31 Jan 2025 23:00:20 +0100 Subject: [PATCH 3/4] ci: standalone compose file for proxy-host-network-mode This is to prevent the below error with docker-compose v1: ERROR: for nginx-proxy "host" network_mode is incompatible with port_bindings --- ...network-mode.yml => test_proxy-host-network-mode.base.yml} | 4 ++++ 1 file changed, 4 insertions(+) rename test/test_host-network-mode/{test_proxy-host-network-mode.yml => test_proxy-host-network-mode.base.yml} (76%) diff --git a/test/test_host-network-mode/test_proxy-host-network-mode.yml b/test/test_host-network-mode/test_proxy-host-network-mode.base.yml similarity index 76% rename from test/test_host-network-mode/test_proxy-host-network-mode.yml rename to test/test_host-network-mode/test_proxy-host-network-mode.base.yml index 283dcf5..1917d06 100644 --- a/test/test_host-network-mode/test_proxy-host-network-mode.yml +++ b/test/test_host-network-mode/test_proxy-host-network-mode.base.yml @@ -1,5 +1,9 @@ services: nginx-proxy: + image: nginxproxy/nginx-proxy:test + container_name: nginx-proxy + volumes: + - /var/run/docker.sock:/tmp/docker.sock:ro environment: HTTP_PORT: 8888 network_mode: host From 3aef5868fb343a8f1fba079e32d37bb94af2a9ee Mon Sep 17 00:00:00 2001 From: Gilles Filippini Date: Fri, 31 Jan 2025 23:26:01 +0100 Subject: [PATCH 4/4] ci: improve docker-compose error handling When docker_compose_up fails, the related containers may be partially created or running. We must run docker_compose_down to ensure proper cleansing. --- test/conftest.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index 2b1ab44..0fef112 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -310,6 +310,9 @@ def get_nginx_conf_from_container(container: Container) -> bytes: return conffile.read() +class DockerComposeException(Exception): + pass + def __prepare_and_execute_compose_cmd(compose_files: List[str], project_name: str, cmd: str): """ Prepare and execute the Docker Compose command with the provided compose files and project name. @@ -325,7 +328,7 @@ def __prepare_and_execute_compose_cmd(compose_files: List[str], project_name: st try: subprocess.check_output(shlex.split(compose_cmd.getvalue()), stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: - pytest.fail(f"Error while running '{compose_cmd.getvalue()}':\n{e.output}", pytrace=False) + raise DockerComposeException(f"Error while running '{compose_cmd.getvalue()}':\n{e.output}") def docker_compose_up(compose_files: List[str], project_name: str): @@ -334,7 +337,14 @@ def docker_compose_up(compose_files: List[str], project_name: str): """ if compose_files is None or len(compose_files) == 0: pytest.fail(f"No compose file passed to docker_compose_up", pytrace=False) - __prepare_and_execute_compose_cmd(compose_files, project_name, cmd="up --detach") + try: + __prepare_and_execute_compose_cmd(compose_files, project_name, cmd="up --detach") + except DockerComposeException as e: + try: + docker_compose_down(compose_files, project_name) + except: + pass + pytest.fail(str(e), pytrace=False) def docker_compose_down(compose_files: List[str], project_name: str):