version: '3.8'

services:
  web:
    build:
      context: https://git.kobeamerijckx.com/Kobe/docupulse.git
      dockerfile: Dockerfile
    ports:
      - "${PORT:-10335}:5000"
    environment:
      - FLASK_APP=app.py
      - FLASK_ENV=production
      - DATABASE_URL=postgresql://postgres:postgres@db:5432/docupulse_${PORT:-10335}
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=docupulse_${PORT:-10335}
      - MASTER=${ISMASTER:-false}
    volumes:
      - docupulse_uploads:/app/uploads
    depends_on:
      - db
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:5000/health"]
      interval: 60s
      timeout: 30s
      retries: 3
      start_period: 120s
    deploy:
      resources:
        limits:
          cpus: '1'
          memory: 1G
    networks:
      - public_network
      - internal_network

  db:
    image: postgres:13
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=docupulse_${PORT:-10335}
    volumes:
      - docupulse_postgres_data:/var/lib/postgresql/data
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 30s
      timeout: 10s
      retries: 3
    networks:
      - internal_network

volumes:
  docupulse_postgres_data:
    name: docupulse_${PORT:-10335}_postgres_data
  docupulse_uploads:
    name: docupulse_${PORT:-10335}_uploads

networks:
  public_network:
    name: docupulse_public