services:
  postgres:
    image: postgres:15
    container_name: uno-postgres
    restart: unless-stopped
    ports:
      - "127.0.0.1:5432:5432"
    environment:
      POSTGRES_DB: ${POSTGRES_DB}
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
      interval: 10s
      timeout: 5s
      retries: 10
  n8n:
    image: docker.n8n.io/n8nio/n8n:stable
    container_name: uno-n8n
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
    ports:
      - "127.0.0.1:5678:5678"
    environment:
      DB_TYPE: postgresdb
      DB_POSTGRESDB_HOST: postgres
      DB_POSTGRESDB_PORT: 5432
      DB_POSTGRESDB_DATABASE: ${POSTGRES_DB}
      DB_POSTGRESDB_USER: ${POSTGRES_USER}
      DB_POSTGRESDB_PASSWORD: ${POSTGRES_PASSWORD}

      N8N_ENCRYPTION_KEY: ${N8N_ENCRYPTION_KEY}

      N8N_HOST: ${N8N_HOST}
      N8N_PROTOCOL: ${N8N_PROTOCOL}
      N8N_PORT: ${N8N_PORT}
      WEBHOOK_URL: ${WEBHOOK_URL}
      N8N_PROXY_HOPS: ${N8N_PROXY_HOPS}
      NODE_FUNCTION_ALLOW_BUILTIN: crypto,http

      GENERIC_TIMEZONE: ${GENERIC_TIMEZONE}
      TZ: ${TZ}
    volumes:
      - n8n_data:/home/node/.n8n
      - ./local-files:/files
  ffmpeg-api:
    build:
      context: ./ffmpeg-api
    container_name: uno-ffmpeg-api
    restart: unless-stopped
    volumes:
      - ./local-files:/files
    ports:
      - "127.0.0.1:8000:8000"
  minio:
    image: minio/minio:latest
    container_name: minio
    restart: always
    ports:
      - "9000:9000"   # API
      - "9001:9001"   # Web UI
    environment:
      MINIO_ROOT_USER: UN0-admin
      MINIO_ROOT_PASSWORD: RAygtZHqGN49qKn
    volumes:
      - /opt/minio/data:/data
    command: server /data --console-address ":9001"
  bff:
    build:
      context: ./bff
    container_name: uno-bff
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
      minio:
        condition: service_started
    ports:
      - "127.0.0.1:3001:3001"
    environment:
      - NODE_ENV=production
      - HOST=0.0.0.0
      - PORT=3001
      - PG_HOST=postgres
      - PG_PORT=5432
      - PG_DATABASE=${POSTGRES_DB}
      - PG_USER=${POSTGRES_USER}
      - PG_PASSWORD=${POSTGRES_PASSWORD}
      - COOKIE_ACCESS_NAME=__Host-access_token
      - COOKIE_REFRESH_NAME=__Host-refresh_token
      - COOKIE_CSRF_NAME=csrf_token
      - ACCESS_TOKEN_TTL_SEC=900
      - REFRESH_TOKEN_TTL_SEC=2592000
      - JWT_ISSUER=uno-click-bff
      - JWT_AUDIENCE=uno-click-web
      - JWT_SECRET=test-secret-key-for-development
      - N8N_BASE_URL=http://uno-n8n:5678
      - S3_ENDPOINT=http://minio:9000
      - S3_ACCESS_KEY=UN0-admin
      - S3_SECRET_KEY=RAygtZHqGN49qKn
      - S3_BUCKET=uno-click
      - S3_IMAGES_INPUT_FOLDER=images_input
      - S3_PRESIGNED_URL_EXPIRES_IN=3600
      - S3_PUBLIC_ENDPOINT=https://uno-click.pip-test.ru/s3-upload/uno-click/
      - TELEGRAM_BOT_TOKEN=8679428833:AAGtP7fkEjoJCPz1o1PhSV_vCI7g2JB9pHo
      - TELEGRAM_BOT_USERNAME=One_Click_Auth_bot
      - TELEGRAM_WEBHOOK_SECRET=dbe8c8d2903a836339dc009782a63f1a96b94f70ac204a1d
      - FRONTEND_URL=https://uno-click.pip-test.ru,https://cc86b8e0-c23c-42e4-9ca9-52684746940d-00-2b5hl9u4q8nnf.pike.replit.dev,https://150b44f4-d8b1-439c-9b60-f012e9015ab6-00-2sfcbvia8exhs.pike.replit.dev
  site:
    build:
      context: ./site
      dockerfile: Dockerfile
    container_name: uno-site
    restart: unless-stopped
    depends_on:
      bff:
        condition: service_started
    ports:
      - "127.0.0.1:3000:3000"
    environment:
      - NODE_ENV=production
      - PORT=3000
      - BFF_URL=http://uno-bff:3001

volumes:
  postgres_data:
  n8n_data:
