providers/proxy: add traefik labels to outposts deployed with docker integration
This commit is contained in:
parent
7861e2e0bd
commit
0203d20759
|
@ -26,6 +26,9 @@ class DockerController(BaseController):
|
|||
super().__init__(outpost)
|
||||
self.client = from_env()
|
||||
|
||||
def _get_labels(self) -> Dict[str, str]:
|
||||
return {}
|
||||
|
||||
def _get_env(self) -> Dict[str, str]:
|
||||
return {
|
||||
"PASSBOOK_HOST": self.outpost.config.passbook_host,
|
||||
|
@ -61,6 +64,7 @@ class DockerController(BaseController):
|
|||
ports={x: x for _, x in self.deployment_ports.items()},
|
||||
environment=self._get_env(),
|
||||
network_mode="host" if settings.TEST else "bridge",
|
||||
labels=self._get_labels(),
|
||||
),
|
||||
True,
|
||||
)
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
"""Proxy Provider Docker Contoller"""
|
||||
from typing import Dict
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from passbook.outposts.controllers.docker import DockerController
|
||||
from passbook.outposts.models import Outpost
|
||||
from passbook.providers.proxy.models import ProxyProvider
|
||||
|
||||
|
||||
class ProxyDockerController(DockerController):
|
||||
|
@ -12,3 +16,14 @@ class ProxyDockerController(DockerController):
|
|||
"http": 4180,
|
||||
"https": 4443,
|
||||
}
|
||||
|
||||
def _get_labels(self) -> Dict[str, str]:
|
||||
hosts = []
|
||||
for proxy_provider in ProxyProvider.objects.filter(outpost__in=[self.outpost]):
|
||||
proxy_provider: ProxyProvider
|
||||
external_host_name = urlparse(proxy_provider.external_host)
|
||||
hosts.append(external_host_name)
|
||||
return {
|
||||
"traefik.frontend.rule": f"Host:{','.join(hosts)}",
|
||||
"traefik.port": "4180",
|
||||
}
|
||||
|
|
Reference in New Issue