version: '3.8'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: speta-exam-app
    restart: unless-stopped
    working_dir: /var/www
    volumes:
      - ../src:/var/www
      - ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
    networks:
      - speta-network
    depends_on:
      - db
      - redis
      - mailhog

  nginx:
    image: nginx:alpine
    container_name: speta-exam-nginx
    restart: unless-stopped
    ports:
      - "8080:80"
    volumes:
      - ../src:/var/www
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
    networks:
      - speta-network
    depends_on:
      - app

  db:
    image: mysql:8.0
    container_name: speta-exam-db
    restart: unless-stopped
    ports:
      - "3306:3306"
    environment:
      MYSQL_DATABASE: speta_exam_hub
      MYSQL_ROOT_PASSWORD: secret
      MYSQL_PASSWORD: secret
      MYSQL_USER: speta
    volumes:
      - dbdata:/var/lib/mysql
      - ./mysql/my.cnf:/etc/mysql/my.cnf
    networks:
      - speta-network

  redis:
    image: redis:alpine
    container_name: speta-exam-redis
    restart: unless-stopped
    ports:
      - "6379:6379"
    networks:
      - speta-network

  mailhog:
    image: mailhog/mailhog
    container_name: speta-exam-mailhog
    ports:
      - "1025:1025"
      - "8025:8025"
    networks:
      - speta-network

  queue:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: speta-exam-queue
    restart: unless-stopped
    working_dir: /var/www
    command: php artisan queue:work --sleep=3 --tries=3
    volumes:
      - ../src:/var/www
      - ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
    networks:
      - speta-network
    depends_on:
      - db
      - redis

  scheduler:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: speta-exam-scheduler
    restart: unless-stopped
    working_dir: /var/www
    command: php artisan schedule:work
    volumes:
      - ../src:/var/www
      - ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
    networks:
      - speta-network
    depends_on:
      - db
      - redis

volumes:
  dbdata:
    driver: local

networks:
  speta-network:
    driver: bridge