# TED Procurement Document Processor - Docker Compose
# Author: Martin.Schweitzer@procon.co.at and claude.ai
#
# Services:
# - PostgreSQL 16 with pgvector extension (nur für lokale Entwicklung)
# - Python embedding service für Vektorisierung
#
# Standard-Verwendung (nur Embedding-Service):
#   docker-compose --profile with-embedding up -d
#
# Lokale Datenbank verwenden:
#   docker-compose --profile local-db up -d
#
# Remote-Datenbank (94.130.218.54):
#   Konfiguration in application.yml (Standard-Einstellung)

version: '3.8'

services:
  # PostgreSQL database with pgvector extension (NUR FÜR LOKALE ENTWICKLUNG)
  # Standardmäßig deaktiviert - verwende Remote-Server 94.130.218.54
  postgres:
    image: pgvector/pgvector:pg16
    container_name: ted-postgres
    environment:
      POSTGRES_DB: sales
      POSTGRES_USER: postgresql
      POSTGRES_PASSWORD: "PDmXRx0Rbk9OFOn9qO5Gm/mPCfqW8zwbZ+/YIU1lySc="
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./init-db.sql:/docker-entrypoint-initdb.d/init-db.sql:ro
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgresql -d sales"]
      interval: 10s
      timeout: 5s
      retries: 5
    restart: unless-stopped
    profiles:
      - local-db

  # Python embedding service (optional - for production vectorization)
  embedding-service:
    build:
      context: .
      dockerfile: Dockerfile.embedding
    container_name: ted-embedding-service
    ports:
      - "8001:8001"
    environment:
      MODEL_NAME: intfloat/multilingual-e5-large
      MAX_LENGTH: 512
      BATCH_SIZE: 16
    volumes:
      - model_cache:/root/.cache/huggingface
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]
    # Remove GPU section if not using NVIDIA GPU
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8001/health"]
      interval: 30s
      timeout: 10s
      retries: 3
    restart: unless-stopped
    profiles:
      - with-embedding

  # PgAdmin for database management (nur für lokale Datenbank)
  pgadmin:
    image: dpage/pgadmin4:latest
    container_name: ted-pgadmin
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@procon.co.at
      PGADMIN_DEFAULT_PASSWORD: admin
    ports:
      - "5050:80"
    volumes:
      - pgadmin_data:/var/lib/pgadmin
    depends_on:
      - postgres
    restart: unless-stopped
    profiles:
      - local-db
      - tools

volumes:
  postgres_data:
    driver: local
  model_cache:
    driver: local
  pgadmin_data:
    driver: local

networks:
  default:
    name: ted-network
