1
0
Fork 0

Refactor: tried to refactor code

- move scripts to assets/scripts (and updated build)
 - put most logic into HaproxyConfigGenerator
 - created DockerLabelHandler for all label handling from previous code
 - added unit tests and fixtures to cover HaproxyConfigGenerator and DockerLabelHandler
 - added a Makefile with build (for docker build) and test targets
This commit is contained in:
till 2020-05-30 22:24:40 +02:00
parent 5f9eac4b8a
commit 08de132450
No known key found for this signature in database
GPG key ID: B119050E2EBA1DC5
21 changed files with 387 additions and 131 deletions

24
assets/scripts/swarm.py Normal file
View file

@ -0,0 +1,24 @@
import os
from easymapping import HaproxyConfigGenerator
# path = os.path.dirname(os.path.realpath(__file__))
with open("/tmp/.docker_data", 'r') as content_file:
lineList = content_file.readlines()
result = {
"customerrors": True if os.getenv("HAPROXY_CUSTOMERRORS") == "true" else False
}
if os.getenv("HAPROXY_PASSWORD"):
result["stats"] = {
"username": os.getenv("HAPROXY_USERNAME") if os.getenv("HAPROXY_USERNAME") else "admin",
"password": os.getenv("HAPROXY_PASSWORD"),
"port": os.getenv("HAPROXY_STATS_PORT") if os.getenv("HAPROXY_STATS_PORT") else "1936",
}
cfg = HaproxyConfigGenerator(result)
print(cfg.generate(lineList))
# print(jsonStr)