From fc87bbb9606171202567f2a5a4eb97d1d7db2ecb Mon Sep 17 00:00:00 2001 From: estromenko Date: Tue, 21 Oct 2025 20:04:45 +0300 Subject: [PATCH] Add dockerization --- .dockerignore | 34 ++++++++++++++++++++++++++++++++++ Dockerfile | 34 ++++++++++++++++++++++++++++++++++ backend/__init__.py | 0 backend/agent.py | 11 +++++++++-- backend/bot.py | 4 ++++ backend/index.py | 6 +++++- compose.yaml | 20 +++++++++++++++----- 7 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 backend/__init__.py diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..03a268b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,34 @@ +# Include any files or directories that you don't want to be copied to your +# container here (e.g., local build artifacts, temporary files, etc.). +# +# For more help, visit the .dockerignore file reference guide at +# https://docs.docker.com/go/build-context-dockerignore/ + +**/.DS_Store +**/__pycache__ +**/.venv +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/bin +**/charts +**/docker-compose* +**/compose.y*ml +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c4e773a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +# syntax=docker/dockerfile:1 +FROM python:3.13-slim + +ENV PYTHONDONTWRITEBYTECODE=1 + +ENV PYTHONUNBUFFERED=1 + +ENV UV_SYSTEM_PYTHON=1 + +WORKDIR /app + +ARG UID=10001 +RUN adduser \ + --disabled-password \ + --gecos "" \ + --home "/nonexistent" \ + --shell "/sbin/nologin" \ + --no-create-home \ + --uid "${UID}" \ + appuser + +RUN --mount=type=cache,target=/var/cache/apt \ + apt-get update && apt-get install -y --no-install-recommends \ + git && rm -rf /var/lib/apt/lists/* + +RUN --mount=from=ghcr.io/astral-sh/uv,source=/uv,target=/bin/uv \ + --mount=type=cache,target=/root/.cache/uv \ + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ + --mount=type=bind,source=uv.lock,target=uv.lock \ + uv sync --no-dev --locked --no-install-project + +COPY . . + +USER appuser diff --git a/backend/__init__.py b/backend/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/agent.py b/backend/agent.py index a2affab..b20c8bf 100644 --- a/backend/agent.py +++ b/backend/agent.py @@ -1,3 +1,4 @@ +import os from langchain.agents import create_agent from langchain_openai import ChatOpenAI from langgraph.checkpoint.memory import InMemorySaver @@ -22,10 +23,16 @@ SYSTEM_PROMPT = """ Поиск в интернете можно делать не более 1 раза за запрос пользователя. """ -redis = Redis() +redis = Redis(host=os.getenv("REDIS_HOST", "127.0.0.1")) llm = ChatOpenAI(model_name="gpt-5") embedding = DeepInfraEmbeddings(model_id="Qwen/Qwen3-Embedding-8B") -vectorstore = Clickhouse(embedding, ClickhouseSettings(port=8123, username="default", password="", index_type="vector_similarity")) +vectorstore = Clickhouse(embedding, ClickhouseSettings( + host=os.getenv("CLICKHOUSE_HOST", "127.0.0.1"), + port=8123, + username="default", + password="", + index_type="vector_similarity", +)) search_tool = DuckDuckGoSearchRun() diff --git a/backend/bot.py b/backend/bot.py index 253225d..c5ee2bd 100644 --- a/backend/bot.py +++ b/backend/bot.py @@ -1,3 +1,7 @@ +import sys + +sys.path.append(".") + import os import io import traceback diff --git a/backend/index.py b/backend/index.py index 3f03ee6..93318ad 100644 --- a/backend/index.py +++ b/backend/index.py @@ -1,3 +1,7 @@ +import sys + +sys.path.append(".") + from backend.agent import vectorstore from langchain_core.documents import Document import clickhouse_connect @@ -16,7 +20,7 @@ WHERE timestamp >= now() - INTERVAL 30 DAY ]) >= 5 """ -client = clickhouse_connect.create_client(port=18123) +client = clickhouse_connect.create_client(host="127.0.0.1", port=18123) documents = [] for row in client.query(query).result_rows: diff --git a/compose.yaml b/compose.yaml index e8c39b7..885ffb6 100644 --- a/compose.yaml +++ b/compose.yaml @@ -7,14 +7,24 @@ services: CLICKHOUSE_DB: default CLICKHOUSE_USER: default CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: "1" - ports: - - "127.0.0.1:8123:8123" - - "127.0.0.1:9000:9000" + network_mode: host volumes: - /srv/vision-career/clickhouse/ch_data:/var/lib/clickhouse/ - /srv/vision-career/clickhouse/ch_logs:/var/log/clickhouse-server/ valkey: image: valkey/valkey:latest restart: always - ports: - - "127.0.0.1:6379:6379" + network_mode: host + bot: + image: vision-career:latest + build: . + command: [".venv/bin/python", "backend/bot.py"] + restart: always + init: true + network_mode: host + env_file: + - .env + develop: + watch: + - action: rebuild + path: .