Merge branch 'pr-35' into develop
Deploy / Deploy Staging (push) Failing after 1m47s
Deploy / Build Production Runtime Images (push) Has been skipped
Deploy / Deploy Production (push) Has been skipped
Deploy / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Validate Code Quality And Tests (push) Has been cancelled
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Has been cancelled
Deploy / Deploy Staging (push) Failing after 1m47s
Deploy / Build Production Runtime Images (push) Has been skipped
Deploy / Deploy Production (push) Has been skipped
Deploy / Production Browser E2E (push) Has been skipped
CI/CD Pipeline / Validate Code Quality And Tests (push) Has been cancelled
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Has been cancelled
This commit is contained in:
@@ -22,7 +22,7 @@ class Settings(BaseSettings):
|
||||
DATABASE_POOL_SIZE: int = 20
|
||||
DATABASE_MAX_OVERFLOW: int = 40
|
||||
DATABASE_POOL_TIMEOUT: int = 30
|
||||
DATABASE_POOL_RECYLE: int = 3600
|
||||
DATABASE_POOL_RECYCLE: int = 3600
|
||||
USE_IN_MEMORY_DB: bool = False
|
||||
AUTO_CREATE_SCHEMA: bool = False
|
||||
|
||||
|
||||
+31
-38
@@ -1,51 +1,44 @@
|
||||
# ============== Stage 1: Builder ==============
|
||||
FROM python:3.12-slim AS builder
|
||||
WORKDIR /app
|
||||
ENV PYTHONUNBUFFERED=1 \
|
||||
PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/ \
|
||||
PIP_TRUSTED_HOST=mirrors.aliyun.com
|
||||
# ============================================================
|
||||
# API Dockerfile - 专门用于 FastAPI 应用
|
||||
# 优化:仅包含 API 所需的依赖
|
||||
# ============================================================
|
||||
|
||||
# Install build dependencies
|
||||
# 基础镜像:Python 3.12
|
||||
FROM python:3.12-slim-bookworm
|
||||
|
||||
# 安装系统依赖
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
gcc \
|
||||
libpq-dev \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install Python dependencies
|
||||
COPY requirements.txt ./
|
||||
RUN python -m pip install --upgrade pip setuptools wheel && \
|
||||
pip install --no-cache-dir --default-timeout=120 --retries 10 -r requirements.txt
|
||||
|
||||
# ============== Stage 2: Production ==============
|
||||
FROM python:3.12-slim AS production
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
ENV PYTHONUNBUFFERED=1 \
|
||||
PYTHONDONTWRITEBYTECODE=1 \
|
||||
PIP_NO_CACHE_DIR=1
|
||||
|
||||
# Install runtime dependencies only
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
libpq5 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
# 复制 requirements.txt(排除 worker 专用依赖)
|
||||
# API 需要 psycopg2/sqlalchemy 用于数据库连接
|
||||
# 注意:opencv、scipy 等是 worker 专用依赖,不在 API 中安装
|
||||
COPY requirements.txt /tmp/requirements.txt
|
||||
|
||||
# Copy installed packages from builder
|
||||
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
|
||||
COPY --from=builder /usr/local/bin /usr/local/bin
|
||||
# 创建虚拟环境并安装依赖
|
||||
RUN python -m venv /opt/venv \
|
||||
&& /opt/venv/bin/pip install --no-cache-dir -r /tmp/requirements.txt \
|
||||
&& rm /tmp/requirements.txt
|
||||
|
||||
# Copy application code
|
||||
ENV PYTHONPATH=/app
|
||||
COPY apps/api /app/apps/api
|
||||
COPY packages /app/packages
|
||||
COPY scripts /app/scripts
|
||||
COPY alembic /app/alembic
|
||||
# 复制应用代码
|
||||
COPY apps/api/ /app/apps/api/
|
||||
COPY packages/ /app/packages/
|
||||
COPY alembic.ini /app/alembic.ini
|
||||
COPY migrations/ /app/migrations/
|
||||
|
||||
# 设置环境变量
|
||||
ENV PATH="/opt/venv/bin:$PATH"
|
||||
ENV PYTHONPATH=/app
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
# 健康检查
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health', timeout=5)"
|
||||
|
||||
# API 入口点
|
||||
WORKDIR /app/apps/api
|
||||
EXPOSE 8000
|
||||
|
||||
# Run as non-root user for security
|
||||
RUN useradd --create-home --shell /bin/bash appuser && \
|
||||
chown -R appuser:appuser /app
|
||||
USER appuser
|
||||
|
||||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Build stage
|
||||
FROM docker.m.daocloud.io/library/node:20 AS builder
|
||||
WORKDIR /app
|
||||
ARG VITE_API_URL=http://47.98.113.167:8000
|
||||
ARG VITE_API_URL=https://saas-api.xiaoxiajianji.com
|
||||
ENV VITE_API_URL=$VITE_API_URL
|
||||
COPY apps/web/package.json apps/web/package-lock.json ./apps/web/
|
||||
WORKDIR /app/apps/web
|
||||
|
||||
@@ -1,20 +1,41 @@
|
||||
FROM python:3.12-slim
|
||||
# ============================================================
|
||||
# Worker Dockerfile - 专门用于 Celery Worker
|
||||
# 优化:仅包含 worker 任务所需的依赖,减小镜像体积
|
||||
# ============================================================
|
||||
|
||||
# 基础镜像:Python 3.12 + ffmpeg
|
||||
FROM python:3.12-slim-bookworm
|
||||
|
||||
# 安装系统依赖
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
ffmpeg \
|
||||
libsm6 \
|
||||
libxext6 \
|
||||
libgl1-mesa-glx \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
ENV PYTHONPATH=/app
|
||||
ENV PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/
|
||||
ENV PIP_TRUSTED_HOST=mirrors.aliyun.com
|
||||
COPY requirements.txt ./
|
||||
RUN set -eux; \
|
||||
sed -i 's|http://deb.debian.org/debian|https://mirrors.aliyun.com/debian|g; s|http://deb.debian.org/debian-security|https://mirrors.aliyun.com/debian-security|g' /etc/apt/sources.list.d/debian.sources; \
|
||||
apt-get -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 update; \
|
||||
apt-get -o Acquire::http::Timeout=30 -o Acquire::https::Timeout=30 install -y --no-install-recommends ffmpeg; \
|
||||
rm -rf /var/lib/apt/lists/*; \
|
||||
python -m pip install --upgrade pip setuptools wheel; \
|
||||
pip install --no-cache-dir --default-timeout=120 --retries 10 -r requirements.txt
|
||||
COPY apps/worker /app/apps/worker
|
||||
COPY packages /app/packages
|
||||
COPY scripts /app/scripts
|
||||
COPY alembic /app/alembic
|
||||
|
||||
# 安装 Python 依赖(优化顺序以利用 Docker 缓存)
|
||||
# 先安装无变化的依赖
|
||||
COPY requirements.txt /tmp/requirements.txt
|
||||
|
||||
# 安装 Python 包
|
||||
RUN pip install --no-cache-dir -r /tmp/requirements.txt
|
||||
|
||||
# 复制应用代码
|
||||
COPY apps/worker/ /app/apps/worker/
|
||||
COPY apps/api/app/config.py /app/apps/api/app/config.py
|
||||
COPY apps/api/app/core/ /app/apps/api/app/core/
|
||||
COPY packages/ /app/packages/
|
||||
COPY alembic.ini /app/alembic.ini
|
||||
COPY migrations/ /app/migrations/
|
||||
|
||||
# 设置 Python 路径
|
||||
ENV PYTHONPATH=/app
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
# Worker 入口点
|
||||
WORKDIR /app/apps/worker
|
||||
CMD ["sh", "-c", "celery -A worker_app.celery_app.celery_app worker --loglevel=info --concurrency=${WORKER_CONCURRENCY:-1} --max-tasks-per-child=${WORKER_MAX_TASKS_PER_CHILD:-100}"]
|
||||
CMD ["celery", "-A", "celery_app", "worker", "--loglevel=info", "--concurrency=2"]
|
||||
|
||||
Reference in New Issue
Block a user