marcosremar2 commited on
Commit
0f77915
·
1 Parent(s): 53a34c2

Fix: Set user permissions in Dockerfile for HF Spaces

Browse files
Files changed (1) hide show
  1. Dockerfile +26 -8
Dockerfile CHANGED
@@ -29,22 +29,40 @@ RUN apt-get update && \
29
 
30
  RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
31
 
32
- WORKDIR /app
 
33
 
34
- COPY requirements.txt .
 
 
 
 
 
 
 
 
 
35
 
36
  RUN python3 -m venv /opt/mineru_venv && \
37
  . /opt/mineru_venv/bin/activate && \
38
  pip install --upgrade pip && \
39
  pip install -r requirements.txt
40
 
41
- # Download model + setup config
42
- RUN wget https://github.com/opendatalab/MinerU/raw/master/scripts/download_models_hf.py -O download_models.py && \
43
- . /opt/mineru_venv/bin/activate && \
 
44
  python3 download_models.py && \
45
- wget https://github.com/opendatalab/MinerU/raw/master/magic-pdf.template.json -O /root/magic-pdf.json && \
46
- sed -i 's|"device": "cpu"|"device": "cpu"|g' /root/magic-pdf.json
 
 
 
 
 
 
47
 
48
- COPY app.py .
 
49
 
50
  CMD ["/opt/mineru_venv/bin/uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
29
 
30
  RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
31
 
32
+ # Set up a new user named "user" with user ID 1000
33
+ RUN useradd -m -u 1000 user
34
 
35
+ # Set home to the user's home directory
36
+ ENV HOME=/home/user \
37
+ PATH=/home/user/.local/bin:$PATH
38
+
39
+ # Set the working directory to the user's home directory
40
+ WORKDIR $HOME/app
41
+
42
+ # Try and run pip command after setting the user to avoid permission issues with Python
43
+ # Copy requirements first and install dependencies as root, then switch user
44
+ COPY --chown=user requirements.txt .
45
 
46
  RUN python3 -m venv /opt/mineru_venv && \
47
  . /opt/mineru_venv/bin/activate && \
48
  pip install --upgrade pip && \
49
  pip install -r requirements.txt
50
 
51
+ # Download model + setup config (run as user)
52
+ USER user
53
+ RUN . /opt/mineru_venv/bin/activate && \
54
+ wget https://github.com/opendatalab/MinerU/raw/master/scripts/download_models_hf.py -O download_models.py && \
55
  python3 download_models.py && \
56
+ wget https://github.com/opendatalab/MinerU/raw/master/magic-pdf.template.json -O $HOME/magic-pdf.json && \
57
+ sed -i 's|"device": "cpu"|"device": "cpu"|g' $HOME/magic-pdf.json
58
+
59
+ # Copy the rest of the application code as the user
60
+ COPY --chown=user . $HOME/app
61
+
62
+ # Create output directories and set permissions (ensure this happens after WORKDIR and USER)
63
+ RUN mkdir -p $HOME/app/output/images && chmod -R 755 $HOME/app/output
64
 
65
+ # Switch back to user before running the app
66
+ USER user
67
 
68
  CMD ["/opt/mineru_venv/bin/uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]