| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- # 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)
- # Use npm install if package-lock.json doesn't exist, otherwise use npm ci
- RUN if [ -f package-lock.json ]; then npm ci; else npm install; fi
- # 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
- # Use npm install if package-lock.json doesn't exist, otherwise use npm ci
- RUN if [ -f package-lock.json ]; then npm ci --only=production; else npm install --only=production; fi && 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"]
|