Files
website/Dockerfile.production
brunoandQwen-Coder 39ae577965 Feature: Add AI Assistant, Enhanced Search, and Responsive Design Improvements
- Add AIAssistant component for intelligent user support
- Implement EnhancedSearchModal with improved search functionality
- Introduce LazyImage component for optimized image loading
- Update HeroSection with responsive design classes
- Modify Navigation to support dynamic base paths for production
- Update Dockerfile with optimized multi-stage build and health checks
- Configure docker-compose.yml with proper port mapping
- Add comprehensive responsive CSS classes in index.css
- Update routing configuration in App.tsx and main.tsx
- Add development documentation in CLAUDE.md and QWEN.md
- Configure build process with environment-specific base paths
- Add optimization roadmap documentation

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2025-11-17 15:50:09 +08:00

97 lines
2.3 KiB
Docker

# 生产环境优化 Dockerfile
# 基于测试结果的最优配置
# 构建阶段
FROM node:18-alpine AS builder
# 明确清除所有代理配置,避免网络冲突
ENV HTTP_PROXY=""
ENV HTTPS_PROXY=""
ENV http_proxy=""
ENV https_proxy=""
ENV NO_PROXY=""
ENV no_proxy=""
WORKDIR /app
# 使用国内镜像源加速包管理
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 清除 npm 代理配置并设置国内镜像源
RUN npm config delete proxy && \
npm config delete https-proxy && \
npm config set registry https://registry.npmmirror.com && \
npm config set cache /tmp/.npm --global
# 安装 pnpm
RUN npm install -g pnpm
# 复制 package 文件
COPY package.json pnpm-lock.yaml ./
# 配置 pnpm 使用国内镜像源
RUN pnpm config set registry https://registry.npmmirror.com
# 安装依赖 (使用网络优化的 pnpm)
RUN pnpm install --frozen-lockfile --prefer-offline
# 复制源代码
COPY . .
# 构建应用
RUN npm run build
# 生产阶段 - 最小化镜像
FROM node:18-alpine AS production
# 清除代理配置
ENV HTTP_PROXY=""
ENV HTTPS_PROXY=""
ENV http_proxy=""
ENV https_proxy=""
ENV NO_PROXY=""
ENV no_proxy=""
WORKDIR /app
# 使用国内镜像源
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 清除 npm 代理配置并设置国内镜像源
RUN npm config delete proxy && \
npm config delete https-proxy && \
npm config set registry https://registry.npmmirror.com
# 只安装运行时必需的工具
RUN npm install -g pnpm serve
# 复制构建产物和配置文件
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/package.json ./
COPY --from=builder /app/pnpm-lock.yaml ./
# 安装生产依赖
RUN pnpm install --prod --frozen-lockfile --prefer-offline
# 清理缓存减小镜像大小
RUN npm cache clean --force && \
pnpm store prune && \
rm -rf /tmp/* /root/.npm
# 创建非 root 用户提高安全性
RUN addgroup -g 1001 -S nodejs && \
adduser -S omniverse -u 1001
# 更改文件所有权
RUN chown -R omniverse:nodejs /app
USER omniverse
# 暴露端口
EXPOSE 5173
# 健康检查
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:5173 || exit 1
# 启动应用
CMD ["serve", "-s", "dist", "-l", "5173"]