This commit is contained in:
jonathang4 2025-06-07 17:13:27 +08:00
parent 188270586a
commit 5771d34359
2 changed files with 57 additions and 46 deletions

View File

@ -1,4 +1,4 @@
FROM python:3.9-slim FROM python:3.11.4-slim
# 设置工作目录 # 设置工作目录
WORKDIR /app WORKDIR /app
@ -7,7 +7,7 @@ WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1 ENV PYTHONUNBUFFERED=1
ENV FLASK_APP=app.py ENV FLASK_APP=app.py
ENV FLASK_ENV=production # FLASK_ENV 和其他环境变量将在 docker-compose.yml 中设置
# 安装系统依赖 # 安装系统依赖
RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y \
@ -17,6 +17,9 @@ RUN apt-get update && apt-get install -y \
# 复制依赖文件 # 复制依赖文件
COPY requirements.txt . COPY requirements.txt .
# 配置pip国内镜像源 (以阿里云为例)
RUN pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# 安装Python依赖 # 安装Python依赖
RUN pip install --no-cache-dir -r requirements.txt RUN pip install --no-cache-dir -r requirements.txt

View File

@ -1,17 +1,42 @@
version: '3.8' version: '3.8'
services: services:
video-api: # 开发环境
# hs-video-api-dev:
# build: .
# container_name: hs-video-api-dev
# ports:
# - "8443:5000"
# env_file:
# - .env.dev
# environment:
# - FLASK_ENV=development
# - APP_ENV=dev
# - SECRET_KEY=${DEV_SECRET_KEY:-dev-secret-key}
# volumes:
# - ./logs:/app/logs
# restart: unless-stopped
# healthcheck:
# test: ["CMD", "curl", "-f", "http://localhost:5000/health"]
# interval: 30s
# timeout: 10s
# retries: 3
# start_period: 40s
# 测试环境
hs-video-api-test:
build: . build: .
container_name: hs-video-api container_name: hs-video-api-test
ports: ports:
- "5000:5000" - "8443:5000"
env_file:
- .env.dev-server
environment: environment:
- FLASK_ENV=production - FLASK_ENV=development
- SECRET_KEY=your-secret-key-here - APP_ENV=dev-server
- SECRET_KEY=${TEST_SECRET_KEY:-test-secret-key}
volumes: volumes:
- ./logs:/app/logs - ./logs:/app/logs
- ./uploads:/app/uploads
restart: unless-stopped restart: unless-stopped
healthcheck: healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:5000/health"] test: ["CMD", "curl", "-f", "http://localhost:5000/health"]
@ -19,42 +44,25 @@ services:
timeout: 10s timeout: 10s
retries: 3 retries: 3
start_period: 40s start_period: 40s
networks:
- video-api-network
# 可选添加Redis用于任务状态持久化 # 生产环境
# redis: hs-video-api-pro:
# image: redis:7-alpine build: .
# container_name: hs-video-redis container_name: hs-video-api-pro
# ports: ports:
# - "6379:6379" - "3300:5000"
# volumes: env_file:
# - redis_data:/data - .env.pro
# restart: unless-stopped environment:
# networks: - FLASK_ENV=production
# - video-api-network - APP_ENV=pro
- SECRET_KEY=${PROD_SECRET_KEY}
# 可选添加Nginx反向代理 volumes:
# nginx: - ./logs:/app/logs
# image: nginx:alpine restart: unless-stopped
# container_name: hs-video-nginx healthcheck:
# ports: test: ["CMD", "curl", "-f", "http://localhost:5000/health"]
# - "80:80" interval: 30s
# - "443:443" timeout: 10s
# volumes: retries: 3
# - ./nginx.conf:/etc/nginx/nginx.conf:ro start_period: 40s
# - ./ssl:/etc/nginx/ssl:ro
# depends_on:
# - video-api
# restart: unless-stopped
# networks:
# - video-api-network
networks:
video-api-network:
driver: bridge
volumes:
# redis_data:
logs:
uploads: