version: '3.8'

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: ear_app
    restart: unless-stopped
    working_dir: /var/www/html
    volumes:
      - ./storage:/var/www/html/storage
      - ./bootstrap/cache:/var/www/html/bootstrap/cache
    environment:
      - APP_ENV=staging
      - APP_DEBUG=false
      - APP_KEY=${APP_KEY}
      - APP_URL=${APP_URL:-http://localhost}
      - DB_CONNECTION=mysql
      - DB_HOST=mysql
      - DB_PORT=3306
      - DB_DATABASE=${DB_DATABASE:-ear_staging}
      - DB_USERNAME=${DB_USERNAME:-ear_user}
      - DB_PASSWORD=${DB_PASSWORD:-secure_password}
      - CACHE_DRIVER=redis
      - SESSION_DRIVER=redis
      - QUEUE_CONNECTION=redis
      - REDIS_HOST=redis
      - REDIS_PORT=6379
    depends_on:
      - mysql
      - redis
    networks:
      - ear_network

  mysql:
    image: mysql:8.0
    container_name: ear_mysql
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: ${DB_DATABASE:-ear_staging}
      MYSQL_USER: ${DB_USERNAME:-ear_user}
      MYSQL_PASSWORD: ${DB_PASSWORD:-secure_password}
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:-root_password}
    volumes:
      - mysql_data:/var/lib/mysql
    ports:
      - "3306:3306"
    networks:
      - ear_network

  redis:
    image: redis:7-alpine
    container_name: ear_redis
    restart: unless-stopped
    volumes:
      - redis_data:/data
    networks:
      - ear_network

  nginx:
    image: nginx:alpine
    container_name: ear_nginx
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./docker/nginx/staging.conf:/etc/nginx/conf.d/default.conf
      - ./docker/ssl:/etc/nginx/ssl
      - ./public:/var/www/html/public
    depends_on:
      - app
    networks:
      - ear_network

volumes:
  mysql_data:
    driver: local
  redis_data:
    driver: local

networks:
  ear_network:
    driver: bridge
