feat(docker): streamline frontend build process and update Docker configuration

- Added a new script `build_frontend_dist.sh` to handle the building of frontend static assets.
- Updated `docker-compose.yml` to include a note about running the build script before building the frontend service.
- Modified the GitHub Actions workflow to integrate the new build script for frontend assets.
- Adjusted the Dockerfile to copy built assets directly from the `dist` directory.
- Refined the `.dockerignore` to exclude unnecessary files while keeping the `dist` directory.
This commit is contained in:
wizardchen
2026-06-10 16:02:39 +08:00
committed by lyingbug
parent fc98f000d8
commit 1c31d649a7
7 changed files with 56 additions and 57 deletions
+4 -8
View File
@@ -1,8 +1,4 @@
node_modules
dist
.git
.gitignore
README.md
.vscode
*.log
.DS_Store
*
!dist
!nginx.conf
!docker-entrypoint.sh
+5 -36
View File
@@ -1,47 +1,16 @@
# 构建阶段
FROM node:24-alpine AS build-stage
# Production image. Build static assets on the host first:
# ./scripts/build_frontend_dist.sh
FROM nginx:stable-alpine
WORKDIR /app
COPY dist /usr/share/nginx/html
# 设置环境变量,忽略类型检查错误
ENV NODE_OPTIONS="--max-old-space-size=4096"
ENV VITE_IS_DOCKER=true
# 注入前端 commit hash(构建上下文为 frontend/,无 .git,故通过构建参数传入)
ARG COMMIT_ID_ARG=unknown
ENV VITE_FRONTEND_COMMIT=${COMMIT_ID_ARG}
# 复制依赖文件
COPY package*.json ./
COPY pnpm-workspace.yaml ./
COPY packages/xlsx-0.20.2.tgz ./packages/xlsx-0.20.2.tgz
# 安装依赖
RUN npm ci
# 复制项目文件
COPY . .
# 构建应用
RUN npm run build
# 生产阶段
FROM nginx:stable-alpine AS production-stage
# 复制构建产物到nginx服务目录
COPY --from=build-stage /app/dist /usr/share/nginx/html
# 复制nginx配置模板文件
COPY nginx.conf /etc/nginx/templates/default.conf.template
# 复制启动脚本
COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
# 设置默认环境变量(MB)
ENV MAX_FILE_SIZE_MB=50
# 暴露端口
EXPOSE 80
ENTRYPOINT ["/docker-entrypoint.sh"]
ENTRYPOINT ["/docker-entrypoint.sh"]