test: separate containers (contd)

This commit is contained in:
Nicolas Duchon 2024-12-22 21:09:56 +01:00
parent c6987b3ea0
commit 77978eab96
8 changed files with 60 additions and 19 deletions

View file

@ -353,7 +353,11 @@ def wait_for_nginxproxy_to_be_ready():
substring "Watching docker events"
"""
containers = docker_client.containers.list(filters={"ancestor": f"nginxproxy/nginx-proxy:{IMAGE_TAG}"})
if len(containers) != 1:
if len(containers) > 1:
logging.info(f"Too many running nginxproxy/nginx-proxy:{IMAGE_TAG} containers")
return
elif len(containers) == 0:
logging.info(f"No running nginxproxy/nginx-proxy:{IMAGE_TAG} container")
return
container = containers[0]
for line in container.logs(stream=True):
@ -387,7 +391,7 @@ def docker_compose_file(request):
if not os.path.isfile(docker_compose_file):
logging.error("Could not find any docker compose file named either '{0}.yml', '{0}.yaml' or 'docker-compose.yml'".format(request.module.__name__))
logging.debug(f"using docker compose file {docker_compose_file}")
logging.info(f"using docker compose file {docker_compose_file}")
return docker_compose_file

View file

@ -1,12 +1,10 @@
import docker
import os
import pytest
from packaging.version import Version
raw_version = docker.from_env().version()["Version"]
pytestmark = pytest.mark.skipif(
Version(raw_version) < Version("1.13"),
reason="Docker compose syntax v3 requires docker engine v1.13 or later (got {raw_version})"
os.environ.get("COMPOSE_PROFILES") == "separateContainers",
reason="This test does not need to run in separateContainers mode"
)

View file

@ -1,9 +1,13 @@
volumes:
nginx_conf_dockergen:
services:
nginx:
image: nginx
container_name: nginx
volumes:
- nginx_conf:/etc/nginx/conf.d:ro
- nginx_conf_dockergen:/etc/nginx/conf.d:ro
dockergen:
image: nginxproxy/docker-gen
@ -11,7 +15,7 @@ services:
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- ../../nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl
- nginx_conf:/etc/nginx/conf.d
- nginx_conf_dockergen:/etc/nginx/conf.d
web:
image: web
@ -21,6 +25,3 @@ services:
environment:
WEB_PORTS: 80
VIRTUAL_HOST: whoami.nginx.container.docker
volumes:
nginx_conf:

View file

@ -1,3 +1,4 @@
import os
import re
import subprocess
@ -147,6 +148,11 @@ def get_env(sut_container, var):
#
###############################################################################
pytestmark = pytest.mark.skipif(
condition = os.environ.get("COMPOSE_PROFILES") == "separateContainers",
reason = "DH parameters generation is not supported in separate containers mode"
)
def test_default_dhparam_is_ffdhe4096(docker_compose):
container_name="dh-default"
sut_container = docker_client.containers.get(container_name)

View file

@ -55,7 +55,7 @@ services:
image: nginxproxy/nginx-proxy:test
volumes:
- &dockerSocket /var/run/docker.sock:/tmp/docker.sock:ro
- &certs ./cert_selection:/etc/nginx/certs:ro
- &certs ./certs:/etc/nginx/certs:ro
sut-dockergen:
profiles:

View file

@ -15,6 +15,9 @@ services:
profiles:
- singleContainer
image: nginxproxy/nginx-proxy:test
ports:
- "8080:8080"
- "8443:8443"
volumes:
- &dockerSocket /var/run/docker.sock:/tmp/docker.sock:ro
- &certs ./certs:/etc/nginx/certs:ro
@ -39,6 +42,9 @@ services:
- separateContainers
container_name: nginx-proxy
image: nginx:alpine
ports:
- "8080:8080"
- "8443:8443"
volumes:
- *confVolume
- *certs

View file

@ -1,13 +1,38 @@
version: "3"
volumes:
nginx_conf:
services:
proxy:
sut:
profiles:
- singleContainer
image: nginxproxy/nginx-proxy:test
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./certs:/etc/nginx/certs:ro
- ./acme_root:/usr/share/nginx/html:ro
- &dockerSocket /var/run/docker.sock:/tmp/docker.sock:ro
- &certs ./certs:/etc/nginx/certs:ro
- &acmeRoot ./acme_root:/usr/share/nginx/html:ro
sut-dockergen:
profiles:
- separateContainers
image: nginxproxy/nginx-proxy:test-dockergen
volumes:
- &confVolume nginx_conf:/etc/nginx/conf.d
- *dockerSocket
- *certs
- *acmeRoot
sut-nginx:
profiles:
- separateContainers
container_name: nginx-proxy
image: nginx:alpine
volumes:
- *confVolume
- *certs
- *acmeRoot
labels:
- "com.github.nginx-proxy.nginx-proxy.nginx"
web1:
image: web

View file

@ -35,6 +35,7 @@ services:
image: nginx:alpine
volumes:
- *confVolume
networks: *nginxProxyNetworks
labels:
- "com.github.nginx-proxy.nginx-proxy.nginx"