marcosremar2 commited on
Commit
e432715
·
1 Parent(s): 1b38816

Feat: Enable CUDA support

Browse files
Files changed (1) hide show
  1. Dockerfile +17 -13
Dockerfile CHANGED
@@ -1,7 +1,8 @@
1
- FROM ubuntu:22.04
2
 
3
  ENV DEBIAN_FRONTEND=noninteractive
4
 
 
5
  RUN apt-get update && \
6
  apt-get install -y software-properties-common && \
7
  add-apt-repository ppa:deadsnakes/ppa && \
@@ -29,50 +30,53 @@ RUN apt-get update && \
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
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
- # Create output directory and set ownership BEFORE switching user for COPY
58
  RUN mkdir -p $HOME/app/output/images && \
59
  chown -R user:user $HOME/app/output
60
 
61
- # Switch to user to run download script and copy app code
62
  USER user
63
 
64
- # Run download script
65
  RUN . /opt/mineru_venv/bin/activate && \
66
  python3 $HOME/app/download_models.py && \
67
  cp $HOME/app/magic-pdf.json $HOME/magic-pdf.json && \
68
- sed -i 's|"device": "cpu"|"device": "cpu"|g' $HOME/magic-pdf.json
69
 
70
  # Copy the rest of the application code as the user
71
- # This will copy into the WORKDIR ($HOME/app)
72
  COPY --chown=user . .
73
 
74
- # Ensure the output dir still has correct permissions after final copy
75
- # (This might be redundant but can help in some cases)
76
  RUN chmod -R 755 $HOME/app/output
77
 
 
 
 
 
78
  CMD ["/opt/mineru_venv/bin/uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ FROM nvidia/cuda:11.8.0-devel-ubuntu22.04
2
 
3
  ENV DEBIAN_FRONTEND=noninteractive
4
 
5
+ # Install base dependencies
6
  RUN apt-get update && \
7
  apt-get install -y software-properties-common && \
8
  add-apt-repository ppa:deadsnakes/ppa && \
 
30
 
31
  RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1
32
 
33
+ # Set up a non-root user
34
  RUN useradd -m -u 1000 user
35
 
36
+ # Set home directory and update PATH
37
  ENV HOME=/home/user \
38
  PATH=/home/user/.local/bin:$PATH
39
 
40
  # Set the working directory
41
  WORKDIR $HOME/app
42
 
43
+ # Copy requirements first (as user)
44
  COPY --chown=user requirements.txt .
45
 
46
+ # Install Python dependencies (as root to manage venv properly)
47
+ # Note: Ensure PyTorch installed picks up CUDA from the base image
48
  RUN python3 -m venv /opt/mineru_venv && \
49
  . /opt/mineru_venv/bin/activate && \
50
  pip install --upgrade pip && \
51
  pip install -r requirements.txt
52
 
53
+ # Download model script and config template, set permissions (as root)
54
  RUN wget https://github.com/opendatalab/MinerU/raw/master/scripts/download_models_hf.py -O $HOME/app/download_models.py && \
55
  chmod +x $HOME/app/download_models.py && \
56
  wget https://github.com/opendatalab/MinerU/raw/master/magic-pdf.template.json -O $HOME/app/magic-pdf.json && \
57
  chown user:user $HOME/app/download_models.py $HOME/app/magic-pdf.json
58
 
59
+ # Create output directory and set ownership (as root)
60
  RUN mkdir -p $HOME/app/output/images && \
61
  chown -R user:user $HOME/app/output
62
 
63
+ # Switch to non-root user
64
  USER user
65
 
66
+ # Run model download script and configure magic-pdf for CUDA
67
  RUN . /opt/mineru_venv/bin/activate && \
68
  python3 $HOME/app/download_models.py && \
69
  cp $HOME/app/magic-pdf.json $HOME/magic-pdf.json && \
70
+ sed -i 's|"device": "cpu"|"device": "cuda"|g' $HOME/magic-pdf.json
71
 
72
  # Copy the rest of the application code as the user
 
73
  COPY --chown=user . .
74
 
75
+ # Ensure the output dir still has correct permissions
 
76
  RUN chmod -R 755 $HOME/app/output
77
 
78
+ # Expose the port (optional but good practice)
79
+ EXPOSE 7860
80
+
81
+ # Run the application
82
  CMD ["/opt/mineru_venv/bin/uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]