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 2.1KB

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