From 85922425d4e7a379cce9e19d437b2ba8b26afe3f Mon Sep 17 00:00:00 2001 From: Joao M Date: Fri, 2 Sep 2022 23:00:16 +0000 Subject: [PATCH] Changes in the Static object --- docs/static.md | 6 +++--- examples/static/{ => conf}/config.yml | 0 examples/static/docker-compose.yml | 2 +- src/functions/__init__.py | 2 +- src/main.py | 2 +- src/processor/__init__.py | 4 +++- 6 files changed, 9 insertions(+), 7 deletions(-) rename examples/static/{ => conf}/config.yml (100%) diff --git a/docs/static.md b/docs/static.md index b754982..6a35bda 100644 --- a/docs/static.md +++ b/docs/static.md @@ -53,19 +53,19 @@ easymapping: - domain:8181 ``` -Then map this file to `/etc/haproxy/easyconfig.yml` in your EasyHAProxy container as: +Then map this file to `/etc/haproxy/static/config.yml` in your EasyHAProxy container as: ```bash docker run -d \ --name easy-haproxy-container \ -v /var/run/docker.sock:/var/run/docker.sock \ - -v /my/config.yml:/etc/haproxy/easyconfig.yml + -v /my/static/:/etc/haproxy/static/ \ -e EASYHAPROXY_DISCOVER="static" \ # + Environment Variables \ -p 80:80 \ -p 443:443 \ -p 1936:1936 \ - --network easyhaproxy + --network easyhaproxy \ byjg/easy-haproxy ``` diff --git a/examples/static/config.yml b/examples/static/conf/config.yml similarity index 100% rename from examples/static/config.yml rename to examples/static/conf/config.yml diff --git a/examples/static/docker-compose.yml b/examples/static/docker-compose.yml index 90f9984..a69904d 100644 --- a/examples/static/docker-compose.yml +++ b/examples/static/docker-compose.yml @@ -7,7 +7,7 @@ services: haproxy: image: byjg/easy-haproxy volumes: - - ./config.yml:/etc/haproxy/easyconfig.yml + - ./conf/:/etc/haproxy/static/ - ./host1.local.pem:/certs/haproxy/host1.local.pem - /var/run/docker.sock:/var/run/docker.sock environment: diff --git a/src/functions/__init__.py b/src/functions/__init__.py index b3d6455..244b454 100644 --- a/src/functions/__init__.py +++ b/src/functions/__init__.py @@ -98,7 +98,7 @@ class Functions: class Consts: - easyhaproxy_config = "/etc/haproxy/easyconfig.yml" + easyhaproxy_config = "/etc/haproxy/static/config.yml" haproxy_config = "/etc/haproxy/haproxy.cfg" certs_letsencrypt = "/certs/letsencrypt" certs_haproxy = "/certs/haproxy" diff --git a/src/main.py b/src/main.py index fe733fe..da5f413 100644 --- a/src/main.py +++ b/src/main.py @@ -14,7 +14,7 @@ def start(): processor_obj.save_config(Consts.haproxy_config) processor_obj.save_certs(Consts.certs_haproxy) letsencrypt_certs_found = processor_obj.get_letsencrypt_hosts() - Functions.log(Functions.EASYHAPROXY_LOG, Functions.DEBUG, 'Found hosts: %s' % ", ".join(processor_obj.get_hosts())) # Needs to after save_config + Functions.log(Functions.EASYHAPROXY_LOG, Functions.DEBUG, 'Found hosts: %s' % ", ".join(processor_obj.get_hosts())) # Needs to run after save_config Functions.log(Functions.EASYHAPROXY_LOG, Functions.TRACE, 'Object Found: %s' % (processor_obj.get_parsed_object())) old_haproxy = None diff --git a/src/processor/__init__.py b/src/processor/__init__.py index eacebbd..3c17c6c 100644 --- a/src/processor/__init__.py +++ b/src/processor/__init__.py @@ -34,7 +34,7 @@ class ContainerEnv: class ProcessorInterface: - static_file = "/etc/haproxy/easyconfig.yml" + static_file = Consts.easyhaproxy_config def __init__(self, filename = None): self.filename = filename @@ -109,6 +109,8 @@ class Static(ProcessorInterface): def get_hosts(self): hosts = [] for object in self.get_parsed_object(): + if "hosts" not in object: + continue for host in object["hosts"].keys(): hosts.append("%s:%s" % (host, object["port"])) return hosts