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" substring "Watching docker events"
""" """
containers = docker_client.containers.list(filters={"ancestor": f"nginxproxy/nginx-proxy:{IMAGE_TAG}"}) 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 return
container = containers[0] container = containers[0]
for line in container.logs(stream=True): for line in container.logs(stream=True):
@ -387,7 +391,7 @@ def docker_compose_file(request):
if not os.path.isfile(docker_compose_file): 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.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 return docker_compose_file

View file

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

View file

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

View file

@ -1,3 +1,4 @@
import os
import re import re
import subprocess 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): def test_default_dhparam_is_ffdhe4096(docker_compose):
container_name="dh-default" container_name="dh-default"
sut_container = docker_client.containers.get(container_name) sut_container = docker_client.containers.get(container_name)

View file

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

View file

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

View file

@ -1,13 +1,38 @@
version: "3" volumes:
nginx_conf:
services: services:
sut:
proxy: profiles:
- singleContainer
image: nginxproxy/nginx-proxy:test image: nginxproxy/nginx-proxy:test
volumes: volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro - &dockerSocket /var/run/docker.sock:/tmp/docker.sock:ro
- ./certs:/etc/nginx/certs:ro - &certs ./certs:/etc/nginx/certs:ro
- ./acme_root:/usr/share/nginx/html: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: web1:
image: web image: web

View file

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