| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- # Multi-stage Dockerfile for Market Data Service API
- # Stage 1: Dependencies installation (for development)
- FROM node:18-alpine AS dependencies
- WORKDIR /app
- # Copy package files
- COPY package*.json ./
- # Install all dependencies (including dev dependencies for build tools)
- RUN npm ci
- # Copy application code and scripts (needed for development)
- COPY . .
- # Create logs directory
- RUN mkdir -p logs
- # Copy entrypoint and wait scripts
- COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
- COPY docker/wait-for-db.sh /usr/local/bin/wait-for-db.sh
- RUN chmod +x /usr/local/bin/entrypoint.sh /usr/local/bin/wait-for-db.sh
- # Install PostgreSQL client for wait script (pg_isready)
- RUN apk add --no-cache postgresql-client
- # Expose port
- EXPOSE 3000
- # Default command (can be overridden in docker-compose)
- CMD ["npm", "start"]
- # Stage 2: Production build
- FROM node:18-alpine AS production
- WORKDIR /app
- # Copy package files
- COPY package*.json ./
- # Install only production dependencies
- RUN npm ci --only=production && npm cache clean --force
- # Copy application code
- COPY . .
- # Create logs directory
- RUN mkdir -p logs
- # Copy entrypoint script
- COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
- COPY docker/wait-for-db.sh /usr/local/bin/wait-for-db.sh
- RUN chmod +x /usr/local/bin/entrypoint.sh /usr/local/bin/wait-for-db.sh
- # Install PostgreSQL client for wait script
- RUN apk add --no-cache postgresql-client
- # Set non-root user for security
- RUN addgroup -g 1001 -S nodejs && \
- adduser -S nodejs -u 1001 && \
- chown -R nodejs:nodejs /app
- USER nodejs
- # Expose port
- EXPOSE 3000
- # Health check
- HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
- CMD node -e "require('http').get('http://localhost:3000/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
- # Use entrypoint script
- ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
- # Default command
- CMD ["npm", "start"]
|