File size: 1,903 Bytes
1e33aa2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8786ea1
 
1e33aa2
8786ea1
 
1e33aa2
 
 
8786ea1
1e33aa2
 
8786ea1
 
1e33aa2
 
 
 
 
 
 
 
 
8786ea1
1e33aa2
 
 
 
 
8786ea1
 
1e33aa2
 
 
8786ea1
1e33aa2
8786ea1
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# # Use python 3.9 or 3.10
# FROM python:3.12

# # Set the working directory
# WORKDIR /code

# # Copy the requirements file
# COPY ./requirements.txt /code/requirements.txt

# # Install dependencies (No cache to save space, though HF has 16GB)
# RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

# # Copy the rest of your code
# COPY . /code

# # Create a non-root user (Hugging Face Security Requirement)
# RUN useradd -m -u 1000 user
# USER user
# ENV HOME=/home/user \
# 	PATH=/home/user/.local/bin:$PATH

# # Expose port 7860 (Hugging Face specific port)
# EXPOSE 7860

# # Start the app on port 7860
# CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]



# 1. Use Python 3.12 as requested
FROM python:3.12

# 2. Set working directory
WORKDIR /code

# 3. Create the user 1000 FIRST
# Hugging Face Spaces run as user 1000 by default. We create it explicitly here.
RUN useradd -m -u 1000 user

# 4. Copy requirements and install dependencies
COPY ./requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

# 5. FIX PERMISSIONS (The Critical Step)
# We create the empty folders for your databases and give 'user' full ownership.
# This prevents the "Permission Denied" error when the app tries to write to them.
RUN mkdir -p /code/chroma_db_Ayurveda \
             /code/chroma_db_Lifestyle \
             /code/chroma_db_Mental_health \
             /code/chroma_db_Yoga \
             /code/chroma_db_psychology && \
    chown -R user:user /code

# 6. Copy the rest of your code
# We use '--chown=user' so the copied files belong to the user, not root.
COPY --chown=user . /code

# 7. Switch to the non-root user for security
USER user

# 8. Set environment variables
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

# 9. Start the app
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]