MiroFish / Dockerfile
wkplhc's picture
Update Dockerfile
f25e67d verified
# 基础镜像
FROM python:3.11-slim
# 环境变量
ENV DEBIAN_FRONTEND=noninteractive \
PYTHONUNBUFFERED=1 \
UV_SYSTEM_PYTHON=1
# 1. 安装系统依赖
RUN apt-get update && apt-get install -y \
curl \
git \
nginx \
build-essential \
python3-dev \
libgl1 \
libglib2.0-0 \
&& rm -rf /var/lib/apt/lists/*
# 2. 安装 Node.js 20
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
apt-get install -y nodejs
# 3. 安装 uv
RUN pip install --no-cache-dir uv
# 设置工作目录
WORKDIR /app
# 4. 拉取代码 (因为 Space 默认不包含代码,必须手动拉取)
RUN git clone https://github.com/666ghj/MiroFish.git /tmp/repo && \
cp -r /tmp/repo/* . && \
rm -rf /tmp/repo
# 5. 复制配置文件 (覆盖仓库里的配置)
COPY . .
# 6. 后端依赖安装 (关键修复步骤)
WORKDIR /app/backend
RUN rm -f uv.lock && \
if [ -f pyproject.toml ]; then \
echo "Found pyproject.toml, exporting requirements..."; \
# 导出带哈希的依赖列表
uv export --format requirements-txt --output-file export_req.txt; \
# [修复] 删除 '-e .' 这一行,解决 pip hash 冲突报错
sed -i '/^-e/d' export_req.txt; \
# 安装依赖
pip install --no-cache-dir -r export_req.txt; \
elif [ -f requirements.txt ]; then \
pip install --no-cache-dir -r requirements.txt; \
else \
echo "No dependencies found, skipping..."; \
fi
# 7. 前端依赖安装
WORKDIR /app/frontend
RUN npm install --legacy-peer-deps
# 8. Nginx 配置
RUN rm -f /etc/nginx/sites-enabled/default
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 9. 启动脚本权限
WORKDIR /app
COPY start.sh .
RUN chmod +x start.sh
# 10. 权限放行
RUN chmod -R 777 /app && \
chmod -R 777 /var/log/nginx && \
chmod -R 777 /var/lib/nginx && \
mkdir -p /var/run/nginx && \
chmod -R 777 /var/run/nginx
EXPOSE 7860
CMD ["./start.sh"]