Files
jenkins-pipeline/Dockerfile/web/lessie_official_web_Dockerfile
2025-11-27 15:17:39 +08:00

79 lines
1.7 KiB
Plaintext
Raw Permalink 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 node:20-bullseye AS builder
WORKDIR /app
# 安装编译工具和 SQLite
RUN apt-get update && \
apt-get install -y --no-install-recommends \
python3 \
make \
g++ \
gcc \
sqlite3 \
libsqlite3-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# 环境变量设置
ENV NUXT_TELEMETRY_DISABLED=1
# 复制所有源代码
COPY ./projects/lessie ./
# 删除可能从主机复制过来的 node_modules
RUN rm -rf node_modules
RUN rm -rf .pnpm-store
RUN rm -rf package-lock.json
# 安装 pnpm v9 (v10 有严格的构建脚本安全限制)
RUN npm install -g pnpm@9
# 重新安装所有依赖(在容器内从零开始编译)
RUN pnpm install --no-frozen-lockfile
# 再次尝试 rebuild better-sqlite3 以确保编译成功
RUN pnpm rebuild better-sqlite3
# 设置生产环境变量
ENV NODE_ENV=production
ENV HOST=0.0.0.0
ENV PORT=3000
# 构建 Nuxt 应用
RUN pnpm run build
RUN ls -a
FROM node:20-slim AS runtime
# 安装 nginx
RUN apt-get update && \
apt-get install -y --no-install-recommends nginx && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# 拷贝你的 nginx 配置
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=builder /app/.output /app
EXPOSE 80
WORKDIR /app
# 创建启动脚本nginx 在后台启动node 在前台运行
RUN echo '#!/bin/sh' > /start.sh && \
echo 'echo "启动 Nginx..."' >> /start.sh && \
echo 'nginx' >> /start.sh && \
echo 'echo "Nginx 已启动"' >> /start.sh && \
echo 'echo "启动 Node.js 应用..."' >> /start.sh && \
echo 'exec node /app/server/index.mjs' >> /start.sh && \
chmod +x /start.sh
# 启动脚本nginx 后台运行node 前台运行
CMD ["/start.sh"]