From 1c03a32298a9c3c18d346535d57e58c22eafd2ad Mon Sep 17 00:00:00 2001 From: "tao.chen" <93983997+taochen-ct@users.noreply.github.com> Date: Mon, 27 Jul 2026 15:37:58 +0800 Subject: [PATCH] update: add common --- backend/Dockerfile | 22 ++++++++++++++++++++++ backend/pyproject.toml | 8 ++++++-- common/pyproject.toml | 11 ++++++----- common/src/common/utils.py | 7 +++++++ docker-compose.yml | 20 ++++++++++++++++++++ runtime/Dockerfile | 19 +++++++++++++++++++ runtime/pyproject.toml | 7 +++++-- uv.lock | 6 ++++++ 8 files changed, 91 insertions(+), 9 deletions(-) create mode 100644 backend/Dockerfile create mode 100644 common/src/common/utils.py create mode 100644 docker-compose.yml create mode 100644 runtime/Dockerfile diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..24e217f --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,22 @@ +# backend/Dockerfile +FROM python:3.12-slim + +WORKDIR /app + +# 安装 uv +COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv + +# 1. 拷贝根目录配置与 lock 文件 +COPY pyproject.toml uv.lock ./ + +# 2. 拷贝 common 模块与 backend 模块 +COPY common ./common +COPY backend ./backend + +# 3. 安装 backend 及其所有依赖 (包括本地 common) +RUN uv sync --frozen --no-dev --package backend + +EXPOSE 8000 + +# 4. 启动服务 (通过 uv run 指定运行 backend 包) +CMD ["uv", "run", "--package", "backend", "uvicorn", "backend.main:app", "--host", "0.0.0.0", "--port", "8000"] \ No newline at end of file diff --git a/backend/pyproject.toml b/backend/pyproject.toml index c3890d4..b19b6f8 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -21,6 +21,10 @@ backend = "backend:main" url = "https://pypi.tuna.tsinghua.edu.cn/simple/" default = true +[tool.uv.sources] +common = { workspace = true } + [build-system] -requires = ["uv_build>=0.11.31,<0.12.0"] -build-backend = "uv_build" +requires = ["hatchling"] +build-backend = "hatchling.build" + diff --git a/common/pyproject.toml b/common/pyproject.toml index 2c7c0f1..694a3b5 100644 --- a/common/pyproject.toml +++ b/common/pyproject.toml @@ -9,9 +9,10 @@ authors = [ requires-python = ">=3.12" dependencies = [] -[project.scripts] -common = "common:main" - [build-system] -requires = ["uv_build>=0.11.31,<0.12.0"] -build-backend = "uv_build" +requires = ["hatchling"] +build-backend = "hatchling.build" + + +[tool.hatch.build.targets.wheel] +packages = ["src/common"] \ No newline at end of file diff --git a/common/src/common/utils.py b/common/src/common/utils.py new file mode 100644 index 0000000..3c4e086 --- /dev/null +++ b/common/src/common/utils.py @@ -0,0 +1,7 @@ +# coding=utf-8 +""" +@Time :2026/7/27 +@Author :tao.chen +""" +def hello_world(): + return 'Hello World!' \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..31a6cca --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +version: '3.8' + +services: + backend: + build: + context: . + dockerfile: backend/Dockerfile + ports: + - "8000:8000" + environment: + - RUNTIME_BASE_URL=http://runtime:8001 + depends_on: + - runtime + + runtime: + build: + context: . + dockerfile: runtime/Dockerfile + ports: + - "8001:8001" \ No newline at end of file diff --git a/runtime/Dockerfile b/runtime/Dockerfile new file mode 100644 index 0000000..61b3080 --- /dev/null +++ b/runtime/Dockerfile @@ -0,0 +1,19 @@ +# runtime/Dockerfile +FROM python:3.12-slim + +WORKDIR /app + +# 安装 uv +COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv + + +COPY pyproject.toml uv.lock ./ + +COPY common ./common +COPY runtime ./runtime + +RUN uv sync --frozen --no-dev --package backend + +EXPOSE 8001 + +CMD ["uv", "run", "--package", "runtime", "uvicorn", "runtime.main:app", "--host", "0.0.0.0", "--port", "8001"] \ No newline at end of file diff --git a/runtime/pyproject.toml b/runtime/pyproject.toml index fabfcc7..7cb0813 100644 --- a/runtime/pyproject.toml +++ b/runtime/pyproject.toml @@ -19,6 +19,9 @@ dependencies = [ url = "https://pypi.tuna.tsinghua.edu.cn/simple/" default = true +[tool.uv.sources] +common = { workspace = true } + [build-system] -requires = ["uv_build>=0.11.31,<0.12.0"] -build-backend = "uv_build" +requires = ["hatchling"] +build-backend = "hatchling.build" \ No newline at end of file diff --git a/uv.lock b/uv.lock index c1b7974..76ca3fa 100644 --- a/uv.lock +++ b/uv.lock @@ -9,6 +9,7 @@ resolution-markers = [ [manifest] members = [ "backend", + "common", "model-platform", "runtime", ] @@ -379,6 +380,11 @@ wheels = [ { url = "https://pypi.tuna.tsinghua.edu.cn/packages/60/97/891a0971e1e4a8c5d2b20bbe0e524dc04548d2307fee33cdeba148fd4fc7/comm-0.2.3-py3-none-any.whl", hash = "sha256:c615d91d75f7f04f095b30d1c1711babd43bdc6419c1be9886a85f2f4e489417", size = 7294, upload-time = "2025-07-25T14:02:02.896Z" }, ] +[[package]] +name = "common" +version = "0.1.0" +source = { editable = "common" } + [[package]] name = "debugpy" version = "1.8.21"