ARG BUILDPLATFORM ARG TARGETPLATFORM ARG TARGETARCH FROM --platform=$BUILDPLATFORM node:22-alpine AS web-build WORKDIR /app/web COPY web/package.json web/bun.lock ./ RUN npm install COPY VERSION /app/VERSION COPY CHANGELOG.md /app/CHANGELOG.md COPY web ./ RUN NEXT_PUBLIC_APP_VERSION="$(cat /app/VERSION)" npm run build FROM --platform=$TARGETPLATFORM python:3.13-slim AS app ARG TARGETPLATFORM ARG TARGETARCH ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ UV_LINK_MODE=copy WORKDIR /app # 安装系统依赖 # - git: Git 存储后端需要 # - libpq-dev: PostgreSQL 客户端库 # - gcc: 编译 psycopg2-binary 需要 RUN apt-get update && apt-get install -y --no-install-recommends \ git \ libpq-dev \ gcc \ openssl \ && rm -rf /var/lib/apt/lists/* RUN pip install --no-cache-dir uv COPY pyproject.toml uv.lock ./ RUN uv sync --frozen --no-dev --no-install-project COPY main.py ./ # config.json 在 .gitignore 中,构建时生成默认配置 RUN if [ ! -f config.json ]; then \ echo '{"auth-key":"chatgpt2api","refresh_account_interval_minute":5,"image_retention_days":15,"image_poll_timeout_secs":120,"auto_remove_rate_limited_accounts":false,"auto_remove_invalid_accounts":true,"log_levels":["debug","error","info","warning"],"proxy":"","base_url":"","sensitive_words":[],"global_system_prompt":"","image_account_concurrency":3,"image_parallel_generation":true,"image_poll_interval_secs":10,"image_poll_initial_wait_secs":10,"image_storage":{"enabled":false,"mode":"local","webdav_url":"","webdav_username":"","webdav_password":"","webdav_root_path":"chatgpt2api/images","public_base_url":""},"image_min_free_mb":500,"chat_completion_cache":{"enabled":true,"ttl_seconds":60,"max_entries":256,"dedupe_inflight":true,"stream_cache":true,"normalize_messages":true,"drop_adjacent_duplicates":true,"drop_assistant_history":false},"image_settle_enabled":false,"image_check_before_hit_enabled":false,"image_settle_secs":2,"auto_relogin_after_refresh":false,"image_timeout_retry_secs":30,"third_party_apps":{"infinite_canvas":{"enabled":true,"url":"https://canvas.best"}}}' > config.json; \ fi COPY VERSION ./ COPY api ./api COPY services ./services COPY utils ./utils COPY scripts ./scripts COPY --from=web-build /app/web/out ./web_dist # HF Spaces: 持久化数据目录软链接到 /data COPY scripts/entrypoint_hf.sh /app/scripts/entrypoint_hf.sh COPY scripts/init_storage_hf.sh /app/scripts/init_storage_hf.sh RUN chmod +x /app/scripts/entrypoint_hf.sh /app/scripts/init_storage_hf.sh EXPOSE 7860 # HF Spaces 必须监听 7860 端口 CMD ["/app/scripts/entrypoint_hf.sh", "uv", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--access-log"]