diff --git a/api-customer/docker-compose.yml b/api-customer/docker-compose.yml index ba0aef78..35eb17e4 100644 --- a/api-customer/docker-compose.yml +++ b/api-customer/docker-compose.yml @@ -11,6 +11,8 @@ services: - mosquitto environment: - MONGO_URI=mongodb://mongo:27017/mydb + - LOCAL_BROKER_USERNAME=main + - LOCAL_BROKER_PASSWORD=hepl - LOCAL_BROKER_ADDRESS=customer-broker - LOCAL_BROKER_PORT=1883 - API_BROKER_ADDRESS=192.168.15.120 @@ -35,6 +37,7 @@ services: ports: - "1883:1883" - "8883:8883" + command: ["sh", "/mosquitto/config/init-mosquitto.sh"] volumes: - ./mosquitto/config:/mosquitto/config - ./mosquitto/data:/mosquitto/data diff --git a/api-customer/mosquitto/config/init-mosquitto.sh b/api-customer/mosquitto/config/init-mosquitto.sh new file mode 100644 index 00000000..efcf31ad --- /dev/null +++ b/api-customer/mosquitto/config/init-mosquitto.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +PASSWORD_FILE=/mosquitto/config/passwords + +echo "Creating password file with pre-registered users..." +if [ ! -f "$PASSWORD_FILE" ]; then + touch "$PASSWORD_FILE" + chmod 600 "$PASSWORD_FILE" + + # Add pre-registered users + mosquitto_passwd -b "$PASSWORD_FILE" main hepl + mosquitto_passwd -b "$PASSWORD_FILE" pi-1 hepl + echo "Password file created !" +else + echo "Password file exists, skipping this step" +fi + +echo "Starting mosquitto..." +exec mosquitto -c /mosquitto/config/mosquitto.conf -v diff --git a/api-customer/mosquitto/config/passwords b/api-customer/mosquitto/config/passwords deleted file mode 100644 index e69de29b..00000000