version: '3.8'

services:
  web:
    build:
      context: .
      dockerfile: Dockerfile
    image: app:latest
    container_name: app-web
    ports:
      - '${HOST_PORT:-3000}:3000'
    environment:
      - NODE_ENV=production
      - PORT=3000
    restart: unless-stopped
    healthcheck:
      test: ['CMD', 'wget', '--quiet', '--tries=1', '--spider', 'http://localhost:3000/health']
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
    # Resource limits (adjust based on your needs)
    deploy:
      resources:
        limits:
          cpus: '1'
          memory: 512M
        reservations:
          cpus: '0.5'
          memory: 256M
    # Security options
    security_opt:
      - no-new-privileges:true
    read_only: true
    tmpfs:
      - /tmp
      - /app/.cache
    # Logging configuration
    logging:
      driver: json-file
      options:
        max-size: '10m'
        max-file: '3'

  # Optional: Add a reverse proxy for production
  # nginx:
  #   image: nginx:alpine
  #   container_name: app-nginx
  #   ports:
  #     - "80:80"
  #     - "443:443"
  #   volumes:
  #     - ./nginx.conf:/etc/nginx/nginx.conf:ro
  #     - ./ssl:/etc/nginx/ssl:ro
  #   depends_on:
  #     - web
  #   restart: unless-stopped

# Network configuration
networks:
  default:
    name: app-network
