添加docker-compose.prod

This commit is contained in:
xie7654
2025-07-04 22:52:22 +08:00
parent 87d8d5ffb4
commit d705a88bd3
19 changed files with 536 additions and 70 deletions

View File

@@ -1,46 +1,62 @@
# syntax=docker/dockerfile:1
####################
# 生产阶段
# 公共基础阶段
####################
FROM nginx:alpine AS prod
# 拷贝编译后的静态文件到 nginx
COPY --from=build /app/dist /usr/share/nginx/html
# 拷贝 nginx 配置
COPY nginx.conf /etc/nginx/conf.d/default.conf
####################
# 开发阶段
####################
FROM node:22.17.0 AS dev
FROM node:22.17.0 AS base
WORKDIR /app
ENV PNPM_SKIP_PROMPT=true
# 拷贝项目
COPY . .
COPY /apps/web-antd/.env.docker /apps/web-antd/.env.local
# 安装 pnpm(官方推荐 corepack更好
# 安装 pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate
# 安装依赖(一定要在 monorepo 根目录,保证 workspace 有效)
# 清理依赖缓存
RUN pnpm store prune && rm -rf $(pnpm store path) && \
rm -rf node_modules .npmrc package-lock.json pnpm-lock.yaml .pnpm-store .turbo && \
find . -name 'node_modules' -type d -prune -exec rm -rf '{}' +
RUN npm run clean
RUN yes | pnpm recursive install
# 安装依赖
RUN pnpm install --force
# 设置前端工作目录(根据实际情况修改)
# 暴露前端 dev server 端口
EXPOSE 5678
#CMD ["tail", "-f", "/dev/null"]
####################
# 开发阶段
####################
# 默认启动 dev server
FROM base AS dev
# 暴露端口(根据需要)
EXPOSE 5678
# CMD ["tail", "-f", "/dev/null"]
# 启动开发服务器
CMD ["npm", "run", "dev:antd"]
# --- 构建阶段 ---
FROM base AS build
# 构建生产版本
RUN npm run build:antd
# --- 生产阶段 ---
FROM nginx:1.25-alpine AS prod
# 删除默认配置
RUN rm -rf /usr/share/nginx/html/*
# 从构建阶段拷贝打包产物到 nginx html 目录
COPY --from=build /app/apps/web-antd/dist /usr/share/nginx/html
# 如果有需要,也可以拷贝自定义 nginx 配置
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 5268
# 默认启动 nginx
CMD ["nginx", "-g", "daemon off;"]