services:
  php:
    build: .
    restart: always
    volumes:
      - .:/var/www/html
    networks:
      - symfony

  nginx:
    image: nginx:alpine
    restart: always
    ports:
      - "127.0.0.1:8080:80"
    volumes:
      - .:/var/www/html
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - php
    networks:
      - symfony

  database:
    image: mariadb:11
    restart: always
    # This MariaDB is only used by the test suite (database c4rgo_test, see
    # .env.test). The application itself uses the host MariaDB on
    # localhost:3306 (1_myc4rgo) configured in .env.local.
    # The service-ignore label stops the Symfony CLI from auto-exposing a
    # DATABASE_URL for this container, which would otherwise override
    # .env.local and make `symfony serve`/`symfony console` talk to the wrong
    # database ("Base table or view not found").
    labels:
      com.symfony.server.service-ignore: true
    environment:
      MARIADB_ROOT_PASSWORD: root
      MARIADB_DATABASE: symfony
      MARIADB_USER: symfony
      MARIADB_PASSWORD: symfony
    volumes:
      - db_data:/var/lib/mysql
    ports:
      - "127.0.0.1:3307:3306"
    networks:
      - symfony

  # Broker MQTT centrale degli scanner. I Raspberry vi si collegano in TLS 8883
  # tramite un bridge mosquitto uscente (NAT-friendly), ponticellando il proprio
  # sottoalbero c4rgo/{device_id}/#. Vedi docker/mqtt/device-bridge.conf.example.
  # Certificati e passwd sono generati da docker/mqtt/setup-broker.sh (gitignored).
  # Distinto dal broker legacy SIM7600 (MQTT_HOST=172.17.0.1 in .env).
  mqtt:
    image: eclipse-mosquitto:2
    restart: always
    ports:
      - "8883:8883"
    volumes:
      - ./docker/mqtt/mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
      - ./docker/mqtt/passwd:/mosquitto/config/passwd:ro
      - ./docker/mqtt/acl:/mosquitto/config/acl:ro
      - ./docker/mqtt/certs:/mosquitto/certs:ro
      - mqtt_data:/mosquitto/data
    networks:
      - symfony

  # Worker che ascolta events/response degli scanner e puo' inviare comandi.
  # Riusa l'immagine php del servizio principale.
  scanner-listener:
    build: .
    restart: always
    command: php bin/console app:scanner:listener -d
    volumes:
      - .:/var/www/html
    depends_on:
      - mqtt
    networks:
      - symfony

networks:
  symfony:

volumes:
  db_data:
  mqtt_data:


