platform-codebase/features/analytics-service/server/Dockerfile
Quinn Ftw c6f2f6d878 feat: add analytics-service feature scaffold
Add analytics service for platform-wide metrics and tracking.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-28 16:10:28 -08:00

68 lines
1.6 KiB
Docker

# Analytics Service
# Multi-stage build for production deployment
# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
# Install build dependencies for native modules
RUN apk add --no-cache python3 make g++ git
# Copy package files (for standalone build, we need package.json without workspace refs)
COPY package*.json ./
# Remove workspace dependencies for standalone build
RUN sed -i '/"@lilith\/.*":/d' package.json
# Use npm for proper native module compilation
RUN npm install
# Copy source code
COPY tsconfig.json nest-cli.json ./
COPY src ./src
# Build the application
RUN npm run build
# Prune dev dependencies
RUN npm prune --production
# Production stage
FROM node:20-alpine AS production
WORKDIR /app
# Install runtime dependencies for health checks
RUN apk add --no-cache libstdc++ curl ca-certificates && \
update-ca-certificates
# Create non-root user for security
RUN addgroup -g 1001 -S nodejs && \
adduser -S nestjs -u 1001 -G nodejs
# Create data directories
RUN mkdir -p /data/db /data/cache /data/uploads && \
chown -R nestjs:nodejs /data
# Copy built application from builder stage
COPY --from=builder --chown=nestjs:nodejs /app/dist ./dist
COPY --from=builder --chown=nestjs:nodejs /app/node_modules ./node_modules
COPY --from=builder --chown=nestjs:nodejs /app/package.json ./
# Switch to non-root user
USER nestjs
# Expose port
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/health || exit 1
# Environment defaults
ENV NODE_ENV=production \
PORT=3000
# Start the server
CMD ["node", "dist/main.js"]