sandbox338 commited on
Commit
52b9e23
·
verified ·
1 Parent(s): 4adeb96

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +28 -47
Dockerfile CHANGED
@@ -2,74 +2,55 @@ FROM python:3.9-slim
2
 
3
  WORKDIR /app
4
 
5
- # Set up environment variables for writable directories
6
- ENV HOME=/app
7
- ENV MPLCONFIGDIR=/tmp/.matplotlib
8
- ENV TORCH_HOME=/tmp/.torch
9
- ENV STREAMLIT_HOME=/tmp/.streamlit
10
- ENV PYTHONPATH=$PYTHONPATH:/app
11
 
12
  # Install system dependencies
13
  RUN apt-get update && apt-get install -y \
14
  build-essential \
15
- curl \
16
- software-properties-common \
17
  git \
18
  libgl1-mesa-glx \
19
  libglib2.0-0 \
20
- libffi-dev \
21
- libssl-dev \
22
- libbz2-dev \
23
- liblzma-dev \
24
- libreadline-dev \
25
- libsqlite3-dev \
26
- zlib1g-dev \
27
  wget \
28
  && rm -rf /var/lib/apt/lists/*
29
 
30
- # Create temporary directories with proper permissions
31
  RUN mkdir -p /tmp/.torch /tmp/.streamlit /tmp/.matplotlib \
32
  && chmod 777 /tmp/.torch /tmp/.streamlit /tmp/.matplotlib
33
 
34
- # Upgrade pip and install base packages
35
- RUN pip install --no-cache-dir --upgrade pip setuptools wheel
36
 
37
- # Install PyTorch and torchvision first (often the most difficult dependencies)
38
- RUN pip install --no-cache-dir torch==1.13.1 torchvision==0.14.1 -f https://download.pytorch.org/whl/cpu/torch_stable.html
39
 
40
- # Install numpy with version constraint
41
- RUN pip install --no-cache-dir "numpy<2.0"
 
42
 
43
- # Copy only requirements first for better caching
44
- COPY requirements.txt ./
45
 
46
- # Install Python dependencies in smaller batches for better error visibility
47
- RUN pip install --no-cache-dir -r requirements.txt
48
-
49
- # Install detectron2 from GitHub (with specific commit for stability)
50
  RUN pip install --no-cache-dir 'git+https://github.com/facebookresearch/detectron2.git@v0.6'
51
 
52
- # Create the src directory and copy application files
53
  RUN mkdir -p /app/src
54
- COPY src/ ./src/
55
-
56
- # Set up Streamlit configuration
57
- RUN mkdir -p /tmp/.streamlit && echo '\
58
- [general]\n\
59
- email = ""\n\
60
- ' > /tmp/.streamlit/credentials.toml
61
 
62
- # Set proper ownership for application files
63
- RUN chown -R 1000:1000 /app
64
-
65
- # Expose Streamlit port
66
- EXPOSE 8501
67
 
68
- # Add a healthcheck
69
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health || exit 1
 
 
 
70
 
71
- # Run as non-root user for better security
72
- USER 1000
73
 
74
- # Command to run the app
75
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
2
 
3
  WORKDIR /app
4
 
5
+ # Set environment variables
6
+ ENV PYTHONUNBUFFERED=1
7
+ ENV PYTHONDONTWRITEBYTECODE=1
8
+ ENV STREAMLIT_SERVER_PORT=7860
9
+ ENV STREAMLIT_SERVER_ADDRESS=0.0.0.0
 
10
 
11
  # Install system dependencies
12
  RUN apt-get update && apt-get install -y \
13
  build-essential \
 
 
14
  git \
15
  libgl1-mesa-glx \
16
  libglib2.0-0 \
 
 
 
 
 
 
 
17
  wget \
18
  && rm -rf /var/lib/apt/lists/*
19
 
20
+ # Create writable directories in /tmp
21
  RUN mkdir -p /tmp/.torch /tmp/.streamlit /tmp/.matplotlib \
22
  && chmod 777 /tmp/.torch /tmp/.streamlit /tmp/.matplotlib
23
 
24
+ # Install PyTorch first (specify CPU version)
25
+ RUN pip install --no-cache-dir torch==1.13.1+cpu torchvision==0.14.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
26
 
27
+ # Install numpy specifically to avoid version conflicts
28
+ RUN pip install --no-cache-dir "numpy>=1.21.0,<1.27.0"
29
 
30
+ # Install detection dependencies - separate critical ones
31
+ RUN pip install --no-cache-dir cython wheel fvcore iopath
32
+ RUN pip install --no-cache-dir pycocotools matplotlib pyyaml tqdm
33
 
34
+ # Install Streamlit and OpenCV
35
+ RUN pip install --no-cache-dir streamlit>=1.20.0,<1.46.0 opencv-python-headless>=4.5.0,<4.12.0 pillow>=9.0.0,<12.0.0
36
 
37
+ # Install detectron2 directly, without going through requirements.txt
 
 
 
38
  RUN pip install --no-cache-dir 'git+https://github.com/facebookresearch/detectron2.git@v0.6'
39
 
40
+ # Create app structure
41
  RUN mkdir -p /app/src
 
 
 
 
 
 
 
42
 
43
+ # Copy app files
44
+ COPY src/ ./src/
 
 
 
45
 
46
+ # Configure Streamlit
47
+ RUN mkdir -p /tmp/.streamlit && \
48
+ echo '[server]\nheadless = true\nenableCORS = false\nenableXsrfProtection = false' > /tmp/.streamlit/config.toml && \
49
+ echo '[general]\nemail = ""' > /tmp/.streamlit/credentials.toml && \
50
+ chmod -R 777 /tmp/.streamlit
51
 
52
+ # Expose the port Streamlit will run on
53
+ EXPOSE 7860
54
 
55
+ # Run the app
56
+ CMD ["streamlit", "run", "src/streamlit_app.py", "--server.port=7860", "--server.address=0.0.0.0"]