From 1f8d168ae8df67463f7c0a7e48bf116116efc7b9 Mon Sep 17 00:00:00 2001 From: 8cH9azbsFifZ Date: Fri, 17 Nov 2023 20:21:09 +0100 Subject: [PATCH] env var config --- CHANGELOG.md | 1 + Dockerfile | 16 ++++++++++++++++ config.py | 24 ++++++++++++------------ docker-compose.yml | 14 ++++++++++++++ 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e171c7..0de202d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +0.0.10 - environment variable config 0.0.9 - add versioned json output 0.0.8 - move json duration string to mopp module (pip) 0.0.7 - topic for durations array diff --git a/Dockerfile b/Dockerfile index 9973c73..b638d98 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,4 +8,20 @@ ADD requirements-test.txt . RUN pip3 install -r requirements-test.txt ADD *.py /app/ +# Configuration for UDP connections +ENV SERVER_IP "mopp_chat_server" +ENV UDP_PORT "7373" + +# Configuration for Chat Server +ENV CLIENT_TIMEOUT "300" +ENV MAX_CLIENTS "100" +ENV KEEPALIVE "10" +ENV CHAT_WPM "20" + +# MQTT configuration +ENV MQTT_HOST "broker.hivemq.com" +ENV MQTT_PORT "1883" +ENV MQTT_TOPIC "/moip/udp2mqtt/durations" + + ENTRYPOINT [ "python3", "./udp2mqtt.py" ] diff --git a/config.py b/config.py index 53596d5..27db20f 100644 --- a/config.py +++ b/config.py @@ -1,19 +1,19 @@ +import os + # Configuration for UDP connections -SERVER_IP = "mopp_chat_server" #"127.0.0.1" # "10.101.101.14" -#SERVER_IP = "10.101.101.14" #"127.0.0.1" # "" -UDP_PORT = 7373 +SERVER_IP = os.environ.get('SERVER_IP', "mopp_chat_server") +UDP_PORT = int(os.environ.get('UDP_PORT', "7373")) # Configuration for Chat Server -CLIENT_TIMEOUT = 3000 -MAX_CLIENTS = 100 -KEEPALIVE = 10 -CHAT_WPM = 20 +CLIENT_TIMEOUT = int(os.environ.get('CLIENT_TIMEOUT', "300")) +MAX_CLIENTS = int(os.environ.get('MAX_CLIENTS', "100")) +KEEPALIVE = int(os.environ.get('KEEPALIVE', "10")) +CHAT_WPM = int(os.environ.get('CHAT_WPM', "20")) # MQTT configuration -MQTT_HOST = "broker.hivemq.com" -MQTT_PORT = 1883 - -TOPIC = "/moip/udp2mqtt/mopp" -TOPICDURATIONS = "/moip/udp2mqtt/durations" +MQTT_HOST = os.environ.get('MQTT_HOST', "broker.hivemq.com") +MQTT_PORT = int(os.environ.get('MQTT_PORT', "1883")) +MQTT_TOPIC = os.environ.get('MQTT_TOPIC', "/moip/udp2mqtt/durations") +# Internal configuration with code dependencies MORSE_JSON_VERSION = 1 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 0608b29..c74e2a6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,3 +3,17 @@ services: udp2mqtt: image: ghcr.io/morse-code-over-ip/udp2mqtt:latest restart: always + environment: + # Configuration for UDP connections + SERVER_IP: "mopp_chat_server" #"10.101.101.14" #"127.0.0.1" + UDP_PORT: "7373" + # Configuration for Chat Server + CLIENT_TIMEOUT: "300" + MAX_CLIENTS: "100" + KEEPALIVE: "10" + CHAT_WPM: "20" + # MQTT configuration + MQTT_HOST: "broker.hivemq.com" + MQTT_PORT: "1883" + MQTT_TOPIC: "/moip/udp2mqtt/durations" +