version: "3.8"

services:
  redis:
    image: redis:7-alpine
    container_name: sqdf_redis
    volumes:
      - redis-data:/data
    restart: unless-stopped
    # Tidak expose port; hanya internal antar container

  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: sqdf_backend
    working_dir: /var/www/html
    ports:
      - "8002:8001" # hanya publish port yang diperlukan ke host
    env_file:
      - ./backend/.env
    environment:
      APP_ENV: production
      APP_DEBUG: "false"
      REDIS_HOST: redis
      CACHE_DRIVER: redis
      QUEUE_CONNECTION: redis
      SESSION_DRIVER: redis
    volumes:
      - backend-storage:/var/www/html/storage
    depends_on:
      - redis
    command: sh -c "php artisan migrate --force || true && php artisan serve --host=0.0.0.0 --port=8001"
    restart: unless-stopped

  queue:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: sqdf_queue
    working_dir: /var/www/html
    env_file:
      - ./backend/.env
    environment:
      REDIS_HOST: redis
      CACHE_DRIVER: redis
      QUEUE_CONNECTION: redis
      SESSION_DRIVER: redis
    volumes:
      - backend-storage:/var/www/html/storage
    depends_on:
      - redis
    command: sh -c "php artisan queue:work --sleep=1 --tries=3"
    restart: unless-stopped

  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    container_name: sqdf_frontend
    working_dir: /app
    ports:
      - "5181:5173"
    environment:
      VITE_BACKEND_URL: http://backend:8001
      CHOKIDAR_USEPOLLING: "true"
    depends_on:
      - backend
    restart: unless-stopped

volumes:
  redis-data:
  backend-storage: