services:
  viizia-nginx:
    image: nginx:1.27-alpine
    container_name: viizia-nginx
    ports:
      - "${VIZ_HTTP_PORT:-8180}:80"
    volumes:
      - ./public:/var/www/html/public:ro
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - viizia-php
    networks:
      - viizia_net

  viizia-php:
    build:
      context: ./docker/php
    container_name: viizia-php
    volumes:
      - .:/var/www/html
      - viizia_uploads:/var/www/html/uploads
    # NOTE : Symfony charge lui-meme .env et .env.local au runtime.
    # On evite donc d'injecter les variables ici (DATABASE_URL, MAILER_DSN...)
    # car les variables d'env du container ecraseraient les .env files.
    depends_on:
      - viizia-mysql
    networks:
      - viizia_net

  viizia-mysql:
    image: mysql:8.0
    container_name: viizia-mysql
    ports:
      - "127.0.0.1:${VIZ_DB_PORT:-8181}:3306"
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:-rootpw}
      MYSQL_DATABASE: ${MYSQL_DATABASE:-viizia}
      MYSQL_USER: ${MYSQL_USER:-viizia}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD:-viizia}
    volumes:
      - viizia_db:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-uroot", "-p${MYSQL_ROOT_PASSWORD:-rootpw}"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - viizia_net

  viizia-phpmyadmin:
    image: phpmyadmin:5
    container_name: viizia-phpmyadmin
    ports:
      - "${VIZ_PMA_PORT:-8182}:80"
    environment:
      PMA_HOST: viizia-mysql
      PMA_USER: root
      PMA_PASSWORD: ${MYSQL_ROOT_PASSWORD:-rootpw}
    depends_on:
      - viizia-mysql
    networks:
      - viizia_net

  viizia-mailhog:
    image: mailhog/mailhog:latest
    container_name: viizia-mailhog
    ports:
      - "${VIZ_MAIL_SMTP_PORT:-8183}:1025"
      - "${VIZ_MAIL_UI_PORT:-8184}:8025"
    networks:
      - viizia_net

networks:
  viizia_net:
    driver: bridge

volumes:
  viizia_db:
  viizia_uploads:
