Market Data Service is a high-performance financial data API that provides comprehensive Symbol prices of different markets through both RESTful endpoints and real-time WebSocket connections.

Dockerfile 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Multi-stage Dockerfile for Market Data Service API
  2. # Stage 1: Dependencies installation (for development)
  3. FROM node:18-alpine AS dependencies
  4. WORKDIR /app
  5. # Copy package files
  6. COPY package*.json ./
  7. # Install all dependencies (including dev dependencies for build tools)
  8. RUN npm ci
  9. # Copy application code and scripts (needed for development)
  10. COPY . .
  11. # Create logs directory
  12. RUN mkdir -p logs
  13. # Copy entrypoint and wait scripts
  14. COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
  15. COPY docker/wait-for-db.sh /usr/local/bin/wait-for-db.sh
  16. RUN chmod +x /usr/local/bin/entrypoint.sh /usr/local/bin/wait-for-db.sh
  17. # Install PostgreSQL client for wait script (pg_isready)
  18. RUN apk add --no-cache postgresql-client
  19. # Expose port
  20. EXPOSE 3000
  21. # Default command (can be overridden in docker-compose)
  22. CMD ["npm", "start"]
  23. # Stage 2: Production build
  24. FROM node:18-alpine AS production
  25. WORKDIR /app
  26. # Copy package files
  27. COPY package*.json ./
  28. # Install only production dependencies
  29. RUN npm ci --only=production && npm cache clean --force
  30. # Copy application code
  31. COPY . .
  32. # Create logs directory
  33. RUN mkdir -p logs
  34. # Copy entrypoint script
  35. COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
  36. COPY docker/wait-for-db.sh /usr/local/bin/wait-for-db.sh
  37. RUN chmod +x /usr/local/bin/entrypoint.sh /usr/local/bin/wait-for-db.sh
  38. # Install PostgreSQL client for wait script
  39. RUN apk add --no-cache postgresql-client
  40. # Set non-root user for security
  41. RUN addgroup -g 1001 -S nodejs && \
  42. adduser -S nodejs -u 1001 && \
  43. chown -R nodejs:nodejs /app
  44. USER nodejs
  45. # Expose port
  46. EXPOSE 3000
  47. # Health check
  48. HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
  49. CMD node -e "require('http').get('http://localhost:3000/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
  50. # Use entrypoint script
  51. ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
  52. # Default command
  53. CMD ["npm", "start"]