1
0
mirror of https://github.com/thib8956/nginx-proxy synced 2025-02-24 09:48:14 +00:00

fix: Ensure networks are actually connected to pytest container

The `network` object would never be in a list of network names (strings), and without `greedy=True` arg as the `docker-py` API docs note, the containers will not be part of the results, thus always returning an empty list which was not intended..

Now the network will properly match the current networks for pytest container, avoiding duplicate connect attempts, and the network list result will actually have containers to count when filtering by length.
This commit is contained in:
polarathene 2021-12-31 22:30:49 +13:00
parent 0e5d97a268
commit 04b0181980

View File

@ -367,7 +367,7 @@ def connect_to_network(network):
return None return None
# make sure our container is connected to the nginx-proxy's network # make sure our container is connected to the nginx-proxy's network
if network not in my_networks: if network.name not in my_networks:
logging.info(f"Connecting to docker network: {network.name}") logging.info(f"Connecting to docker network: {network.name}")
network.connect(my_container) network.connect(my_container)
return network return network
@ -405,7 +405,7 @@ def connect_to_all_networks():
return [] return []
else: else:
# find the list of docker networks # find the list of docker networks
networks = [network for network in docker_client.networks.list() if len(network.containers) > 0 and network.name != 'bridge'] networks = [network for network in docker_client.networks.list(greedy=True) if len(network.containers) > 0 and network.name != 'bridge']
return [connect_to_network(network) for network in networks] return [connect_to_network(network) for network in networks]