version: '3.9'
services:
  app:
    build: { context: ., dockerfile: Dockerfile }
    restart: unless-stopped
    environment:
      - APP_ENV=production
      - DB_HOST=postgres
      - REDIS_HOST=redis
      - QUEUE_CONNECTION=redis
    depends_on: [postgres, redis]
    healthcheck:
      test: ["CMD", "php", "artisan", "inspire"]
      interval: 30s
  nginx:
    image: nginx:alpine
    ports: ["80:80", "443:443"]
    volumes:
      - ./docker/nginx.conf:/etc/nginx/conf.d/default.conf
      - ./public:/var/www/public
    depends_on: [app]
  worker:
    build: { context: ., dockerfile: Dockerfile }
    restart: unless-stopped
    command: php artisan queue:work redis --tries=5 --timeout=300
    depends_on: [redis, postgres]
  scheduler:
    build: { context: ., dockerfile: Dockerfile }
    restart: unless-stopped
    command: sh -c "while :; do php artisan schedule:run; sleep 60; done"
    depends_on: [postgres]
  postgres:
    image: postgres:15-alpine
    restart: unless-stopped
    environment:
      POSTGRES_DB: nfe_saas
      POSTGRES_USER: nfe
      POSTGRES_PASSWORD: ${DB_PASSWORD:-changeme}
    volumes: ["pg_data:/var/lib/postgresql/data"]
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U nfe"]
      interval: 10s
  redis:
    image: redis:7-alpine
    restart: unless-stopped
    volumes: ["redis_data:/data"]
volumes:
  pg_data:
  redis_data:
