File size: 1,384 Bytes
9229549
c6723e1
6fd9abb
9229549
 
 
 
6fd9abb
9229549
6fd9abb
 
9229549
 
6fd9abb
 
4048976
9229549
53e0621
9229549
6fd9abb
 
9229549
 
 
 
 
 
 
6fd9abb
 
9229549
6fd9abb
 
9229549
 
 
 
 
 
 
 
 
 
4048976
 
9229549
6fd9abb
 
9229549
58a8161
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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"]