# Base stage for all Python services FROM python:3.11-slim AS base # Set working directory WORKDIR /app # Install common system dependencies for MySQL RUN apt-get update && apt-get install -y \ gcc \ default-libmysqlclient-dev \ && rm -rf /var/lib/apt/lists/* # Copy and install unified requirements COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Create non-root user for security RUN groupadd -r appuser && useradd -r -g appuser appuser # --- API Gateway Service Stage --- FROM base AS api_gateway # Copy shared module COPY shared/ ./shared/ # Copy application code COPY api_service/app/ ./app/ # Switch to non-root user USER appuser # Expose port EXPOSE 8000 # Health check HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ CMD curl -f http://localhost:8000/health || exit 1 # Start application CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] # --- Auth Service Stage --- FROM base AS auth_service # Copy shared module COPY shared/ ./shared/ # Copy application code COPY auth_service/app/ ./app/ # Switch to non-root user USER appuser # Expose port EXPOSE 8000 # Health check HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ CMD curl -f http://localhost:8000/health || exit 1 # Start application CMD ["python", "-m", "app.main"] # --- Task Scheduler Service Stage --- FROM base AS task_scheduler # Copy shared module COPY shared/ ./shared/ # Copy application code COPY task_scheduler/app/ ./app/ # Switch to non-root user USER appuser # Start Celery Beat scheduler CMD ["celery", "-A", "app.celery_app", "beat", "--loglevel=info"] # --- Sign-in Executor Service Stage --- FROM base AS signin_executor # Copy shared module COPY shared/ ./shared/ # Copy application code COPY signin_executor/app/ ./app/ # Switch to non-root user USER appuser # Expose port EXPOSE 8000 # Health check HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ CMD curl -f http://localhost:8000/health || exit 1 # Start application CMD ["python", "-m", "app.main"]