Update Dockerfile
Browse files- Dockerfile +19 -19
Dockerfile
CHANGED
|
@@ -4,10 +4,9 @@ FROM python:3.11-slim
|
|
| 4 |
# 环境变量
|
| 5 |
ENV DEBIAN_FRONTEND=noninteractive \
|
| 6 |
PYTHONUNBUFFERED=1 \
|
| 7 |
-
# 强制 uv 使用系统 Python
|
| 8 |
UV_SYSTEM_PYTHON=1
|
| 9 |
|
| 10 |
-
# 1. 安装系统依赖
|
| 11 |
RUN apt-get update && apt-get install -y \
|
| 12 |
curl \
|
| 13 |
git \
|
|
@@ -28,47 +27,48 @@ RUN pip install --no-cache-dir uv
|
|
| 28 |
# 设置工作目录
|
| 29 |
WORKDIR /app
|
| 30 |
|
| 31 |
-
# 4.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
COPY . .
|
| 33 |
|
| 34 |
-
#
|
| 35 |
WORKDIR /app/backend
|
| 36 |
-
|
| 37 |
-
# 策略:
|
| 38 |
-
# 1. 删除锁文件防止跨平台冲突
|
| 39 |
-
# 2. 尝试用 uv 导出依赖到 requirements.txt (如果 pyproject.toml 存在)
|
| 40 |
-
# 3. 如果导出失败(或没有 pyproject.toml),则尝试直接使用现有的 requirements.txt
|
| 41 |
-
# 4. 最后用 pip 安装
|
| 42 |
RUN rm -f uv.lock && \
|
| 43 |
if [ -f pyproject.toml ]; then \
|
| 44 |
echo "Found pyproject.toml, exporting requirements..."; \
|
| 45 |
-
uv export --format requirements-txt --output-file export_req.txt || echo "uv export failed
|
| 46 |
fi && \
|
| 47 |
if [ -f export_req.txt ]; then \
|
| 48 |
pip install --no-cache-dir -r export_req.txt; \
|
| 49 |
elif [ -f requirements.txt ]; then \
|
| 50 |
-
echo "Using existing requirements.txt..."; \
|
| 51 |
pip install --no-cache-dir -r requirements.txt; \
|
| 52 |
else \
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
exit 1; \
|
| 56 |
fi
|
| 57 |
|
| 58 |
-
#
|
| 59 |
WORKDIR /app/frontend
|
| 60 |
RUN npm install --legacy-peer-deps
|
| 61 |
|
| 62 |
-
#
|
| 63 |
RUN rm -f /etc/nginx/sites-enabled/default
|
| 64 |
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
| 65 |
|
| 66 |
-
#
|
| 67 |
WORKDIR /app
|
| 68 |
COPY start.sh .
|
| 69 |
RUN chmod +x start.sh
|
| 70 |
|
| 71 |
-
#
|
| 72 |
RUN chmod -R 777 /app && \
|
| 73 |
chmod -R 777 /var/log/nginx && \
|
| 74 |
chmod -R 777 /var/lib/nginx && \
|
|
|
|
| 4 |
# 环境变量
|
| 5 |
ENV DEBIAN_FRONTEND=noninteractive \
|
| 6 |
PYTHONUNBUFFERED=1 \
|
|
|
|
| 7 |
UV_SYSTEM_PYTHON=1
|
| 8 |
|
| 9 |
+
# 1. 安装系统依赖
|
| 10 |
RUN apt-get update && apt-get install -y \
|
| 11 |
curl \
|
| 12 |
git \
|
|
|
|
| 27 |
# 设置工作目录
|
| 28 |
WORKDIR /app
|
| 29 |
|
| 30 |
+
# 4. [关键步骤] 拉取 MiroFish 源代码
|
| 31 |
+
# 我们先克隆到临时目录,然后移动所有文件到 /app
|
| 32 |
+
# 这样可以避免 "directory not empty" 的错误
|
| 33 |
+
RUN git clone https://github.com/666ghj/MiroFish.git /tmp/repo && \
|
| 34 |
+
cp -r /tmp/repo/* . && \
|
| 35 |
+
rm -rf /tmp/repo
|
| 36 |
+
|
| 37 |
+
# 5. [覆盖配置] 复制当前 Space 里的配置文件
|
| 38 |
+
# 这会用你上传的 nginx.conf 和 start.sh 覆盖仓库里可能存在的同名文件
|
| 39 |
COPY . .
|
| 40 |
|
| 41 |
+
# 6. 后端依赖安装
|
| 42 |
WORKDIR /app/backend
|
| 43 |
+
# 删除锁文件防止兼容性问题,然后导出依赖并安装
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
RUN rm -f uv.lock && \
|
| 45 |
if [ -f pyproject.toml ]; then \
|
| 46 |
echo "Found pyproject.toml, exporting requirements..."; \
|
| 47 |
+
uv export --format requirements-txt --output-file export_req.txt || echo "uv export failed"; \
|
| 48 |
fi && \
|
| 49 |
if [ -f export_req.txt ]; then \
|
| 50 |
pip install --no-cache-dir -r export_req.txt; \
|
| 51 |
elif [ -f requirements.txt ]; then \
|
|
|
|
| 52 |
pip install --no-cache-dir -r requirements.txt; \
|
| 53 |
else \
|
| 54 |
+
# 如果这里还报错,那就是 GitHub 仓库本身有问题,但通常不会
|
| 55 |
+
pip install --no-cache-dir . || echo "Install local package failed, trying to continue..."; \
|
|
|
|
| 56 |
fi
|
| 57 |
|
| 58 |
+
# 7. 前端依赖安装
|
| 59 |
WORKDIR /app/frontend
|
| 60 |
RUN npm install --legacy-peer-deps
|
| 61 |
|
| 62 |
+
# 8. Nginx 配置
|
| 63 |
RUN rm -f /etc/nginx/sites-enabled/default
|
| 64 |
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
| 65 |
|
| 66 |
+
# 9. 启动脚本权限
|
| 67 |
WORKDIR /app
|
| 68 |
COPY start.sh .
|
| 69 |
RUN chmod +x start.sh
|
| 70 |
|
| 71 |
+
# 10. 权限放行
|
| 72 |
RUN chmod -R 777 /app && \
|
| 73 |
chmod -R 777 /var/log/nginx && \
|
| 74 |
chmod -R 777 /var/lib/nginx && \
|