Skip to content

Commit 30c95a1

Browse files
committed
feat(docker): 使用Poetry管理依赖并更新Dockerfile
1 parent 6cf3a7f commit 30c95a1

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

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)