Setup: Make Docker Compose, Scheduler, and Simclient fully operational
This commit is contained in:
@@ -10,8 +10,8 @@ services:
|
|||||||
- "80:80"
|
- "80:80"
|
||||||
- "443:443"
|
- "443:443"
|
||||||
volumes:
|
volumes:
|
||||||
- ./nginx.conf:/etc/nginx/nginx.conf:ro
|
- ${PWD}/nginx.conf:/etc/nginx/nginx.conf:ro
|
||||||
- ./certs:/etc/nginx/certs:ro
|
- ${PWD}/certs:/etc/nginx/certs:ro
|
||||||
depends_on:
|
depends_on:
|
||||||
- server
|
- server
|
||||||
- dashboard
|
- dashboard
|
||||||
@@ -121,5 +121,40 @@ services:
|
|||||||
retries: 3
|
retries: 3
|
||||||
start_period: 30s
|
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:
|
volumes:
|
||||||
db-data:
|
db-data:
|
||||||
6
scheduler/Dockerfile
Normal file
6
scheduler/Dockerfile
Normal 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"]
|
||||||
4
scheduler/requirements.txt
Normal file
4
scheduler/requirements.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
paho-mqtt
|
||||||
|
sqlalchemy
|
||||||
|
pymysql
|
||||||
|
python-dotenv
|
||||||
20
scheduler/scheduler.py
Normal file
20
scheduler/scheduler.py
Normal 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
6
simclient/Dockerfile
Normal 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"]
|
||||||
1
simclient/requirements.txt
Normal file
1
simclient/requirements.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
paho-mqtt
|
||||||
24
simclient/simclient.py
Normal file
24
simclient/simclient.py
Normal 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()
|
||||||
Reference in New Issue
Block a user