outposts: check docker container ports match

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-06-25 11:54:35 +02:00
parent c9ad87d419
commit bb776c2710
1 changed files with 20 additions and 0 deletions

View File

@ -53,6 +53,21 @@ class DockerController(BaseController):
return True return True
return False return False
def _comp_ports(self, container: Container) -> bool:
"""Check that the container has the correct ports exposed. Return true if container needs
to be rebuilt."""
# {'6379/tcp': [{'HostIp': '127.0.0.1', 'HostPort': '6379'}]}
for port in self.deployment_ports:
key = f"{port.inner_port or port.port}/{port.protocol}"
if key not in container.ports:
return True
host_matching = False
for host_port in container.ports[key]:
host_matching = host_port.get("HostPort") == port.port
if not host_matching:
return True
return False
def _get_container(self) -> tuple[Container, bool]: def _get_container(self) -> tuple[Container, bool]:
container_name = f"authentik-proxy-{self.outpost.uuid.hex}" container_name = f"authentik-proxy-{self.outpost.uuid.hex}"
try: try:
@ -98,6 +113,11 @@ class DockerController(BaseController):
) )
self.down() self.down()
return self.up() return self.up()
# Check container's ports
if self._comp_ports(container):
self.logger.info("Container has mis-matched ports, re-creating...")
self.down()
return self.up()
# Check that container values match our values # Check that container values match our values
if self._comp_env(container): if self._comp_env(container):
self.logger.info("Container has outdated config, re-creating...") self.logger.info("Container has outdated config, re-creating...")