Spaces:
Sleeping
Sleeping
| # Use Python 3.10 | |
| FROM python:3.10-slim | |
| # Set environment variables | |
| ENV PYTHONDONTWRITEBYTECODE=1 \ | |
| PYTHONUNBUFFERED=1 \ | |
| PORT=7860 | |
| # Set work directory | |
| WORKDIR /app | |
| # Install system dependencies | |
| # Added pkg-config and libcairo2-dev (CRITICAL for xhtml2pdf/pycairo) | |
| RUN apt-get update && apt-get install -y \ | |
| gcc \ | |
| libpq-dev \ | |
| pkg-config \ | |
| libcairo2-dev \ | |
| python3-dev \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Create a non-root user with ID 1000 (Required for Hugging Face Spaces) | |
| RUN useradd -m -u 1000 user | |
| # Copy requirements first to leverage caching | |
| COPY backend/requirements.txt /app/ | |
| # Install Python dependencies (as root, so they are available system-wide) | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Copy the rest of the backend code | |
| COPY backend/ /app/ | |
| # --- PERMISSION FIX START --- | |
| # Create the staticfiles directory explicitly | |
| RUN mkdir -p /app/staticfiles | |
| # Change ownership of the application directory to the non-root user | |
| # This ensures the user can write to 'staticfiles' and 'db.sqlite3' | |
| RUN chown -R user:user /app | |
| # --- PERMISSION FIX END --- | |
| # Switch to the non-root user for all subsequent commands | |
| USER user | |
| # Run collectstatic (As the user who now owns the directory) | |
| RUN python manage.py collectstatic --noinput | |
| # Run with Gunicorn | |
| CMD ["gunicorn", "respirex_backend.wsgi:application", "--bind", "0.0.0.0:7860"] | |