From 1ce8b41bdeae4abf69a17ecb2b87185956b9834e Mon Sep 17 00:00:00 2001 From: Paper-Dragon <2678885646@qq.com> Date: Fri, 4 Jul 2025 00:16:39 +0800 Subject: [PATCH] Add GPU support with Docker enhancements - Introduced a `Dockerfile.gpu` for GPU-enabled backend setup. - Added `docker-compose.gpu.yml` to utilize GPU resources via NVIDIA. - Fixed Nginx configuration for GPU backend port changes. --- backend/Dockerfile.gpu | 15 ++++++++++++++ docker-compose.gpu.yml | 44 ++++++++++++++++++++++++++++++++++++++++++ nginx/default.conf | 4 ++-- 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 backend/Dockerfile.gpu create mode 100644 docker-compose.gpu.yml diff --git a/backend/Dockerfile.gpu b/backend/Dockerfile.gpu new file mode 100644 index 0000000..0eb3538 --- /dev/null +++ b/backend/Dockerfile.gpu @@ -0,0 +1,15 @@ +FROM nvidia/cuda:12.6.0-cudnn-runtime-ubuntu24.04 + +RUN apt update && \ + apt install -y ffmpeg python3-pip && \ + apt clean all + +# 设置 Hugging Face 镜像源环境变量 +ENV HF_ENDPOINT=https://hf-mirror.com + +WORKDIR /app +COPY ./backend /app +RUN pip install --no-cache-dir -i https://pypi.mirrors.ustc.edu.cn/simple -r requirements.txt --break-system-packages +RUN pip install --no-cache-dir -i https://pypi.mirrors.ustc.edu.cn/simple transformers[torch]>=4.23 --break-system-packages + +CMD ["python3", "main.py"] diff --git a/docker-compose.gpu.yml b/docker-compose.gpu.yml new file mode 100644 index 0000000..9e9a56d --- /dev/null +++ b/docker-compose.gpu.yml @@ -0,0 +1,44 @@ + +services: + backend: + container_name: bilinote-backend + build: + context: . + dockerfile: backend/Dockerfile.gpu + env_file: + - .env + environment: + - BACKEND_PORT=${BACKEND_PORT} + - BACKEND_HOST=${BACKEND_HOST} + volumes: + - ./backend:/app + expose: + - "${BACKEND_PORT}" # 不再对外暴露,用于 nginx 内部通信 + deploy: + resources: + reservations: + devices: + - driver: "nvidia" + count: "all" + capabilities: ["gpu"] + + frontend: + container_name: bilinote-frontend + build: + context: . + dockerfile: BillNote_frontend/Dockerfile + env_file: + - .env + expose: + - "80" # 不暴露给宿主机,只供 nginx 访问 + + nginx: + container_name: bilinote-nginx + image: nginx:1.25-alpine + ports: + - "${APP_PORT}:80" + volumes: + - ./nginx/default.conf:/etc/nginx/conf.d/default.conf + depends_on: + - backend + - frontend diff --git a/nginx/default.conf b/nginx/default.conf index 318afa6..865352d 100644 --- a/nginx/default.conf +++ b/nginx/default.conf @@ -8,13 +8,13 @@ server { # 所有 /api 请求代理给 backend 容器 location /api/ { - proxy_pass http://backend:8000; + proxy_pass http://backend:8483; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } location /static/ { - proxy_pass http://backend:8000/static/; + proxy_pass http://backend:8483/static/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr;