MogensR commited on
Commit
bdd5765
·
1 Parent(s): 8b72ab2

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +55 -39
Dockerfile CHANGED
@@ -1,58 +1,74 @@
1
- # Use CUDA-enabled base image to match HF Spaces CUDA 12.3
2
- FROM nvidia/cuda:12.3.2-cudnn9-devel-ubuntu22.04
3
 
4
  # Set environment variables
5
  ENV PYTHONDONTWRITEBYTECODE=1 \
6
  PYTHONUNBUFFERED=1 \
7
- GRADIO_SERVER_NAME="0.0.0.0" \
8
- GRADIO_SERVER_PORT="7860" \
9
- DISPLAY=:99
10
-
11
- # Set working directory
12
- WORKDIR /app
13
-
14
- # Create a non-root user for security
15
- RUN useradd -m myuser && \
16
- chown myuser:myuser /app
17
 
18
  # Install system dependencies
19
  RUN apt-get update && apt-get install -y \
 
 
 
 
20
  git \
21
- ffmpeg \
22
- xvfb \
23
- libglib2.0-0 \
24
- libgomp1 \
25
  curl \
26
- && rm -rf /var/lib/apt/lists/* \
27
- && apt-get clean
 
 
 
 
 
 
 
 
 
 
 
28
 
29
- # Copy requirements first to leverage Docker cache
30
- COPY requirements.txt .
31
 
32
- # Install Python dependencies as non-root user
33
- RUN pip install --no-cache-dir --upgrade pip && \
34
- pip install --no-cache-dir -r requirements.txt
35
 
36
- # Copy application code
37
- COPY --chown=myuser:myuser . .
38
 
39
- # Create necessary directories with proper permissions
40
- RUN mkdir -p /tmp/gradio /tmp/model_cache && \
41
- chmod 777 /tmp/gradio /tmp/model_cache && \
42
- chown myuser:myuser /tmp/gradio /tmp/model_cache
43
 
44
- # Set proper permissions for the app directory
45
- RUN chmod -R 755 /app
46
 
47
- # Expose port
48
- EXPOSE 7860
 
 
 
 
 
 
 
49
 
50
- # Health check to ensure the app is running
51
- HEALTHCHECK --interval=30s --timeout=3s \
 
 
 
 
 
 
52
  CMD curl -f http://localhost:7860/ || exit 1
53
 
54
- # Switch to non-root user for security
55
- USER myuser
56
 
57
- # Run the application via start.sh to ensure xvfb
58
- CMD ["bash", "start.sh"]
 
1
+ # Use official Python runtime with CUDA support
2
+ FROM nvidia/cuda:12.1-devel-ubuntu22.04
3
 
4
  # Set environment variables
5
  ENV PYTHONDONTWRITEBYTECODE=1 \
6
  PYTHONUNBUFFERED=1 \
7
+ DEBIAN_FRONTEND=noninteractive \
8
+ TORCH_CUDA_ARCH_LIST="6.0 6.1 7.0 7.5 8.0 8.6+PTX" \
9
+ FORCE_CUDA="1"
 
 
 
 
 
 
 
10
 
11
  # Install system dependencies
12
  RUN apt-get update && apt-get install -y \
13
+ python3.10 \
14
+ python3.10-dev \
15
+ python3-pip \
16
+ python3.10-venv \
17
  git \
18
+ wget \
 
 
 
19
  curl \
20
+ build-essential \
21
+ cmake \
22
+ pkg-config \
23
+ libopencv-dev \
24
+ python3-opencv \
25
+ ffmpeg \
26
+ libsm6 \
27
+ libxext6 \
28
+ libfontconfig1 \
29
+ libxrender1 \
30
+ libgl1-mesa-glx \
31
+ && apt-get clean \
32
+ && rm -rf /var/lib/apt/lists/*
33
 
34
+ # Create and set working directory
35
+ WORKDIR /app
36
 
37
+ # Create non-root user for security
38
+ RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
39
+ USER appuser
40
 
41
+ # Install Python dependencies
42
+ COPY --chown=appuser:appuser requirements.txt .
43
 
44
+ # Install PyTorch with CUDA support first (speeds up other installs)
45
+ RUN pip install --no-cache-dir --user torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
 
 
46
 
47
+ # Install other requirements
48
+ RUN pip install --no-cache-dir --user -r requirements.txt
49
 
50
+ # Add user bin to PATH
51
+ ENV PATH="/home/appuser/.local/bin:$PATH"
52
+
53
+ # Copy application code
54
+ COPY --chown=appuser:appuser . .
55
+
56
+ # Create necessary directories
57
+ RUN mkdir -p /tmp/model_cache /tmp/processing && \
58
+ chmod 755 /tmp/model_cache /tmp/processing
59
 
60
+ # Set environment variables for runtime
61
+ ENV GRADIO_SERVER_NAME="0.0.0.0" \
62
+ GRADIO_SERVER_PORT="7860" \
63
+ MODEL_CACHE_DIR="/tmp/model_cache" \
64
+ TORCH_HOME="/tmp/model_cache"
65
+
66
+ # Health check
67
+ HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
68
  CMD curl -f http://localhost:7860/ || exit 1
69
 
70
+ # Expose port
71
+ EXPOSE 7860
72
 
73
+ # Run the application
74
+ CMD ["python3", "app.py"]