services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: corpsaf-app
    restart: unless-stopped
    working_dir: /var/www/html
    volumes:
      - ./:/var/www/html
      - /var/www/html/vendor
      - ./docker/nginx/default.conf:/etc/nginx/sites-available/default
    ports:
      - "8000:80"
    environment:
      - APP_ENV=${APP_ENV:-local}
      - APP_DEBUG=${APP_DEBUG:-true}
      - DB_CONNECTION=mysql
      - DB_HOST=db
      - DB_PORT=3306
      - DB_DATABASE=${DB_DATABASE:-corpsaf}
      - DB_USERNAME=${DB_USERNAME:-corpsaf_user}
      - DB_PASSWORD=${DB_PASSWORD:-corpsaf_password}
    depends_on:
      - db
    networks:
      - corpsaf-network

  db:
    image: mysql:8.0
    container_name: corpsaf-db
    restart: unless-stopped
    environment:
      - MYSQL_DATABASE=${DB_DATABASE:-corpsaf}
      - MYSQL_USER=${DB_USERNAME:-corpsaf_user}
      - MYSQL_PASSWORD=${DB_PASSWORD:-corpsaf_password}
      - MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD:-root_password}
    volumes:
      - db_data:/var/lib/mysql
    ports:
      - "3307:3306" 
    networks:
      - corpsaf-network

  node:
    image: node:20-alpine
    container_name: corpsaf-node
    working_dir: /var/www/html
    volumes:
      - ./:/var/www/html
      - /var/www/html/node_modules
    command: sh -c "npm install && npm run dev"
    ports:
      - "5173:5173"
    networks:
      - corpsaf-network
    depends_on:
      - app
    profiles:
      - dev

volumes:
  db_data:
    driver: local

networks:
  corpsaf-network:
    driver: bridge

