version: '3.8'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: business-platform-app
    restart: unless-stopped
    working_dir: /var/www
    volumes:
      - ./:/var/www
      - ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
    networks:
      - business-platform
    depends_on:
      - mysql
      - redis

  nginx:
    image: nginx:alpine
    container_name: business-platform-nginx
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./:/var/www
      - ./docker/nginx/conf.d:/etc/nginx/conf.d
      - ./docker/nginx/ssl:/etc/nginx/ssl
    networks:
      - business-platform
    depends_on:
      - app

  mysql:
    image: mysql:8.0
    container_name: business-platform-mysql
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: ${DB_DATABASE:-business_platform}
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD:-secret}
      MYSQL_PASSWORD: ${DB_PASSWORD:-secret}
      MYSQL_USER: ${DB_USERNAME:-business_user}
    volumes:
      - mysql-data:/var/lib/mysql
      - ./docker/mysql/my.cnf:/etc/mysql/my.cnf
    ports:
      - "3306:3306"
    networks:
      - business-platform

  redis:
    image: redis:alpine
    container_name: business-platform-redis
    restart: unless-stopped
    ports:
      - "6379:6379"
    volumes:
      - redis-data:/data
    networks:
      - business-platform

  queue:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: business-platform-queue
    restart: unless-stopped
    command: php artisan queue:work --sleep=3 --tries=3
    volumes:
      - ./:/var/www
    networks:
      - business-platform
    depends_on:
      - app
      - mysql
      - redis

  scheduler:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: business-platform-scheduler
    restart: unless-stopped
    command: /bin/sh -c "while true; do php artisan schedule:run; sleep 60; done"
    volumes:
      - ./:/var/www
    networks:
      - business-platform
    depends_on:
      - app
      - mysql

networks:
  business-platform:
    driver: bridge

volumes:
  mysql-data:
  redis-data:
