Hoghoghi / Dockerfile
Really-amin's picture
Upload 143 files
c636ebf verified
raw
history blame
1.75 kB
# Multi-stage build for production
FROM python:3.10-slim as builder
# Install build dependencies
RUN apt-get update && apt-get install -y \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Create virtual environment
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Copy requirements and install dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Production stage
FROM python:3.10-slim
# Create non-root user for security
RUN groupadd -r appuser && useradd -r -g appuser appuser
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
poppler-utils \
tesseract-ocr \
libgl1 \
curl \
nginx \
&& rm -rf /var/lib/apt/lists/*
# Copy virtual environment from builder
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Set working directory
WORKDIR /app
# Create application directories with proper permissions
RUN mkdir -p /app/data /app/cache /app/logs /app/uploads /app/backups \
&& chown -R appuser:appuser /app
# Copy application files
COPY --chown=appuser:appuser . .
# Make startup script executable
RUN chmod +x start.sh
# Set environment variables
ENV PYTHONPATH=/app
ENV DATABASE_PATH=/app/data/legal_dashboard.db
ENV TRANSFORMERS_CACHE=/app/cache
ENV HF_HOME=/app/cache
ENV LOG_LEVEL=INFO
ENV ENVIRONMENT=production
# Switch to non-root user
USER appuser
# Expose port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:8000/api/health || exit 1
# Run application
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4"]