version: '3.8'

services:
  # Application Service
  app:
    build:
      context: .
      target: development
      dockerfile: Dockerfile
    container_name: hirecameroon_app
    volumes:
      - .:/var/www
      - ./docker/nginx/php.ini:/usr/local/etc/php/conf.d/custom.ini
    ports:
      - "9000:9000"
    depends_on:
      - mysql
      - redis
    environment:
      - APP_ENV=local
      - DB_HOST=mysql
      - REDIS_HOST=redis
    networks:
      - hirecameroon

  # Web Server
  web:
    image: nginx:alpine
    container_name: hirecameroon_web
    ports:
      - "80:80"
    volumes:
      - ./:/var/www
      - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - app
    networks:
      - hirecameroon

  # Database
  mysql:
    image: mysql:8.0
    container_name: hirecameroon_mysql
    ports:
      - "3306:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=password
      - MYSQL_DATABASE=hirecameroon
      - MYSQL_USER=hirecameroon
      - MYSQL_PASSWORD=password
    volumes:
      - mysql_data:/var/lib/mysql
      - ./database/HireCameroon.sql:/docker-entrypoint-initdb.d/init.sql
    networks:
      - hirecameroon

  # Cache
  redis:
    image: redis:7-alpine
    container_name: hirecameroon_redis
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
    networks:
      - hirecameroon

  # Queue Worker
  queue:
    build:
      context: .
      target: development
      dockerfile: Dockerfile
    container_name: hirecameroon_queue
    command: php artisan queue:work --verbose --tries=3 --timeout=90
    volumes:
      - .:/var/www
    depends_on:
      - mysql
      - redis
    environment:
      - APP_ENV=local
      - DB_HOST=mysql
      - REDIS_HOST=redis
    networks:
      - hirecameroon

  # Scheduler
  scheduler:
    build:
      context: .
      target: development
      dockerfile: Dockerfile
    container_name: hirecameroon_scheduler
    command: crond -f
    volumes:
      - .:/var/www
    depends_on:
      - mysql
      - redis
    environment:
      - APP_ENV=local
      - DB_HOST=mysql
      - REDIS_HOST=redis
    networks:
      - hirecameroon

  # MailHog for Development
  mailhog:
    image: mailhog/mailhog
    container_name: hirecameroon_mailhog
    ports:
      - "1025:1025"
      - "8025:8025"
    networks:
      - hirecameroon

volumes:
  mysql_data:
  redis_data:

networks:
  hirecameroon:
    driver: bridge