coolify/templates/compose/mosquitto.yaml

51 lines
2.1 KiB
YAML
Raw Normal View History

2024-10-18 19:49:10 +00:00
# documentation: https://mosquitto.org/documentation/
# slogan: Mosquitto is lightweight and suitable for use on all devices, from low-power single-board computers to full servers.
# category: messaging
2024-10-18 19:49:10 +00:00
# tags: mosquitto, mqtt, open-source
# logo: svgs/mosquitto.svg
# port: 1883
2024-10-10 18:18:35 +00:00
services:
mosquitto:
image: eclipse-mosquitto
environment:
- SERVICE_URL_MOSQUITTO_1883
2024-10-18 19:48:16 +00:00
- MQTT_USERNAME=${SERVICE_USER_MOSQUITTO}
- MQTT_PASSWORD=${SERVICE_PASSWORD_MOSQUITTO}
2024-10-11 14:40:59 +00:00
- REQUIRE_CERTIFICATE=${REQUIRE_CERTIFICATE:-false}
- ALLOW_ANONYMOUS=${ALLOW_ANONYMOUS:-true}
2024-10-10 18:18:35 +00:00
volumes:
- "./mosquitto/config:/mosquitto/config"
- "./certs:/certs"
ports:
- "8883:8883"
2024-10-18 19:48:16 +00:00
healthcheck:
test: ["CMD-SHELL", "exit 0"]
interval: 30s
timeout: 10s
retries: 3
2024-10-10 18:18:35 +00:00
entrypoint: 'sh -c "
2024-10-11 14:42:20 +00:00
if [ ''$REQUIRE_CERTIFICATE'' = ''true'' ]; then
echo ''listener 8883'' > /mosquitto/config/mosquitto.conf &&
2024-10-10 18:18:35 +00:00
echo ''cafile /certs/ca.crt'' >> /mosquitto/config/mosquitto.conf &&
echo ''certfile /certs/server.crt'' >> /mosquitto/config/mosquitto.conf &&
2024-10-11 14:42:20 +00:00
echo ''keyfile /certs/server.key'' >> /mosquitto/config/mosquitto.conf;
else
echo ''listener 1883'' > /mosquitto/config/mosquitto.conf;
2024-10-11 14:42:20 +00:00
fi &&
2024-10-10 18:18:35 +00:00
echo ''require_certificate ''$REQUIRE_CERTIFICATE >> /mosquitto/config/mosquitto.conf &&
2024-10-18 20:58:15 +00:00
echo ''allow_anonymous ''$ALLOW_ANONYMOUS >> /mosquitto/config/mosquitto.conf;
if [ -n ''$SERVICE_USER_MOSQUITTO'' ] && [ -n ''$SERVICE_PASSWORD_MOSQUITTO'' ]; then
2024-10-10 18:18:35 +00:00
echo ''password_file /mosquitto/config/passwords'' >> /mosquitto/config/mosquitto.conf &&
touch /mosquitto/config/passwords &&
chmod 0700 /mosquitto/config/passwords &&
2024-10-11 14:42:20 +00:00
chown root:root /mosquitto/config/passwords &&
2024-10-18 19:48:16 +00:00
mosquitto_passwd -b -c /mosquitto/config/passwords $SERVICE_USER_MOSQUITTO $SERVICE_PASSWORD_MOSQUITTO &&
2024-10-17 22:02:57 +00:00
chown mosquitto:mosquitto /mosquitto/config/passwords;
fi &&
2024-10-10 18:18:35 +00:00
exec mosquitto -c /mosquitto/config/mosquitto.conf
"'
labels:
- traefik.tcp.routers.mqtt.entrypoints=mqtt
- traefik.tcp.routers.mqtts.entrypoints=mqtts