41 lines
962 B
Docker
41 lines
962 B
Docker
# Stage 1: Build
|
|
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/node:18-slim AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy package files
|
|
COPY package.json package-lock.json ./
|
|
|
|
# Delete package-lock.json to avoid platform specific issues and force fresh resolution
|
|
RUN rm package-lock.json
|
|
|
|
# Install dependencies
|
|
RUN npm install --legacy-peer-deps
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Build the application
|
|
RUN npm run build
|
|
|
|
# Stage 2: Production with Nginx
|
|
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx:alpine
|
|
|
|
# Remove default nginx config
|
|
RUN rm /etc/nginx/conf.d/default.conf
|
|
|
|
# Copy custom nginx config
|
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
|
|
|
# Copy built files from builder
|
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
|
|
|
# Expose port
|
|
EXPOSE 80
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
|
|
CMD wget --quiet --tries=1 --spider http://localhost/ || exit 1
|
|
|
|
# Start nginx
|
|
CMD ["nginx", "-g", "daemon off;"] |