Skip to content

Commit 48675cb

Browse files
authored
Merge pull request #177 from kaykouo/addpoetry
使用Poetry管理依赖并将其更新到Dockerfile中去
2 parents 74b75aa + 30c95a1 commit 48675cb

5 files changed

Lines changed: 2631 additions & 41 deletions

File tree

README.md

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ This project is generously sponsored by ZMTO. Visit their website: [https://zmto
2828

2929
## 系统要求
3030

31-
* **Python**: 3.9+ (推荐 3.10+ 或 3.11+)
31+
* **Python**: >=3.9, <4.0 (由 Poetry 管理)
3232
* **操作系统**: Windows, macOS, Linux (完全跨平台支持)
3333
* **内存**: 建议 2GB+ 可用内存
3434
* **网络**: 稳定的互联网连接访问 Google AI Studio
@@ -158,12 +158,36 @@ python launch_camoufox.py --headless
158158

159159
### 快速开始
160160

161-
1. **安装**: 参见 [安装指南](docs/installation-guide.md)
162-
2. **配置**: 参见 [环境变量配置指南](docs/environment-configuration.md) - **推荐先配置**
163-
3. **首次认证**: 参见 [认证设置指南](docs/authentication-setup.md)
164-
4. **日常运行**: 参见 [日常运行指南](docs/daily-usage.md)
165-
5. **API使用**: 参见 [API使用指南](docs/api-usage.md)
166-
6. **Web界面**: 参见 [Web UI使用指南](docs/webui-guide.md)
161+
本项目现在使用 [Poetry](https://python-poetry.org/) 进行依赖管理。
162+
163+
1. **安装 Poetry**:
164+
如果您尚未安装 Poetry,请参照其官方文档进行安装:[Poetry Installation](https://python-poetry.org/docs/#installation)
165+
166+
2. **克隆项目**:
167+
```bash
168+
git clone https://github.com/CJackHwang/AIstudioProxyAPI.git
169+
cd AIstudioProxyAPI
170+
```
171+
172+
3. **安装依赖**:
173+
使用 Poetry 安装项目依赖。这会自动创建一个虚拟环境(如果当前没有激活的虚拟环境)。
174+
```bash
175+
poetry install
176+
```
177+
178+
4. **激活虚拟环境 (可选但推荐)**:
179+
要激活 Poetry 创建的虚拟环境,请运行:
180+
```bash
181+
poetry shell
182+
```
183+
之后,您可以直接运行 Python 脚本 (例如 `python gui_launcher.py`)。
184+
或者,如果您不想激活 shell,可以在每个命令前加上 `poetry run` (例如 `poetry run python gui_launcher.py`)。
185+
186+
5. **配置**: 参见 [环境变量配置指南](docs/environment-configuration.md) - **推荐先配置**
187+
6. **首次认证**: 参见 [认证设置指南](docs/authentication-setup.md)
188+
7. **日常运行**: 参见 [日常运行指南](docs/daily-usage.md) (请使用 `poetry run python launch_camoufox.py` 或在 `poetry shell` 中运行 `python launch_camoufox.py`)
189+
8. **API使用**: 参见 [API使用指南](docs/api-usage.md)
190+
9. **Web界面**: 参见 [Web UI使用指南](docs/webui-guide.md)
167191

168192
### 详细文档
169193

docker/Dockerfile

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,20 @@ RUN apt-get update && \
99
supervisor curl \
1010
&& apt-get clean && rm -rf /var/lib/apt/lists/*
1111

12+
# Install Poetry
13+
ENV POETRY_HOME="/opt/poetry"
14+
ENV POETRY_VERSION=1.8.3
15+
RUN curl -sSL https://install.python-poetry.org | python3 - --version ${POETRY_VERSION}
16+
ENV PATH="${POETRY_HOME}/bin:${PATH}"
17+
1218
WORKDIR /app_builder
13-
COPY requirements.txt ./
14-
RUN pip install --no-cache-dir --upgrade pip && \
15-
pip install --no-cache-dir -U "camoufox[geoip]" && \
16-
pip install --no-cache-dir -r requirements.txt
19+
20+
# Copy Poetry project files
21+
COPY pyproject.toml poetry.lock ./
22+
23+
# Configure Poetry to not create virtualenvs and install dependencies
24+
RUN poetry config virtualenvs.create false --local && \
25+
poetry install --no-root --no-dev --no-interaction --no-ansi
1726

1827
FROM python:3.10-slim-bookworm
1928

@@ -28,11 +37,17 @@ RUN groupadd -r appgroup && useradd -r -g appgroup -s /bin/bash -d /app appuser
2837

2938
WORKDIR /app
3039

40+
# Copy installed packages and executables from builder stage
3141
COPY --from=builder /usr/local/lib/python3.10/site-packages/ /usr/local/lib/python3.10/site-packages/
3242
COPY --from=builder /usr/local/bin/ /usr/local/bin/
43+
COPY --from=builder /opt/poetry/bin/poetry /usr/local/bin/poetry
3344

45+
# Copy application code
3446
COPY . .
3547

48+
# Install Playwright browsers and dependencies, and fetch camoufox
49+
# Note: poetry is now available in the final image if needed for any build scripts,
50+
# but dependencies should already be installed.
3651
RUN camoufox fetch && \
3752
python -m playwright install firefox && \
3853
python -m playwright install-deps firefox
@@ -69,7 +84,7 @@ ENV PLAYWRIGHT_BROWSERS_PATH=/home/appuser/.cache/ms-playwright
6984

7085
ENV PYTHONUNBUFFERED=1
7186

72-
# 默认环境变量 (可被 .env 文件或运行时环境变量覆盖)
87+
# Default environment variables (can be overridden by .env or runtime)
7388
ENV PORT=8000
7489
ENV DEFAULT_FASTAPI_PORT=2048
7590
ENV DEFAULT_CAMOUFOX_PORT=9222
@@ -78,7 +93,7 @@ ENV SERVER_LOG_LEVEL=INFO
7893
ENV DEBUG_LOGS_ENABLED=false
7994
ENV AUTO_CONFIRM_LOGIN=true
8095

81-
# 向后兼容的环境变量
96+
# Backward compatibility
8297
ENV SERVER_PORT=2048
8398
ENV INTERNAL_CAMOUFOX_PROXY=""
8499

0 commit comments

Comments
 (0)