Files
qihuaiflow/Dockerfile
T

79 lines
3.3 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
FROM python:3.11-slim
WORKDIR /app
# ============================================================
# 系统依赖(含编译 bcrypt/cryptography 所需的 build-essential)
# 使用清华镜像加速(国内环境)
# ============================================================
RUN sed -i 's|deb.debian.org|mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list.d/debian.sources 2>/dev/null || true
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
ca-certificates \
build-essential \
libffi-dev \
libssl-dev \
default-mysql-client \
redis-tools \
netcat-openbsd \
nginx \
&& rm -rf /var/lib/apt/lists/*
# ============================================================
# 安装 Node.js(用于前端构建)
# ============================================================
RUN sed -i 's|deb.debian.org|mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list.d/debian.sources 2>/dev/null || true
RUN apt-get update && apt-get install -y --no-install-recommends \
nodejs \
npm \
&& rm -rf /var/lib/apt/lists/*
# ============================================================
# 复制项目源码
# ============================================================
COPY backend/ /app/backend/
COPY frontend/ /app/frontend/
COPY migrations/ /app/migrations/
COPY nginx.conf /app/nginx.conf
COPY VERSION /app/VERSION
COPY CHANGELOG.md /app/CHANGELOG.md
COPY run.sh /app/run.sh
# ============================================================
# 安装 Python 依赖到虚拟环境(与 run.sh 的 .venv 优先逻辑一致)
# 说明:run.sh 启动时会优先使用 $PYTHON_DIR/.venv,
# 此处把依赖直接烤进镜像的 .venv,避免运行时再联网安装导致崩溃循环。
# ============================================================
RUN python3 -m venv /app/backend/python/.venv && \
/app/backend/python/.venv/bin/pip install --no-cache-dir \
-r /app/backend/python/requirements.txt \
-i https://pypi.tuna.tsinghua.edu.cn/simple
# ============================================================
# 安装前端依赖并构建(使用国内 npm 镜像)
# ============================================================
RUN cd /app/frontend && npm install --registry=https://registry.npmmirror.com && npm run build
# 验证前端构建产物
RUN test -f /app/frontend/dist/index.html || (echo "ERROR: 前端构建失败,index.html 不存在" && exit 1)
RUN test -d /app/frontend/dist/assets || (echo "ERROR: 前端构建失败,assets 目录不存在" && exit 1)
RUN echo "前端构建完成,dist 目录大小: $(du -sh /app/frontend/dist | cut -f1)"
# ============================================================
# 配置 nginx:移除默认站点,写入自定义配置
# ============================================================
RUN rm -f /etc/nginx/sites-enabled/default && \
rm -f /etc/nginx/conf.d/default.conf 2>/dev/null || true; \
cp /app/nginx.conf /etc/nginx/conf.d/aiflow.conf && \
sed -i 's/include \/etc\/nginx\/sites-enabled\/\*;/# include \/etc\/nginx\/sites-enabled\/*;/' /etc/nginx/nginx.conf && \
mkdir -p /var/log/nginx && \
chown -R www-data:www-data /var/log/nginx && \
chown -R www-data:www-data /var/lib/nginx
# 复制启动脚本并设置权限
RUN chmod +x /app/run.sh
EXPOSE 8080 18080
CMD ["/app/run.sh"]