From 6633ecbe706b2ea6ecd60e71caadbddf4d422aa6 Mon Sep 17 00:00:00 2001 From: Laurent Ollagnier Date: Sun, 30 Nov 2025 10:34:02 +0100 Subject: [PATCH] Lancement en mode network plutot que pod --- VContainers/MQTT/config/nanomq.conf | 4 ++-- VContainers/run.sh | 25 +++++++++++++++-------- VContainers/stop.sh | 4 ++-- VNode/services/buzzer/buzzer-manager.js | 2 +- VNode/services/config/config_game.json | 11 +++++----- VNode/services/config/config_network.json | 9 ++++---- VNode/services/light/light-manager.js | 2 +- 7 files changed, 31 insertions(+), 26 deletions(-) diff --git a/VContainers/MQTT/config/nanomq.conf b/VContainers/MQTT/config/nanomq.conf index 4d55b5e7..cade21a0 100644 --- a/VContainers/MQTT/config/nanomq.conf +++ b/VContainers/MQTT/config/nanomq.conf @@ -18,11 +18,11 @@ mqtt { } listeners.tcp { - bind = "127.0.0.1:1883" + bind = "0.0.0.0:1883" } listeners.ws { - bind = "127.0.0.1:9001" + bind = "0.0.0.0:9001" } http_server { diff --git a/VContainers/run.sh b/VContainers/run.sh index eb94456f..e121832e 100755 --- a/VContainers/run.sh +++ b/VContainers/run.sh @@ -4,21 +4,28 @@ set -e # Move to repository root cd "$(dirname "$0")/.." -echo "Creating Pod vulture..." -# Check if pod exists to avoid error -if podman pod exists vulture; then - echo "Pod vulture already exists." +NETWORK_NAME="vulture-net" + +echo "Creating network $NETWORK_NAME..." +if podman network exists $NETWORK_NAME; then + echo "Network $NETWORK_NAME already exists." else - podman pod create --name vulture -p 8080:80 -p 1883:1883 -p 8081:8081 -p 8083:8083 -p 8883:8883 -p 9001:9001 + podman network create $NETWORK_NAME fi echo "Starting NanoMQ..." -podman run -dt --rm --pod vulture --name nanomq -v ./VContainers/MQTT/config/nanomq.conf:/etc/nanomq.conf docker.io/emqx/nanomq:latest --conf /etc/nanomq.conf +# NanoMQ needs to expose ports for external access (e.g. VApp frontend) and be on the network for VNode +podman run -dt --rm --network $NETWORK_NAME --name nanomq \ + -p 1883:1883 -p 9001:9001 -p 8081:8081 -p 8083:8083 -p 8883:8883 \ + -v ./VContainers/MQTT/config/nanomq.conf:/etc/nanomq.conf \ + docker.io/emqx/nanomq:latest --conf /etc/nanomq.conf echo "Starting VNode..." -podman run -dt --rm --pod vulture --name vnode vnode:latest +# VNode connects to nanomq via the network, no ports needed on host unless for debugging +podman run -dt --rm --network $NETWORK_NAME --name vnode vnode:latest echo "Starting VApp..." -podman run -dt --rm --pod vulture --name vapp vapp:latest +# VApp (nginx) needs port 80 exposed +podman run -dt --rm --network $NETWORK_NAME --name vapp -p 8080:80 vapp:latest -echo "All containers started." +echo "All containers started on network $NETWORK_NAME." diff --git a/VContainers/stop.sh b/VContainers/stop.sh index 0e93d036..cd64e4d9 100755 --- a/VContainers/stop.sh +++ b/VContainers/stop.sh @@ -5,7 +5,7 @@ podman stop vapp || echo "vapp not running" podman stop vnode || echo "vnode not running" podman stop nanomq || echo "nanomq not running" -echo "Removing pod..." -podman pod rm vulture || echo "Pod vulture not found" +echo "Removing network..." +podman network rm vulture-net || echo "Network vulture-net not found" echo "Cleanup complete." diff --git a/VNode/services/buzzer/buzzer-manager.js b/VNode/services/buzzer/buzzer-manager.js index 92919af4..38166587 100644 --- a/VNode/services/buzzer/buzzer-manager.js +++ b/VNode/services/buzzer/buzzer-manager.js @@ -2,7 +2,7 @@ const mqtt = require('mqtt'); // MQTT broker configuration -const brokerUrl = 'mqtt://localhost'; // Broker URL (change if needed) +const brokerUrl = 'mqtt://nanomq'; // Broker URL (change if needed) const clientId = 'buzzer_manager'; const options = { clientId, diff --git a/VNode/services/config/config_game.json b/VNode/services/config/config_game.json index ddeba6c0..9d873038 100644 --- a/VNode/services/config/config_game.json +++ b/VNode/services/config/config_game.json @@ -1,18 +1,17 @@ { "services": { - "mqttHost": "mqtt://localhost", - "score":{ - "MQTTconfig":{ + "mqttHost": "mqtt://nanomq", + "score": { + "MQTTconfig": { "mqttScoreTopic": "game/score", "mqttScoreChangeTopic": "game/score/update" } }, - "quizzcollector":{ - "MQTTconfig":{ + "quizzcollector": { + "MQTTconfig": { "mqttQuizzCollectorListTopic": "game/quizz-collector/list", "mqttQuizzCollectorCmdTopic": "game/quizz-collector/cmd" } } } - } \ No newline at end of file diff --git a/VNode/services/config/config_network.json b/VNode/services/config/config_network.json index d50dede7..27580ac2 100644 --- a/VNode/services/config/config_network.json +++ b/VNode/services/config/config_network.json @@ -1,17 +1,16 @@ { "hosts": { - "buzzers":{ - "IP":{ + "buzzers": { + "IP": { "redBuzzerIP": "8.8.8.6", "blueBuzzerIP": "8.8.8.8", "greenBuzzerIP": "8.8.8.8", "yellowBuzzerIP": "8.8.8.8" }, - "MQTTconfig":{ - "mqttHost": "mqtt://localhost", + "MQTTconfig": { + "mqttHost": "mqtt://nanomq", "mqttTopic": "buzzer/watcher" } } } - } \ No newline at end of file diff --git a/VNode/services/light/light-manager.js b/VNode/services/light/light-manager.js index 3bb87516..d5ebb082 100644 --- a/VNode/services/light/light-manager.js +++ b/VNode/services/light/light-manager.js @@ -2,7 +2,7 @@ const mqtt = require('mqtt'); // Configuration du broker MQTT et de WLED -const brokerUrl = 'mqtt://localhost'; // Change ce lien si nécessaire +const brokerUrl = 'mqtt://nanomq'; // Change ce lien si nécessaire const clientId = 'light_manager_wled'; const wledTopicBase = 'wled/all'; // Le topic de base pour ton ruban WLED const options = {