Skip to content

Commit 7c0d38c

Browse files
authored
Merge pull request nginx-proxy#1985 from hiqdev/networks-order
Make sure networks order is the same
2 parents cb82aad + 510d376 commit 7c0d38c

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

nginx.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ upstream {{ .Upstream }} {
105105
{{ end }}
106106
{{ end }}
107107
{{ range $knownNetwork := $networks }}
108-
{{ range $containerNetwork := $container.Networks }}
108+
{{ range $containerNetwork := sortObjectsByKeysAsc $container.Networks "Name" }}
109109
{{ if (and (ne $containerNetwork.Name "ingress") (or (eq $knownNetwork.Name $containerNetwork.Name) (eq $knownNetwork.Name "host"))) }}
110110
## Can be connected with "{{ $containerNetwork.Name }}" network
111111
{{ if $address }}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import pytest
2+
import logging
3+
import time
4+
5+
def test_forwards_to_web1(docker_compose, nginxproxy):
6+
r = nginxproxy.get("http://web1.nginx-proxy.local/port")
7+
assert r.status_code == 200
8+
assert r.text == "answer from port 81\n"
9+
10+
def test_nginx_config_remains_the_same_after_restart(docker_compose, nginxproxy):
11+
"""
12+
Restarts the Web container and returns nginx-proxy config after restart
13+
"""
14+
def get_conf_after_web_container_restart():
15+
web_containers = docker_compose.containers.list(filters={"ancestor": "web:latest"})
16+
assert len(web_containers) == 1
17+
web_containers[0].restart()
18+
time.sleep(3)
19+
20+
return nginxproxy.get_conf()
21+
22+
config_before_restart = nginxproxy.get_conf()
23+
24+
for i in range(1, 8):
25+
logging.info(f"Checking for the {i}-st time that config is the same")
26+
config_after_restart = get_conf_after_web_container_restart()
27+
if config_before_restart != config_after_restart:
28+
logging.debug(f"{config_before_restart!r} \n\n {config_after_restart!r}")
29+
pytest.fail("nginx-proxy config before and after restart of a web container does not match", pytrace=False)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: '2'
2+
3+
networks:
4+
net1: {}
5+
net2: {}
6+
net3: {}
7+
8+
services:
9+
nginx-proxy:
10+
image: nginxproxy/nginx-proxy:test
11+
volumes:
12+
- /var/run/docker.sock:/tmp/docker.sock:ro
13+
networks:
14+
- net1
15+
16+
web:
17+
image: web
18+
expose:
19+
- "81"
20+
environment:
21+
WEB_PORTS: 81
22+
VIRTUAL_HOST: web1.nginx-proxy.local
23+
networks:
24+
- net1
25+
- net2
26+
- net3

0 commit comments

Comments
 (0)