This commit is contained in:
2026-04-09 08:52:40 +00:00
parent b80e97799f
commit 880f5caf2d
8 changed files with 144 additions and 2 deletions

15
.dockerignore Normal file
View File

@@ -0,0 +1,15 @@
.git
.gitignore
backend/.venv
backend/__pycache__
backend/app/__pycache__
frontend/node_modules
frontend/dist
storage/uploads/*
storage/processed/*
storage/covers/*
storage/hls/*
!storage/uploads/.gitkeep
!storage/processed/.gitkeep
!storage/covers/.gitkeep
!storage/hls/.gitkeep

View File

@@ -130,13 +130,16 @@ vplatform/
│ │ ├── config.py │ │ ├── config.py
│ │ ├── main.py │ │ ├── main.py
│ │ └── schemas.py │ │ └── schemas.py
│ ├── Dockerfile
│ └── requirements.txt │ └── requirements.txt
├── frontend/ ├── frontend/
│ ├── src/ │ ├── src/
│ │ ├── App.jsx │ │ ├── App.jsx
│ │ ├── main.jsx │ │ ├── main.jsx
│ │ └── styles.css │ │ └── styles.css
│ ├── Dockerfile
│ ├── index.html │ ├── index.html
│ ├── nginx.conf
│ ├── package.json │ ├── package.json
│ └── vite.config.js │ └── vite.config.js
├── storage/ ├── storage/
@@ -144,8 +147,10 @@ vplatform/
│ ├── hls/ │ ├── hls/
│ ├── processed/ │ ├── processed/
│ └── uploads/ │ └── uploads/
├── .dockerignore
├── .gitignore ├── .gitignore
├── README.md ├── README.md
├── docker-compose.yml
└── prompt.md └── prompt.md
``` ```
@@ -194,6 +199,27 @@ npm run dev
- 后端http://localhost:8000 - 后端http://localhost:8000
- 健康检查http://localhost:8000/api/health - 健康检查http://localhost:8000/api/health
## Docker 启动
如果你希望在 Ubuntu 24.04 或其他装有 Docker 的环境中快速运行,直接使用:
```bash
docker compose up --build
```
启动后访问:
- 前端http://localhost:8080
- 后端 APIhttp://localhost:8000
- 健康检查http://localhost:8000/api/health
容器方案说明:
- 后端镜像基于 `python:3.12-slim`,容器内安装 `ffmpeg`
- 前端镜像采用 Node 构建 + Nginx 静态托管
- Nginx 会把 `/api``/media` 反向代理到后端容器
- `docker-compose.yml` 把宿主机 `./storage` 挂载到容器 `/app/storage`,所以上传文件和处理结果会保留
## API 说明 ## API 说明
### `POST /api/upload` ### `POST /api/upload`

20
backend/Dockerfile Normal file
View File

@@ -0,0 +1,20 @@
FROM python:3.12-slim
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /app/backend
RUN apt-get update \
&& apt-get install -y --no-install-recommends ffmpeg \
&& rm -rf /var/lib/apt/lists/*
COPY backend/requirements.txt ./requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
COPY backend /app/backend
COPY storage /app/storage
EXPOSE 8000
CMD ["python", "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

View File

@@ -1,3 +1,4 @@
import os
from typing import Dict, List from typing import Dict, List
from fastapi import FastAPI, File, HTTPException, UploadFile from fastapi import FastAPI, File, HTTPException, UploadFile
@@ -10,10 +11,15 @@ from app.services.storage import get_upload_path, save_upload
from app.services.tasks import task_manager from app.services.tasks import task_manager
def get_allowed_origins() -> List[str]:
origins = os.getenv("CORS_ORIGINS", "http://localhost:5173,http://localhost:8080")
return [origin.strip() for origin in origins.split(",") if origin.strip()]
app = FastAPI(title="VPlatform API", version="0.1.0") app = FastAPI(title="VPlatform API", version="0.1.0")
app.add_middleware( app.add_middleware(
CORSMiddleware, CORSMiddleware,
allow_origins=["http://localhost:5173"], allow_origins=get_allowed_origins(),
allow_credentials=True, allow_credentials=True,
allow_methods=["*"], allow_methods=["*"],
allow_headers=["*"], allow_headers=["*"],

26
docker-compose.yml Normal file
View File

@@ -0,0 +1,26 @@
services:
backend:
build:
context: .
dockerfile: backend/Dockerfile
container_name: vplatform-backend
environment:
CORS_ORIGINS: http://localhost:5173,http://localhost:8080
ports:
- "8000:8000"
volumes:
- ./storage:/app/storage
restart: unless-stopped
frontend:
build:
context: .
dockerfile: frontend/Dockerfile
args:
VITE_API_BASE_URL: ""
container_name: vplatform-frontend
depends_on:
- backend
ports:
- "8080:80"
restart: unless-stopped

20
frontend/Dockerfile Normal file
View File

@@ -0,0 +1,20 @@
FROM node:20-alpine AS build
WORKDIR /app/frontend
COPY frontend/package*.json ./
RUN npm install
COPY frontend /app/frontend
ARG VITE_API_BASE_URL=
ENV VITE_API_BASE_URL=${VITE_API_BASE_URL}
RUN npm run build
FROM nginx:1.27-alpine
COPY frontend/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/frontend/dist /usr/share/nginx/html
EXPOSE 80

29
frontend/nginx.conf Normal file
View File

@@ -0,0 +1,29 @@
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
location /api/ {
proxy_pass http://backend:8000/api/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /media/ {
proxy_pass http://backend:8000/media/;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location / {
try_files $uri $uri/ /index.html;
}
}

View File

@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
const API_BASE = 'http://localhost:8000' const API_BASE = import.meta.env.VITE_API_BASE_URL || ''
const defaultForm = { const defaultForm = {
clip_seconds: 8, clip_seconds: 8,