# Backend Dockerfile - NestJS FROM node:20-alpine AS builder WORKDIR /app # Copy package files and npm config COPY server/package*.json ./server/ COPY server/.npmrc ./server/ COPY shared/package*.json ./shared/ # Install dependencies with multiple mirror fallback RUN cd server && \ echo "Trying Aliyun mirror..." && \ npm install --registry=https://registry.npmmirror.com --prefer-offline --no-audit --no-fund || \ (echo "Aliyun failed, trying Tencent Cloud..." && \ npm install --registry=https://mirrors.cloud.tencent.com/npm/ --prefer-offline --no-audit --no-fund) || \ (echo "Tencent failed, trying Huawei Cloud..." && \ npm install --registry=https://repo.huaweicloud.com/repository/npm/ --prefer-offline --no-audit --no-fund) # Copy source code COPY server/src ./server/src COPY server/tsconfig.json ./server/ COPY server/nest-cli.json ./server/ COPY shared ./shared # Build RUN cd server && npm run build # Production stage FROM node:20-alpine WORKDIR /app # Copy package files and npm config COPY server/package*.json ./ COPY server/.npmrc ./ # Install production dependencies with multiple mirror fallback RUN echo "Installing production dependencies..." && \ (npm install --omit=dev --registry=https://registry.npmmirror.com --prefer-offline --no-audit --no-fund || \ npm install --omit=dev --registry=https://mirrors.cloud.tencent.com/npm/ --prefer-offline --no-audit --no-fund || \ npm install --omit=dev --registry=https://repo.huaweicloud.com/repository/npm/ --prefer-offline --no-audit --no-fund) # Copy built application COPY --from=builder /app/server/dist ./dist COPY shared ./shared # Create data directory RUN mkdir -p /app/data EXPOSE 3000 CMD ["node", "dist/main.js"]