version: '3.8'

services:
  php:
    build:
      context: .
      dockerfile: docker/Dockerfile
    container_name: rental-php
    working_dir: /var/www/html
    volumes:
      - .:/var/www/html
      # Optimisation : exclure les dossiers qui changent souvent
      - /var/www/html/var
    depends_on:
      - postgres
      - mysql_source
    environment:
      - APP_ENV=dev
      - APP_DEBUG=1
    user: "1000:1000"  # Utiliser l'utilisateur www


  nginx:
    image: nginx:alpine
    container_name: rental-nginx
    ports:
      - "8080:80"
    volumes:
      - .:/var/www/html
      - ./docker/nginx.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - php

  postgres:
    image: postgres:16
    container_name: rental_postgres
    restart: unless-stopped
    environment:
      POSTGRES_DB: rental_database
      POSTGRES_USER: rental_user
      POSTGRES_PASSWORD: rental_password
    volumes:
      - pgdata:/var/lib/postgresql/data
    ports:
      - "5432:5432"

  mysql_source:
    image: mysql:5.7
    container_name: rental_mysql_source
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: root_password
      MYSQL_USER: mysql_user
      MYSQL_PASSWORD: mysql_password
    volumes:
      - mysqldata:/var/lib/mysql
      - ./old_db:/docker-entrypoint-initdb.d
    ports:
      - "3306:3306"
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

  adminer:
    image: adminer
    container_name: rental-adminer
    ports:
      - "8081:8080"
    depends_on:
      - postgres
      - mysql_source

  asset-watcher:
    build:
      context: .
      dockerfile: docker/Dockerfile
    container_name: rental-asset-watcher
    working_dir: /var/www/html
    volumes:
      - .:/var/www/html
    command: tail -f /dev/null
    depends_on:
      - php

volumes:
  pgdata:
  mysqldata:
