| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- # ============================================
- # Build stage for Frontend with multi-registry support
- # Node.js + Nginx 多镜像源支持
- # ============================================
- # 使用方式:
- # docker build -t web:latest -f shop-recycle-web/Dockerfile.multiarch . # 默认使用官方镜像
- # docker build --build-arg NODE_REGISTRY=registry.aliyuncs.com -t web:latest -f shop-recycle-web/Dockerfile.multiarch .
- ARG NODE_REGISTRY=node
- ARG NGINX_REGISTRY=nginx
- # ====== Build Stage ======
- FROM ${NODE_REGISTRY}:18-alpine AS builder
- ARG BUILD_NUMBER=local
- ARG GIT_COMMIT=unknown
- WORKDIR /build
- # Copy package files
- COPY shop-recycle-web/package*.json ./
- # Install dependencies (cached layer - only changes if package.json changes)
- RUN npm ci
- # Copy source code
- COPY shop-recycle-web/src ./src
- COPY shop-recycle-web/public ./public
- COPY shop-recycle-web/vite.config.js ./
- COPY shop-recycle-web/index.html ./
- # Build application
- RUN npm run build
- # ====== Runtime Stage ======
- FROM ${NGINX_REGISTRY}:1.25-alpine
- LABEL maintainer="shop-recycle"
- LABEL service="shop-recycle-web"
- LABEL build.number=${BUILD_NUMBER}
- LABEL git.commit=${GIT_COMMIT}
- ENV TZ=Asia/Shanghai
- # Remove default nginx config
- RUN rm -rf /etc/nginx/conf.d/default.conf
- # Copy nginx configuration
- COPY shop-recycle-web/nginx.conf /etc/nginx/conf.d/default.conf
- # Copy built static files from builder stage
- COPY --from=builder /build/dist /usr/share/nginx/html
- EXPOSE 80
- # Health check
- HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
- CMD wget --no-verbose --tries=1 --spider http://localhost/health || exit 0
- ENTRYPOINT ["nginx", "-g", "daemon off;"]
|