version: '3.8'

services:
  app:
    build:
      context: ..
      dockerfile: docker/Dockerfile
    container_name: ecommerce-ops-app
    restart: unless-stopped
    environment:
      - APP_ENV=production
      - APP_DEBUG=false
      - APP_URL=http://localhost:8000
      - DB_HOST=db
      - DB_PORT=3306
      - DB_DATABASE=ecommerce_ops
      - DB_USERNAME=ecommerce
      - DB_PASSWORD=ecommerce_secret
      - REDIS_HOST=redis
      - QUEUE_CONNECTION=database
      - SESSION_DRIVER=database
      - CACHE_STORE=database
    ports:
      - "8000:8000"
    volumes:
      - ../storage:/var/www/storage
      - ../public:/var/www/public
    depends_on:
      - db
      - redis
    networks:
      - ecommerce-network

  db:
    image: mysql:8.0
    container_name: ecommerce-ops-db
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: root_secret
      MYSQL_DATABASE: ecommerce_ops
      MYSQL_USER: ecommerce
      MYSQL_PASSWORD: ecommerce_secret
    ports:
      - "3306:3306"
    volumes:
      - mysql-data:/var/lib/mysql
    networks:
      - ecommerce-network

  redis:
    image: redis:7-alpine
    container_name: ecommerce-ops-redis
    restart: unless-stopped
    ports:
      - "6379:6379"
    networks:
      - ecommerce-network

  scheduler:
    build:
      context: ..
      dockerfile: docker/Dockerfile
    container_name: ecommerce-ops-scheduler
    restart: unless-stopped
    command: ["sh", "-c", "while true; do php artisan schedule:run; sleep 60; done"]
    environment:
      - APP_ENV=production
      - DB_HOST=db
      - REDIS_HOST=redis
    depends_on:
      - db
      - redis
    networks:
      - ecommerce-network

volumes:
  mysql-data:

networks:
  ecommerce-network:
    driver: bridge