File size: 1,623 Bytes
0bb49b0
 
 
 
 
68d341f
a7de04e
0bb49b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a7de04e
0bb49b0
 
 
22911db
 
 
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
FROM python:3.11-slim

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1 \
    PORT=7860 \
    MEDIA_ROOT=/home/user/app/media

# Install required system packages for OpenCV
RUN apt-get update && apt-get install -y --no-install-recommends \
    libgl1 \
    libglib2.0-0 \
    libsm6 \
    libxext6 \
    libxrender1 \
    && rm -rf /var/lib/apt/lists/*

# Set up a new user called "user" with user ID 1000 (Required for Hugging Face Spaces)
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

WORKDIR $HOME/app

# Copy requirements separately to cache the layer
COPY --chown=user requirements.txt ./

# Install python dependencies
RUN pip install --upgrade pip && \
    pip install -r requirements.txt

# Copy project files with proper ownership
COPY --chown=user . .

# Create necessary directories with proper user permissions
RUN mkdir -p $HOME/app/staticfiles $HOME/app/media

EXPOSE 7860

# Run migrations, collect static files, seed catalog only when empty, then start Gunicorn.
# RUN_RESET_CATALOG=1 can still be used for a full reset when explicitly requested.
CMD ["sh", "-c", "python manage.py migrate && python manage.py collectstatic --noinput && if [ \"${RUN_RESET_CATALOG:-0}\" = \"1\" ]; then python manage.py reset_catalog; elif ! python manage.py shell -c \"from fitting_system.models import Product; import sys; sys.exit(0 if Product.objects.exists() else 1)\"; then python manage.py reset_catalog; fi && python manage.py create_admin && gunicorn config.wsgi:application --bind 0.0.0.0:${PORT:-7860} --workers 2 --timeout 120"]