From 743696a66b64ca95c65ebe6168dfce7bc29f5909 Mon Sep 17 00:00:00 2001 From: puke <1129090915@qq.com> Date: Fri, 7 Nov 2025 00:12:48 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D=E5=9B=BD=E5=86=85docker?= =?UTF-8?q?=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 22 ++++++++++++++++++++-- docker-compose.yml | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index ebb4cb0..5ee4cc0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,9 +3,22 @@ FROM python:3.11-slim +# Build arguments for mirror configuration +# USE_CN_MIRROR: whether to use China mirrors (true/false) +# UV_INDEX_URL: Python package index URL (defaults to Aliyun when USE_CN_MIRROR=true) +ARG USE_CN_MIRROR=false +ARG UV_INDEX_URL=https://pypi.org/simple + # Set working directory WORKDIR /app +# Replace apt sources with China mirrors if needed +# Debian 12 uses DEB822 format in /etc/apt/sources.list.d/debian.sources +RUN if [ "$USE_CN_MIRROR" = "true" ]; then \ + sed -i 's|deb.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources && \ + sed -i 's|security.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list.d/debian.sources; \ + fi + # Install system dependencies # - curl: for health checks and downloads # - ffmpeg: for video/audio processing @@ -29,8 +42,13 @@ ENV PATH="/root/.local/bin:$PATH" COPY pyproject.toml uv.lock README.md ./ COPY pixelle_video ./pixelle_video -# Install Python dependencies using uv -RUN /root/.local/bin/uv sync --frozen --no-dev +# Install Python dependencies using uv with configurable index URL +# Auto-select Aliyun mirror when USE_CN_MIRROR=true and UV_INDEX_URL is default +RUN if [ "$USE_CN_MIRROR" = "true" ] && [ "$UV_INDEX_URL" = "https://pypi.org/simple" ]; then \ + /root/.local/bin/uv sync --frozen --no-dev --index-url https://mirrors.aliyun.com/pypi/simple/; \ + else \ + /root/.local/bin/uv sync --frozen --no-dev --index-url $UV_INDEX_URL; \ + fi # Copy rest of application code COPY api ./api diff --git a/docker-compose.yml b/docker-compose.yml index ab1d948..270ef3f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,11 +1,26 @@ version: '3.8' +# Build Arguments Configuration +# You can override these by setting environment variables before running docker-compose +# +# Example for China environment (auto uses Aliyun mirrors): +# USE_CN_MIRROR=true docker-compose up -d +# +# Example for international environment (default): +# docker-compose up -d +# +# Advanced: Use custom PyPI mirror: +# USE_CN_MIRROR=true UV_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple/ docker-compose up -d + services: # API Service - FastAPI backend api: build: context: . dockerfile: Dockerfile + args: + USE_CN_MIRROR: ${USE_CN_MIRROR:-false} + UV_INDEX_URL: ${UV_INDEX_URL:-https://pypi.org/simple} container_name: pixelle-video-api command: /root/.local/bin/uv run python api/app.py --host 0.0.0.0 --port 8000 ports: @@ -42,6 +57,9 @@ services: build: context: . dockerfile: Dockerfile + args: + USE_CN_MIRROR: ${USE_CN_MIRROR:-false} + UV_INDEX_URL: ${UV_INDEX_URL:-https://pypi.org/simple} container_name: pixelle-video-web command: /root/.local/bin/uv run streamlit run web/app.py --server.port 8501 --server.address 0.0.0.0 ports: