Setup: Make Docker Compose, Scheduler, and Simclient fully operational

This commit is contained in:
2025-07-14 18:41:28 +00:00
parent 7c1f546af9
commit 2fa84c1e2b
7 changed files with 99 additions and 3 deletions

View File

@@ -10,8 +10,8 @@ services:
- "80:80"
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- ./certs:/etc/nginx/certs:ro
- ${PWD}/nginx.conf:/etc/nginx/nginx.conf:ro
- ${PWD}/certs:/etc/nginx/certs:ro
depends_on:
- server
- dashboard
@@ -121,5 +121,40 @@ services:
retries: 3
start_period: 30s
scheduler:
build:
context: ./scheduler
dockerfile: Dockerfile
image: infoscreen-scheduler:latest
container_name: infoscreen-scheduler
restart: unless-stopped
depends_on:
db:
condition: service_healthy
mqtt:
condition: service_healthy
environment:
DB_CONN: "mysql+pymysql://${DB_USER}:${DB_PASSWORD}@db/${DB_NAME}"
MQTT_BROKER_URL: mqtt
MQTT_PORT: 1883
networks:
- infoscreen-net
simclient:
build:
context: ./simclient
dockerfile: Dockerfile
image: infoscreen-simclient:latest
container_name: infoscreen-simclient
restart: unless-stopped
depends_on:
mqtt:
condition: service_healthy
environment:
MQTT_BROKER_URL: mqtt
MQTT_PORT: 1883
networks:
- infoscreen-net
volumes:
db-data:
db-data:

6
scheduler/Dockerfile Normal file
View File

@@ -0,0 +1,6 @@
FROM python:3.13-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python", "scheduler.py"]

View File

@@ -0,0 +1,4 @@
paho-mqtt
sqlalchemy
pymysql
python-dotenv

20
scheduler/scheduler.py Normal file
View File

@@ -0,0 +1,20 @@
# scheduler/scheduler.py
import time
import paho.mqtt.client as mqtt
def main():
# Fix für die veraltete API - explizit callback_api_version setzen
client = mqtt.Client(callback_api_version=mqtt.CallbackAPIVersion.VERSION2)
# Im Docker-Netzwerk: Hostname des MQTT-Brokers ist "mqtt", nicht "localhost"
client.connect("mqtt", 1883)
while True:
# Hier später: Events aus DB lesen und MQTT-Nachricht senden
print("Scheduler läuft...")
time.sleep(10)
if __name__ == "__main__":
main()

6
simclient/Dockerfile Normal file
View File

@@ -0,0 +1,6 @@
FROM python:3.13-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python", "simclient.py"]

View File

@@ -0,0 +1 @@
paho-mqtt

24
simclient/simclient.py Normal file
View File

@@ -0,0 +1,24 @@
# simclient/simclient.py
import time
import paho.mqtt.client as mqtt
def on_message(client, userdata, msg):
print(f"Empfangen: {msg.topic} {msg.payload.decode()}")
def main():
client = mqtt.Client()
client.on_message = on_message
# Im Docker-Netzwerk: Hostname des MQTT-Brokers ist "mqtt"
client.connect("mqtt", 1883)
client.subscribe("infoscreen/+/now")
while True:
# Heartbeat senden
client.publish("infoscreen/client1/heartbeat", "alive")
client.loop(timeout=1.0)
time.sleep(5)
if __name__ == "__main__":
main()