version: "3.8"

services:
    worker:
      build:
        context: ..
        dockerfile: docker/worker/Dockerfile
      container_name: doc_translator_worker
      environment:
        DB_DSN: "postgresql://doc_user:doc_password@db:5432/doc_translator"
        OUTPUT_DIR: "/data/output"
      volumes:
        - ../data:/data
      depends_on:
        - db
      ports:
        - "8000:8000"
      command: ["uvicorn", "worker.app:app", "--host", "0.0.0.0", "--port", "8000"]
    db:
      image: postgres:16
      container_name: doc_translator_db
      restart: unless-stopped
      environment:
        POSTGRES_DB: doc_translator
        POSTGRES_USER: doc_user
        POSTGRES_PASSWORD: doc_password
      ports:
        - "5432:5432"
      volumes:
        - db_data:/var/lib/postgresql/data
    ollama:
      image: ollama/ollama:latest
      container_name: doc_translator_ollama
      restart: unless-stopped
      ports:
        - "11434:11434"
      environment:
        OLLAMA_HOST: 0.0.0.0
      volumes:
        - ollama_data:/root/.ollama
    n8n:
      image: docker.n8n.io/n8nio/n8n:latest
      container_name: doc_translator_n8n
      restart: unless-stopped
      depends_on:
        - db
        - ollama
      ports:
        - "5678:5678"
      environment:
        # базовые настройки n8n
        N8N_HOST: localhost
        N8N_PORT: 5678
        N8N_PROTOCOL: http
        N8N_EDITOR_BASE_URL: "http://localhost:5678"
        WEBHOOK_URL: "http://localhost:5678"

        # подключение к Postgres
        DB_TYPE: postgresdb
        DB_POSTGRESDB_HOST: db
        DB_POSTGRESDB_PORT: 5432
        DB_POSTGRESDB_DATABASE: doc_translator
        DB_POSTGRESDB_USER: doc_user
        DB_POSTGRESDB_PASSWORD: doc_password

        # доступ к файлам
        N8N_RESTRICT_FILE_ACCESS_TO: /data; /home/node/.n8n-files
        N8N_BLOCK_FILE_ACCESS_TO_N8N_FILES: "false"

        # часовой пояс
        GENERIC_TIMEZONE: Europe/Moscow
        TZ: Europe/Moscow
      volumes:
        - ../data:/data
        - n8n_data:/home/node/.n8n

  

volumes:
  db_data:
  n8n_data:
  ollama_data: