# ============================================================================= # Wallet Service Dockerfile # ============================================================================= # Build stage FROM node:20-alpine AS builder WORKDIR /app # Copy package files COPY package*.json ./ COPY tsconfig*.json ./ COPY nest-cli.json ./ # Copy Prisma schema COPY prisma ./prisma/ # Install dependencies RUN npm install # Generate Prisma client (dummy DATABASE_URL for build time only) RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate # Copy source code COPY src ./src # Build TypeScript RUN npm run build # Verify build output exists RUN ls -la dist/ && test -f dist/main.js # Production stage - use Debian slim for OpenSSL compatibility FROM node:20-slim WORKDIR /app # Install OpenSSL and wget for health checks RUN apt-get update && apt-get install -y --no-install-recommends \ openssl \ wget \ && rm -rf /var/lib/apt/lists/* # Install production dependencies only COPY package*.json ./ RUN npm install --omit=dev # Copy Prisma schema and generate client (dummy DATABASE_URL for build time only) COPY prisma ./prisma/ RUN DATABASE_URL="postgresql://user:pass@localhost:5432/db" npx prisma generate # Copy built files COPY --from=builder /app/dist ./dist # Create non-root user RUN groupadd -g 1001 nodejs && \ useradd -u 1001 -g nodejs nestjs # Switch to non-root user USER nestjs # Expose port EXPOSE 3001 # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \ CMD wget -q --spider http://localhost:3001/health || exit 1 # Start service CMD ["node", "dist/main.js"]