diff --git a/.dockerignore b/.dockerignore index 1b9d5e1..179b969 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,321 +1,35 @@ -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* -.pnpm-debug.log* +# Git 和 IDE +.git +.github +.idea/ +.vscode/ .DS_Store -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json -BiliNote/pnpm-lock.yaml -# Runtime data -pids -*.pid -*.seed -*.pid.lock -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov +# Tauri 构建产物(非常大) +BillNote_frontend/src-tauri/target +BillNote_frontend/src-tauri/bin -# Coverage directory used by tools like istanbul -coverage -*.lcov +# 运行时数据 +backend/data +backend/static +backend/models +backend/logs +backend/uploads +backend/*.db +backend/note_results +backend/bin/ -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories +# 依赖和构建缓存 node_modules/ -jspm_packages/ - -# Snowpack dependency directory (https://snowpack.dev/) -web_modules/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional stylelint cache -.stylelintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ -.BiliNote-dev/* -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variable files -.env -.env.development.local -.env.test.local -.env.production.local -.env.local -!.env.example -# parcel-bundler cache (https://parceljs.org/) -.cache -.parcel-cache - -# Next.js build output -.next -out - -# Nuxt.js build / generate output -.nuxt -dist - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and not Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# vuepress v2.x temp and cache directory -.temp -.cache - -# vitepress build output -**/.vitepress/dist - -# vitepress cache directory -**/.vitepress/cache - -# Docusaurus cache and generated files -.docusaurus - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port - -# Stores VSCode versions used for testing VSCode extensions -.vscode-test - -# yarn v2 -.yarn/cache -.yarn/unplugged -.yarn/build-state.yml -.yarn/install-state.gz -.pnp.* -# Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ dist/ -downloads/ -eggs/ -.eggs/ - -lib64/ -parts/ -sdist/ -var/ -wheels/ -share/python-wheels/ +build/ +*.tar *.egg-info/ -.installed.cfg -*.egg -MANIFEST -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -cover/ - -# Translations -*.mo -*.pot -.idea/ -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -.pybuilder/ -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -# For a library or package, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# .python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# UV -# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. -# This is especially recommended for binary packages to ensure reproducibility, and is more -# commonly ignored for libraries. -#uv.lock - -# poetry -# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. -# This is especially recommended for binary packages to ensure reproducibility, and is more -# commonly ignored for libraries. -# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control -#poetry.lock - -# pdm -# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. -#pdm.lock -# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it -# in version control. -# https://pdm.fming.dev/latest/usage/project/#working-with-version-control -.pdm.toml -.pdm-python -.pdm-build/ - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments +# 环境文件 .env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# Cython debug symbols -cython_debug/ - -# PyCharm -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ - -# Ruff stuff: -.ruff_cache/ - -# PyPI configuration file -.pypirc -/backend/data/* -/backend/static/* -/backend/note_tasks.db -/backend/bin/ -/backend/logs/ -/backend/note_results -/backend/models -/backend/.idea/* -/backend/bili_note.db -/backend/uploads/* -/BiliNote_frontend/.idea/* +.env.local +.env.*.local +!.env.example diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index bb8fd20..73d4571 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -1,76 +1,73 @@ -name: Build Complete Docker Image +name: Build and Publish Docker Image on: push: tags: - - 'v*' # 在推送 tag 时触发 (如 v1.0.0) + - 'v*' + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} jobs: - build: + build-and-push: runs-on: ubuntu-latest - + permissions: + contents: read + packages: write + steps: - name: Checkout Code uses: actions/checkout@v4 - - name: Extract Version from Tag - id: get_version - run: | - # 获取 tag 名称 (如 refs/tags/v1.0.0 -> v1.0.0) - VERSION=${GITHUB_REF#refs/tags/} - echo "version=$VERSION" >> $GITHUB_OUTPUT - echo "Tag version: $VERSION" - - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Build Docker Image - run: | - VERSION="${{ steps.get_version.outputs.version }}" - IMAGE_NAME="bilinote:${VERSION}" - - echo "Building image: ${IMAGE_NAME}" - - # 构建镜像 - docker build -f Dockerfile.complete -t ${IMAGE_NAME} . - - # 保存镜像为 tar 文件 - docker save ${IMAGE_NAME} -o bilinote-${VERSION}.tar - - # 显示镜像信息 - echo "Image built successfully!" - docker images bilinote:${VERSION} - - - name: Upload Docker Image Artifact - uses: actions/upload-artifact@v4 + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 with: - name: bilinote-${{ steps.get_version.outputs.version }} - path: bilinote-${{ steps.get_version.outputs.version }}.tar - retention-days: 90 + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=sha,prefix= + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and Push Docker Image + uses: docker/build-push-action@v6 + with: + context: . + file: Dockerfile.complete + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + platforms: linux/amd64,linux/arm64 - name: Generate Usage Instructions run: | - VERSION="${{ steps.get_version.outputs.version }}" echo "==========================================" - echo "Docker Image Build Complete!" + echo "Docker Image Published!" echo "==========================================" echo "" - echo "Image Name: bilinote:${VERSION}" - echo "Artifact: bilinote-${VERSION}.tar" + echo "Pull the image:" + echo " docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" echo "" - echo "To use this Docker image:" - echo "1. Download the artifact from this workflow run" - echo "2. Load the image:" - echo " docker load < bilinote-${VERSION}.tar" - echo "3. Run the container:" - echo " docker run -d -p 80:80 --name bilinote bilinote:${VERSION}" + echo "Run the container:" + echo " docker run -d -p 80:80 \\" + echo " -v bilinote-data:/app/backend/data \\" + echo " --name bilinote \\" + echo " ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" echo "" - echo "Or with environment variables:" - echo " docker run -d -p 80:80 \\" - echo " -e BACKEND_PORT=8483 \\" - echo " -e BACKEND_HOST=0.0.0.0 \\" - echo " -v /path/to/data:/app/backend/data \\" - echo " --name bilinote bilinote:${VERSION}" - echo "" - echo "Access the application at: http://localhost:80" + echo "Access the application at: http://localhost" echo "==========================================" diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b3e2771..d6f1e2a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,25 +6,38 @@ on: tags: - 'v*' # 发布 tag 时触发 workflow_dispatch: + jobs: build: strategy: matrix: - platform: [macos-latest, windows-latest] + include: + - platform: macos-latest + - platform: ubuntu-22.04 + - platform: windows-latest runs-on: ${{ matrix.platform }} steps: - name: Checkout Code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - # 设置 Python 环境 + # Linux 系统依赖(Tauri 需要) + - name: Install Linux Dependencies + if: matrix.platform == 'ubuntu-22.04' + run: | + sudo apt-get update + sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf + + # 设置 Python 环境(带 pip 缓存) - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: - python-version: '3.10' + python-version: '3.11' + cache: 'pip' + cache-dependency-path: backend/requirements.txt - # 安装 Python 依赖并执行你的 build.sh + # 安装 Python 依赖并执行构建 - name: Install Python dependencies & Build backend shell: bash run: | @@ -38,30 +51,57 @@ jobs: ./backend/build.sh fi - # 设置 Node 环境 + 安装前端依赖 + # 设置 pnpm + - name: Setup pnpm + uses: pnpm/action-setup@v4 + with: + version: 'latest' + + # 设置 Node 环境(带 pnpm 缓存) - name: Set up Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: '20' + cache: 'pnpm' + cache-dependency-path: BillNote_frontend/pnpm-lock.yaml - - name: Enable Corepack + Install pnpm + - name: Install frontend dependencies working-directory: BillNote_frontend - run: | - corepack enable - pnpm install + run: pnpm install --frozen-lockfile # 设置 Rust 环境 - name: Set up Rust uses: dtolnay/rust-toolchain@stable + # Cargo 缓存 + - name: Cache Cargo + uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + BillNote_frontend/src-tauri/target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('BillNote_frontend/src-tauri/Cargo.lock') }} + restore-keys: ${{ runner.os }}-cargo- + # 打包 Tauri 应用 - name: Build Tauri App working-directory: BillNote_frontend run: pnpm tauri build - # 可选:上传构建产物 + # 生成 SHA256 校验和 + - name: Generate Checksums + shell: bash + run: | + cd BillNote_frontend/src-tauri/target/release/bundle/ + find . -type f \( -name "*.dmg" -o -name "*.msi" -o -name "*.deb" -o -name "*.AppImage" \) -exec sha256sum {} \; > checksums.sha256 || true + + # 上传构建产物 - name: Upload Desktop Bundle uses: actions/upload-artifact@v4 with: name: app-${{ matrix.platform }} - path: BillNote_frontend/src-tauri/target/release/bundle/ + path: | + BillNote_frontend/src-tauri/target/release/bundle/ diff --git a/BillNote_frontend/Dockerfile b/BillNote_frontend/Dockerfile index e666adc..a1e7b4e 100644 --- a/BillNote_frontend/Dockerfile +++ b/BillNote_frontend/Dockerfile @@ -1,25 +1,23 @@ # === 前端构建阶段 === FROM node:18-alpine AS builder -# 安装 pnpm -RUN npm install -g pnpm +RUN corepack enable && corepack prepare pnpm@latest --activate -# 设置工作目录 WORKDIR /app -# 拷贝前端源码 -COPY ./BillNote_frontend /app +# 先复制 lockfile 利用依赖层缓存 +COPY ./BillNote_frontend/package.json ./BillNote_frontend/pnpm-lock.yaml ./ +RUN pnpm install --frozen-lockfile -# 安装依赖并构建 -RUN pnpm install && pnpm run build +# 再复制源代码并构建 +COPY ./BillNote_frontend/ ./ +RUN pnpm run build # --- 阶段2:使用 nginx 作为静态服务器 --- FROM nginx:1.25-alpine -# 删除默认配置(可选) RUN rm -rf /etc/nginx/conf.d/default.conf COPY ./BillNote_frontend/deploy/default.conf /etc/nginx/conf.d/default.conf - # 拷贝构建产物 -COPY --from=builder /app/dist /usr/share/nginx/html \ No newline at end of file +COPY --from=builder /app/dist /usr/share/nginx/html diff --git a/Dockerfile.complete b/Dockerfile.complete index ba38edb..534551b 100644 --- a/Dockerfile.complete +++ b/Dockerfile.complete @@ -1,41 +1,56 @@ # === 阶段1:构建 Backend === FROM python:3.11-slim AS backend-builder +ARG APT_MIRROR=mirrors.tuna.tsinghua.edu.cn +ARG PIP_INDEX=https://pypi.tuna.tsinghua.edu.cn/simple + RUN rm -f /etc/apt/sources.list && \ rm -rf /etc/apt/sources.list.d/* && \ - echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \ - echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \ - echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \ + echo "deb https://${APT_MIRROR}/debian bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \ + echo "deb https://${APT_MIRROR}/debian bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \ + echo "deb https://${APT_MIRROR}/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \ apt-get update && \ - apt-get install -y ffmpeg && \ + apt-get install -y --no-install-recommends ffmpeg && \ rm -rf /var/lib/apt/lists/* ENV PATH="/usr/bin:${PATH}" ENV HF_ENDPOINT=https://hf-mirror.com WORKDIR /tmp/backend + +# 先复制 requirements.txt 利用层缓存 +COPY ./backend/requirements.txt /tmp/backend/requirements.txt +RUN pip install --no-cache-dir -i ${PIP_INDEX} -r requirements.txt + COPY ./backend /tmp/backend -RUN pip install --no-cache-dir -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt # === 阶段2:构建 Frontend === FROM node:18-alpine AS frontend-builder -RUN npm install -g pnpm +RUN corepack enable && corepack prepare pnpm@latest --activate + WORKDIR /tmp/frontend + +# 先复制 lockfile 利用依赖层缓存 +COPY ./BillNote_frontend/package.json ./BillNote_frontend/pnpm-lock.yaml ./ +RUN pnpm install --frozen-lockfile + COPY ./BillNote_frontend /tmp/frontend -RUN pnpm install && pnpm run build +RUN pnpm run build # === 阶段3:完整应用镜像 === FROM python:3.11-slim +ARG APT_MIRROR=mirrors.tuna.tsinghua.edu.cn + # 安装必要的运行时依赖 RUN rm -f /etc/apt/sources.list && \ rm -rf /etc/apt/sources.list.d/* && \ - echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \ - echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \ - echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \ + echo "deb https://${APT_MIRROR}/debian bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \ + echo "deb https://${APT_MIRROR}/debian bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \ + echo "deb https://${APT_MIRROR}/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \ apt-get update && \ - apt-get install -y ffmpeg nginx supervisor procps && \ + apt-get install -y --no-install-recommends ffmpeg nginx supervisor procps && \ rm -rf /var/lib/apt/lists/* ENV PATH="/usr/bin:${PATH}" diff --git a/README.md b/README.md index 22402a1..19b89e4 100644 --- a/README.md +++ b/README.md @@ -104,9 +104,30 @@ sudo apt install ffmpeg ### 🐳 使用 Docker 一键部署 -确保你已安装 Docker 和 Docker Compose: +确保你已安装 Docker,然后直接拉取预构建镜像运行: -[docker 部署](https://github.com/JefferyHcool/bilinote-deploy/blob/master/README.md) +```bash +# 拉取最新镜像 +docker pull ghcr.io/jefferyhcool/bilinote:latest + +# 运行容器 +docker run -d -p 80:80 \ + -v bilinote-data:/app/backend/data \ + --name bilinote \ + ghcr.io/jefferyhcool/bilinote:latest +``` + +访问:`http://localhost` + +也可以使用 docker-compose 本地构建: + +```bash +# 标准部署 +docker-compose up -d + +# GPU 加速部署(需要 NVIDIA GPU) +docker-compose -f docker-compose.gpu.yml up -d +``` ## 🧠 TODO diff --git a/backend/Dockerfile b/backend/Dockerfile index d482d2b..9e899bf 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,23 +1,27 @@ FROM python:3.11-slim +ARG APT_MIRROR=mirrors.tuna.tsinghua.edu.cn +ARG PIP_INDEX=https://pypi.tuna.tsinghua.edu.cn/simple RUN rm -f /etc/apt/sources.list && \ rm -rf /etc/apt/sources.list.d/* && \ - echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \ - echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \ - echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \ + echo "deb https://${APT_MIRROR}/debian bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \ + echo "deb https://${APT_MIRROR}/debian bookworm-updates main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \ + echo "deb https://${APT_MIRROR}/debian-security bookworm-security main contrib non-free non-free-firmware" >> /etc/apt/sources.list && \ apt-get update && \ - apt-get install -y ffmpeg && \ + apt-get install -y --no-install-recommends ffmpeg curl && \ rm -rf /var/lib/apt/lists/* -# 确保 PATH 中包含 ffmpeg 路径(可选) ENV PATH="/usr/bin:${PATH}" - -# 设置 Hugging Face 镜像源环境变量 ENV HF_ENDPOINT=https://hf-mirror.com WORKDIR /app + +# 先复制 requirements.txt 利用层缓存 +COPY ./backend/requirements.txt /app/requirements.txt +RUN pip install --no-cache-dir -i ${PIP_INDEX} -r requirements.txt + +# 再复制应用代码(频繁变动不影响 pip 缓存层) COPY ./backend /app -RUN pip install --no-cache-dir -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt CMD ["python", "main.py"] diff --git a/backend/Dockerfile.gpu b/backend/Dockerfile.gpu index 341dbbe..d74a3cb 100644 --- a/backend/Dockerfile.gpu +++ b/backend/Dockerfile.gpu @@ -1,16 +1,27 @@ FROM nvidia/cuda:12.4.1-cudnn-runtime-ubuntu22.04 -RUN apt update && \ - apt install -y ffmpeg python3-pip && \ - apt clean all && \ +ARG APT_MIRROR=mirrors.tuna.tsinghua.edu.cn +ARG PIP_INDEX=https://pypi.tuna.tsinghua.edu.cn/simple + +RUN rm -f /etc/apt/sources.list && \ + rm -rf /etc/apt/sources.list.d/* && \ + echo "deb https://${APT_MIRROR}/ubuntu jammy main restricted universe multiverse" > /etc/apt/sources.list && \ + echo "deb https://${APT_MIRROR}/ubuntu jammy-updates main restricted universe multiverse" >> /etc/apt/sources.list && \ + echo "deb https://${APT_MIRROR}/ubuntu jammy-security main restricted universe multiverse" >> /etc/apt/sources.list && \ + apt-get update && \ + apt-get install -y --no-install-recommends ffmpeg python3-pip curl && \ rm -rf /var/lib/apt/lists/* -# 设置 Hugging Face 镜像源环境变量 ENV HF_ENDPOINT=https://hf-mirror.com WORKDIR /app + +# 先复制 requirements.txt 利用层缓存 +COPY ./backend/requirements.txt /app/requirements.txt +RUN pip install --no-cache-dir -i ${PIP_INDEX} -r requirements.txt && \ + pip install --no-cache-dir -i ${PIP_INDEX} 'transformers[torch]>=4.23' + +# 再复制应用代码 COPY ./backend /app -RUN pip install --no-cache-dir -i https://pypi.mirrors.ustc.edu.cn/simple -r requirements.txt -RUN pip install --no-cache-dir -i https://pypi.mirrors.ustc.edu.cn/simple 'transformers[torch]>=4.23' CMD ["python3", "main.py"] diff --git a/backend/build.sh b/backend/build.sh index 9c1a500..ae23261 100755 --- a/backend/build.sh +++ b/backend/build.sh @@ -25,6 +25,7 @@ cp .env.example backend/.env # 步骤 2: PyInstaller 打包,直接添加已存在的 .env 文件 echo "开始 PyInstaller 打包..." pyinstaller \ + -y \ --name BiliNoteBackend \ --paths backend \ --distpath ./BillNote_frontend/src-tauri/bin \ diff --git a/docker-compose.gpu.yml b/docker-compose.gpu.yml index 9e9a56d..1b1fdbc 100644 --- a/docker-compose.gpu.yml +++ b/docker-compose.gpu.yml @@ -5,6 +5,9 @@ services: build: context: . dockerfile: backend/Dockerfile.gpu + args: + APT_MIRROR: ${APT_MIRROR:-mirrors.tuna.tsinghua.edu.cn} + PIP_INDEX: ${PIP_INDEX:-https://pypi.tuna.tsinghua.edu.cn/simple} env_file: - .env environment: diff --git a/docker-compose.yml b/docker-compose.yml index d7d09dd..4f5383a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,6 +5,9 @@ services: build: context: . dockerfile: backend/Dockerfile + args: + APT_MIRROR: ${APT_MIRROR:-mirrors.tuna.tsinghua.edu.cn} + PIP_INDEX: ${PIP_INDEX:-https://pypi.tuna.tsinghua.edu.cn/simple} env_file: - .env environment: