# Multi-stage Docker build for COBY Multi-Exchange Data Aggregation System FROM python:3.11-slim as base # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ PYTHONPATH=/app \ PIP_NO_CACHE_DIR=1 \ PIP_DISABLE_PIP_VERSION_CHECK=1 # Install system dependencies RUN apt-get update && apt-get install -y \ gcc \ g++ \ libpq-dev \ curl \ && rm -rf /var/lib/apt/lists/* # Create app user RUN groupadd -r coby && useradd -r -g coby coby # Set work directory WORKDIR /app # Copy requirements first for better caching COPY requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir -r requirements.txt # Copy application code COPY . . # Create necessary directories RUN mkdir -p logs data && \ chown -R coby:coby /app # Switch to non-root user USER coby # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD python -c "import requests; requests.get('http://localhost:8080/health', timeout=5)" || exit 1 # Default command CMD ["python", "-m", "COBY.main"] # Development stage FROM base as development USER root # Install development dependencies RUN pip install --no-cache-dir pytest pytest-asyncio pytest-cov black flake8 mypy # Install debugging tools RUN apt-get update && apt-get install -y \ vim \ htop \ net-tools \ && rm -rf /var/lib/apt/lists/* USER coby # Override command for development CMD ["python", "-m", "COBY.main", "--debug"] # Production stage FROM base as production # Copy only necessary files for production COPY --from=base /app /app # Set production environment ENV ENVIRONMENT=production \ DEBUG=false \ LOG_LEVEL=INFO # Expose ports EXPOSE 8080 8081 # Use production command CMD ["python", "-m", "COBY.main"]