|
| 1 | +# Backend-only Dockerfile for Development |
| 2 | +# This Dockerfile builds only the backend (no frontend build) |
| 3 | +# Use this for docker-compose.dev.yaml where frontend runs separately |
| 4 | + |
| 5 | +# ============================================================================= |
| 6 | +# Backend Dependencies Stage |
| 7 | +# ============================================================================= |
| 8 | +FROM python:3.11-slim AS backend-deps |
| 9 | + |
| 10 | +WORKDIR /app |
| 11 | + |
| 12 | +# Install system dependencies |
| 13 | +RUN apt-get update && apt-get install -y \ |
| 14 | + g++ \ |
| 15 | + gcc \ |
| 16 | + git \ |
| 17 | + && rm -rf /var/lib/apt/lists/* |
| 18 | + |
| 19 | +# Copy requirements and install Python dependencies |
| 20 | +COPY requirements.docker.txt ./requirements.txt |
| 21 | +RUN pip install --no-cache-dir -r requirements.txt |
| 22 | + |
| 23 | +# ============================================================================= |
| 24 | +# Final Runtime Stage |
| 25 | +# ============================================================================= |
| 26 | +FROM python:3.11-slim AS final |
| 27 | + |
| 28 | +# Set working directory |
| 29 | +WORKDIR /app |
| 30 | + |
| 31 | +# Install runtime dependencies |
| 32 | +RUN apt-get update && apt-get install -y \ |
| 33 | + curl \ |
| 34 | + git \ |
| 35 | + poppler-utils \ |
| 36 | + && rm -rf /var/lib/apt/lists/* |
| 37 | + |
| 38 | +# Copy Python dependencies from backend-deps stage |
| 39 | +COPY --from=backend-deps /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages |
| 40 | +COPY --from=backend-deps /usr/local/bin /usr/local/bin |
| 41 | + |
| 42 | +# Copy application code (explicitly copy only necessary directories) |
| 43 | +# Security: Explicitly copy only required source code to prevent sensitive data exposure |
| 44 | +# .dockerignore provides additional protection as a defense-in-depth measure |
| 45 | +COPY src/ ./src/ |
| 46 | +# Copy guardrails configuration (required for NeMo Guardrails) |
| 47 | +COPY data/config/guardrails/ ./data/config/guardrails/ |
| 48 | + |
| 49 | +# Build arguments for version injection |
| 50 | +ARG VERSION=0.0.0 |
| 51 | +ARG GIT_SHA=unknown |
| 52 | +ARG BUILD_TIME=unknown |
| 53 | + |
| 54 | +# Set environment variables |
| 55 | +ENV VERSION=$VERSION |
| 56 | +ENV GIT_SHA=$GIT_SHA |
| 57 | +ENV BUILD_TIME=$BUILD_TIME |
| 58 | +ENV DOCKER_IMAGE=warehouse-assistant:$VERSION |
| 59 | +ENV PYTHONPATH=/app |
| 60 | +ENV PYTHONUNBUFFERED=1 |
| 61 | + |
| 62 | +# Create non-root user for security |
| 63 | +RUN groupadd -r appuser && \ |
| 64 | + useradd -r -g appuser appuser && \ |
| 65 | + chown -R appuser:appuser /app |
| 66 | +USER appuser |
| 67 | + |
| 68 | +# Health check |
| 69 | +HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ |
| 70 | + CMD curl -f http://localhost:8001/api/v1/health || exit 1 |
| 71 | + |
| 72 | +# Expose port |
| 73 | +EXPOSE 8001 |
| 74 | + |
| 75 | +# Start command |
| 76 | +CMD ["uvicorn", "src.api.app:app", "--host", "0.0.0.0", "--port", "8001"] |
| 77 | + |
0 commit comments