From 2ad61e6afa461fc5585c4470c57d6dc5a13f86bb Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Thu, 28 Jul 2022 19:50:07 +0100 Subject: [PATCH] Properly pass environment variables to the process --- .env | 3 +++ docker-compose.yml | 8 +++++--- threshold | 24 ++++++++++++++---------- 3 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..f46978d --- /dev/null +++ b/.env @@ -0,0 +1,3 @@ +THRESHOLD_LISTENER_PORT=13867 +THRESHOLD_RELAY_PORT=13868 +THRESHOLD_API_PORT=13869 diff --git a/docker-compose.yml b/docker-compose.yml index ea35296..9cb401e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,9 +7,11 @@ services: volumes: - .:/code ports: - - "13867:13867" - - "13868:13868" - - "13869:13869" + - "${THRESHOLD_LISTENER_PORT}:${THRESHOLD_LISTENER_PORT}" + - "${THRESHOLD_RELAY_PORT}:${THRESHOLD_RELAY_PORT}" + - "${THRESHOLD_API_PORT}:${THRESHOLD_API_PORT}" + env_file: + - .env # for development extra_hosts: - "host.docker.internal:host-gateway" diff --git a/threshold b/threshold index 5c9e032..edf71da 100755 --- a/threshold +++ b/threshold @@ -39,21 +39,25 @@ stdout = getwriter("utf8")(stdout) # this is a generic fix but we all know stderr = getwriter("utf8")(stderr) # it's just for the retards on Rizon using # unicode quit messages for no reason +trues = ('true', '1', 't', True) + # Main listener -listener_address = getenv("THRESHOLD_LISTENER_HOST") or main.config["Listener"]["Address"] -listener_port = int(getenv("THRESHOLD_LISTENER_PORT")) or main.config["Listener"]["Port"] -listener_ssl = int(getenv("THRESHOLD_LISTENER_SSL")) or main.config["Listener"]["UseSSL"] +listener_address = getenv("THRESHOLD_LISTENER_HOST", main.config["Listener"]["Address"]) +listener_port = int(getenv("THRESHOLD_LISTENER_PORT", main.config["Listener"]["Port"])) +listener_ssl = getenv("THRESHOLD_LISTENER_SSL", main.config["Listener"]["UseSSL"]) in trues # RelayAPI -relay_enabled = int(getenv("THRESHOLD_RELAY_ENABLED")) or main.config["Relay"]["Enabled"] -relay_address = getenv("THRESHOLD_RELAY_HOST") or main.config["RelayAPI"]["Address"] -relay_port = int(getenv("THRESHOLD_RELAY_PORT")) or main.config["RelayAPI"]["Port"] -relay_ssl = int(getenv("THRESHOLD_RELAY_SSL")) or main.config["RelayAPI"]["UseSSL"] +relay_enabled = getenv("THRESHOLD_RELAY_ENABLED", main.config["RelayAPI"]["Enabled"]) in trues +relay_address = getenv("THRESHOLD_RELAY_HOST", main.config["RelayAPI"]["Address"]) +relay_port = int(getenv("THRESHOLD_RELAY_PORT", main.config["RelayAPI"]["Port"])) +relay_ssl = getenv("THRESHOLD_RELAY_SSL", main.config["RelayAPI"]["UseSSL"]) in trues # Web API -api_enabled = int(getenv("THRESHOLD_API_ENABLED")) or main.config["API"]["Enabled"] -api_address = getenv("THRESHOLD_API_HOST") or main.config["API"]["Address"] -api_port = int(getenv("THRESHOLD_API_PORT")) or main.config["API"]["Port"] +api_enabled = getenv("THRESHOLD_API_ENABLED", main.config["API"]["Enabled"]) in trues +api_address = getenv("THRESHOLD_API_HOST", main.config["API"]["Address"]) +api_port = int(getenv("THRESHOLD_API_PORT", main.config["API"]["Port"])) +print("API PORT", api_port) +print("ENV PORT", getenv("THRESHOLD_API_PORT")) if __name__ == "__main__": listener = ServerFactory()