🐳 chore: 优化打包速度

使用国内镜像
This commit is contained in:
kalicyh 2025-02-18 13:07:29 +08:00
parent 511c26d8a4
commit 188a7b8bb7
3 changed files with 16 additions and 687 deletions

View file

@ -1,28 +1,25 @@
# 第一阶段:前端构建
FROM node:18 AS frontend-builder
FROM ccr.ccs.tencentyun.com/kalicyh/node:18-alpine AS frontend-builder
WORKDIR /app/ZhiKongTaiWeb
RUN corepack enable && yarn config set registry https://registry.npmmirror.com
COPY ZhiKongTaiWeb/package.json ZhiKongTaiWeb/yarn.lock ./
RUN mkdir node_modules && yarn install --frozen-lockfile
RUN yarn install --frozen-lockfile
COPY ZhiKongTaiWeb .
RUN yarn build
# 第二阶段:构建 Python 依赖
FROM ccr.ccs.tencentyun.com/kalicyh/poetry:v3.10_latest AS builder
WORKDIR /app
COPY pyproject.toml poetry.lock /app/
# 同时拷贝本地环境.venv
COPY . .
# 检查是否有缺失
RUN poetry install --no-root
# 第三阶段:生产镜像
FROM python:3.10-slim
WORKDIR /opt/xiaozhi-esp32-server
# 使用清华源加速apt安装
RUN rm -rf /etc/apt/sources.list.d/* && \
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware" > /etc/apt/sources.list && \
@ -34,13 +31,10 @@ RUN rm -rf /etc/apt/sources.list.d/* && \
apt-get clean
# 从构建阶段复制虚拟环境和前端构建产物
COPY --from=builder /app/.venv /opt/venv
COPY --from=frontend-builder /app/ZhiKongTaiWeb/dist /opt/xiaozhi-esp32-server/manager/static/webui
COPY --from=frontend-builder /app/ZhiKongTaiWeb/dist /app/manager/static/webui
# 设置虚拟环境路径
ENV PATH="/opt/venv/bin:$PATH"
# 复制应用代码
COPY . .
ENV PATH="/app/.venv/bin:$PATH"
# 启动应用
CMD ["python", "app.py"]
ENTRYPOINT ["poetry", "run", "python"]
CMD ["app.py"]

670
poetry.lock generated

File diff suppressed because it is too large Load diff

View file

@ -28,11 +28,6 @@ setuptools = "^75.8.0"
loguru = "^0.7.3"
[[tool.poetry.source]]
name = "mirrors"
url = "https://pypi.tuna.tsinghua.edu.cn/simple/"
priority = "primary"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"