marcosremar2 commited on
Commit
76f1a7c
·
1 Parent(s): 4afc45f

Fix: Restructure Dockerfile for permissions

Browse files
Files changed (1) hide show
  1. Dockerfile +16 -12
Dockerfile CHANGED
@@ -36,34 +36,38 @@ RUN useradd -m -u 1000 user
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
- chmod +x download_models.py && \
56
- python3 download_models.py && \
57
- wget https://github.com/opendatalab/MinerU/raw/master/magic-pdf.template.json -O $HOME/magic-pdf.json && \
58
  sed -i 's|"device": "cpu"|"device": "cpu"|g' $HOME/magic-pdf.json
59
 
60
  # Copy the rest of the application code as the user
61
  COPY --chown=user . $HOME/app
62
 
63
  # Create output directories and set permissions (ensure this happens after WORKDIR and USER)
64
- RUN mkdir -p $HOME/app/output/images && chmod -R 755 $HOME/app/output
65
-
66
- # Switch back to user before running the app
67
- USER user
68
 
69
  CMD ["/opt/mineru_venv/bin/uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
36
  ENV HOME=/home/user \
37
  PATH=/home/user/.local/bin:$PATH
38
 
39
+ # Set the working directory
40
  WORKDIR $HOME/app
41
 
42
+ # Copy requirements first
 
43
  COPY --chown=user requirements.txt .
44
 
45
+ # Install dependencies as root
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 script and set permissions as root
52
+ RUN wget https://github.com/opendatalab/MinerU/raw/master/scripts/download_models_hf.py -O $HOME/app/download_models.py && \
53
+ chmod +x $HOME/app/download_models.py && \
54
+ wget https://github.com/opendatalab/MinerU/raw/master/magic-pdf.template.json -O $HOME/app/magic-pdf.json && \
55
+ chown user:user $HOME/app/download_models.py $HOME/app/magic-pdf.json
56
+
57
+ # Switch to user to run download script and copy app code
58
  USER user
59
+
60
+ # Run download script
61
  RUN . /opt/mineru_venv/bin/activate && \
62
+ python3 $HOME/app/download_models.py && \
63
+ cp $HOME/app/magic-pdf.json $HOME/magic-pdf.json && \
 
 
64
  sed -i 's|"device": "cpu"|"device": "cpu"|g' $HOME/magic-pdf.json
65
 
66
  # Copy the rest of the application code as the user
67
  COPY --chown=user . $HOME/app
68
 
69
  # Create output directories and set permissions (ensure this happens after WORKDIR and USER)
70
+ # Already running as user, just need to create dirs
71
+ RUN mkdir -p $HOME/app/output/images
 
 
72
 
73
  CMD ["/opt/mineru_venv/bin/uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]