services:
  web:
    container_name: php-${DOCKER_APP_NAME}-apache
    build:
      context: ./docker/php
      dockerfile: Dockerfile
      args:
        DOCKER_PHP_VERSION: ${DOCKER_PHP_VERSION}
        DOCKER_NODE_VERSION: ${DOCKER_NODE_VERSION}
        CURRENT_UID: ${CURRENT_UID}
        CURRENT_GID: ${CURRENT_GID}
    environment:
      PHP_IDE_CONFIG: serverName=${DOCKER_APP_NAME}-docker
      XDEBUG_CLIENT_HOST: ${XDEBUG_CLIENT_HOST:-host.docker.internal}
      XDEBUG_CONFIG: client_host=${XDEBUG_CLIENT_HOST:-host.docker.internal} client_port=9003
      DATABASE_URL: "postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}?serverVersion=16&charset=utf8"
      CORS_ALLOW_ORIGIN: ${CORS_ALLOW_ORIGIN}
    volumes:
      - ./:/var/www/html
      - ~/.cache:/var/www/.cache # Pour la cache de composer
      - ~/.config:/var/www/.config # Pour la config de yarn
      - ~/.composer:/var/www/.composer # Pour la config de composer
      - ./docker/php/config/php.ini:/usr/local/etc/php/php.ini
      - ./docker/php/config/vhost.conf:/etc/apache2/sites-available/000-default.conf
      - ./docker/php/config/docker-php-ext-xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
      - ./LOG:/var/www/html/LOG
      - ./LOG/logs_apache:/var/log/apache2/
    extra_hosts:
      - "host.docker.internal:host-gateway"
    depends_on:
      - db
    ports:
        - "8081:80"
        - "3001:3000"
    restart: unless-stopped
  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - pg_data:/var/lib/postgresql/data
    ports:
      - "${POSTGRES_PORT:-5433}:5432"
    restart: unless-stopped

  pgadmin:
    container_name: pgadmin-${DOCKER_APP_NAME}
    image: dpage/pgadmin4:latest
    user: root
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_EMAIL:-admin@admin.com}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASSWORD:-admin}
      PGADMIN_CONFIG_SERVER_MODE: 'False'
      PGADMIN_CONFIG_MASTER_PASSWORD_REQUIRED: 'False'
      PGADMIN_SERVER_JSON_FILE: '/pgadmin4/servers.json'
    volumes:
      - pgadmin_data:/var/lib/pgadmin
      - ./docker/pgadmin/servers.json:/pgadmin4/servers.json:ro
      - ./docker/pgadmin/pgpass:/pgadmin4/pgpass:ro
    ports:
      - "${PGADMIN_PORT:-5050}:80"
    depends_on:
      - db
    restart: unless-stopped
    entrypoint: >
      /bin/sh -c "
      mkdir -p /var/lib/pgadmin &&
      cp /pgadmin4/pgpass /var/lib/pgadmin/pgpass &&
      chmod 600 /var/lib/pgadmin/pgpass &&
      chown 5050:5050 /var/lib/pgadmin/pgpass &&
      /entrypoint.sh
      "

volumes:
  pg_data:
  pgadmin_data:
