feat(proxy): sing-box для обхода блокировки OpenRouter из РФ
OpenRouter отдаёт 403 с российских IP (подтверждено вживую). Добавлен sing-box как отдельный сервис (VLESS+WS+TLS до ноды вне РФ) — только для исходящих запросов к OpenRouter из ollama_client.py, остальной трафик (Postgres/RabbitMQ/MinIO/Ollama) идёт напрямую. Реальный конфиг с UUID — только на проде (см. config.json.example), в git не попадает.
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -106,3 +106,6 @@ services/**/app/models/**/*.py[cod]
|
|||||||
tmp/
|
tmp/
|
||||||
temp/
|
temp/
|
||||||
CREDENTIALS.md
|
CREDENTIALS.md
|
||||||
|
|
||||||
|
# Прокси-конфиг с реальными credentials (UUID) — только на проде, не в git
|
||||||
|
infra/singbox/config.json
|
||||||
|
|||||||
@@ -109,6 +109,19 @@ services:
|
|||||||
elasticsearch:
|
elasticsearch:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
|
||||||
|
# SOCKS5-прокси (sing-box → VLESS-нода вне РФ) — OpenRouter недоступен
|
||||||
|
# напрямую из России, только для этого и нужен. Остальной трафик
|
||||||
|
# worker-gpu (Postgres/RabbitMQ/MinIO/Ollama) идёт напрямую, не через него.
|
||||||
|
singbox-proxy:
|
||||||
|
image: ghcr.io/sagernet/sing-box:v1.10.0
|
||||||
|
container_name: antiplagiator-singbox-proxy
|
||||||
|
command: run -c /etc/sing-box/config.json
|
||||||
|
volumes:
|
||||||
|
- ./infra/singbox/config.json:/etc/sing-box/config.json:ro
|
||||||
|
networks:
|
||||||
|
- antiplagiator
|
||||||
|
restart: unless-stopped
|
||||||
|
|
||||||
worker-gpu:
|
worker-gpu:
|
||||||
build:
|
build:
|
||||||
context: ./services/worker-gpu
|
context: ./services/worker-gpu
|
||||||
@@ -120,6 +133,8 @@ services:
|
|||||||
depends_on:
|
depends_on:
|
||||||
elasticsearch:
|
elasticsearch:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
singbox-proxy:
|
||||||
|
condition: service_started
|
||||||
|
|
||||||
worker-indexer:
|
worker-indexer:
|
||||||
build:
|
build:
|
||||||
|
|||||||
39
infra/singbox/config.json.example
Normal file
39
infra/singbox/config.json.example
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"log": {
|
||||||
|
"level": "warn"
|
||||||
|
},
|
||||||
|
"inbounds": [
|
||||||
|
{
|
||||||
|
"type": "socks",
|
||||||
|
"tag": "socks-in",
|
||||||
|
"listen": "0.0.0.0",
|
||||||
|
"listen_port": 1080
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outbounds": [
|
||||||
|
{
|
||||||
|
"type": "vless",
|
||||||
|
"tag": "proxy-out",
|
||||||
|
"server": "CHANGE_ME.example.com",
|
||||||
|
"server_port": 443,
|
||||||
|
"uuid": "CHANGE_ME-uuid",
|
||||||
|
"packet_encoding": "xudp",
|
||||||
|
"tls": {
|
||||||
|
"enabled": true,
|
||||||
|
"server_name": "CHANGE_ME.example.com",
|
||||||
|
"alpn": ["http/1.1"],
|
||||||
|
"utls": {
|
||||||
|
"enabled": true,
|
||||||
|
"fingerprint": "chrome"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"transport": {
|
||||||
|
"type": "ws",
|
||||||
|
"path": "/api/stream"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"route": {
|
||||||
|
"final": "proxy-out"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -45,6 +45,9 @@ class Settings(BaseSettings):
|
|||||||
OPENROUTER_API_KEY: str = ""
|
OPENROUTER_API_KEY: str = ""
|
||||||
OPENROUTER_MODEL: str = "deepseek/deepseek-chat"
|
OPENROUTER_MODEL: str = "deepseek/deepseek-chat"
|
||||||
OPENROUTER_URL: str = "https://openrouter.ai/api/v1/chat/completions"
|
OPENROUTER_URL: str = "https://openrouter.ai/api/v1/chat/completions"
|
||||||
|
# OpenRouter блокирует запросы из РФ — заворачиваем именно эти запросы
|
||||||
|
# через sing-box (docker-compose сервис singbox-proxy). Пусто = без прокси.
|
||||||
|
OPENROUTER_PROXY_URL: str = "socks5://singbox-proxy:1080"
|
||||||
|
|
||||||
# FAISS / ML
|
# FAISS / ML
|
||||||
FAISS_INDEX_PATH: str = "/data/index/faiss.index"
|
FAISS_INDEX_PATH: str = "/data/index/faiss.index"
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ class OllamaClient:
|
|||||||
json=payload,
|
json=payload,
|
||||||
headers={"Authorization": f"Bearer {settings.OPENROUTER_API_KEY}"},
|
headers={"Authorization": f"Bearer {settings.OPENROUTER_API_KEY}"},
|
||||||
timeout=self.timeout,
|
timeout=self.timeout,
|
||||||
|
proxy=settings.OPENROUTER_PROXY_URL or None,
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response.json()["choices"][0]["message"]["content"]
|
return response.json()["choices"][0]["message"]["content"]
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ qdrant-client==1.19.0 # альтернативный векторный бэк
|
|||||||
torch==2.3.0
|
torch==2.3.0
|
||||||
numpy==1.26.4
|
numpy==1.26.4
|
||||||
httpx==0.27.0
|
httpx==0.27.0
|
||||||
|
socksio==1.0.0 # SOCKS5-прокси для httpx (нужен для OpenRouter из РФ, см. app.ollama_client)
|
||||||
minio==7.2.7
|
minio==7.2.7
|
||||||
datasketch==1.6.5
|
datasketch==1.6.5
|
||||||
pydantic-settings==2.2.1
|
pydantic-settings==2.2.1
|
||||||
|
|||||||
Reference in New Issue
Block a user