Aka18 commited on
Commit
24f5365
·
verified ·
1 Parent(s): 2781411

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +12 -31
Dockerfile CHANGED
@@ -6,7 +6,7 @@ RUN useradd --create-home --shell /bin/bash app_user
6
  # Set working directory
7
  WORKDIR /app
8
 
9
- # Environment variables optimized for Hugging Face Spaces networking
10
  ENV PYTHONUNBUFFERED=1
11
  ENV PYTHONDONTWRITEBYTECODE=1
12
  ENV PYTHONPATH=/app
@@ -16,58 +16,40 @@ ENV STREAMLIT_SERVER_ADDRESS=0.0.0.0
16
  ENV MPLCONFIGDIR=/tmp/matplotlib
17
  ENV STREAMLIT_CONFIG_DIR=/tmp/.streamlit
18
 
19
- # CRITICAL: Network and API configurations for Hugging Face Spaces
20
  ENV MPLBACKEND=Agg
21
- ENV GROQ_API_TIMEOUT=120
22
- ENV GROQ_MAX_RETRIES=5
23
- ENV GROQ_BASE_URL=https://api.groq.com/openai/v1
24
- ENV HTTPX_TIMEOUT=120
25
- ENV REQUESTS_TIMEOUT=120
26
- ENV CURL_TIMEOUT=120
27
 
28
- # Network optimization for container environments
29
- ENV HTTP_PROXY=""
30
- ENV HTTPS_PROXY=""
31
- ENV NO_PROXY="localhost,127.0.0.1"
32
-
33
- # Install system dependencies including networking tools
34
  RUN apt-get update && apt-get install -y \
35
  gcc \
36
  g++ \
37
  curl \
38
- wget \
39
  ca-certificates \
40
- dnsutils \
41
- iputils-ping \
42
  && rm -rf /var/lib/apt/lists/* \
43
  && apt-get clean
44
 
45
- # Update CA certificates for HTTPS connections
46
- RUN update-ca-certificates
47
-
48
- # Copy requirements and install with networking optimizations
49
  COPY requirements.txt .
50
  RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
51
- pip install --no-cache-dir --timeout=600 --retries=3 -r requirements.txt
52
 
53
  # Copy application files
54
  COPY . .
55
 
56
  # Create necessary directories and set permissions
57
- RUN mkdir -p /tmp/.streamlit /tmp/matplotlib /app/temp /tmp/analysis_output && \
58
- chown -R app_user:app_user /app /tmp/.streamlit /tmp/matplotlib /tmp/analysis_output && \
59
- chmod -R 755 /tmp/.streamlit /tmp/matplotlib /app/temp /tmp/analysis_output
60
 
61
  # Switch to non-root user
62
  USER app_user
63
 
64
- # Test network connectivity at build time
65
- RUN curl -I https://api.groq.com --connect-timeout 10 --max-time 30 || echo "Groq API not reachable at build time"
66
-
67
  # Expose port
68
  EXPOSE 7860
69
 
70
- # Run with network-optimized Streamlit settings
71
  CMD ["streamlit", "run", "app.py", \
72
  "--server.port=7860", \
73
  "--server.address=0.0.0.0", \
@@ -75,5 +57,4 @@ CMD ["streamlit", "run", "app.py", \
75
  "--server.enableCORS=false", \
76
  "--server.enableXsrfProtection=false", \
77
  "--server.fileWatcherType=none", \
78
- "--browser.gatherUsageStats=false", \
79
- "--server.maxUploadSize=200"]
 
6
  # Set working directory
7
  WORKDIR /app
8
 
9
+ # Environment variables
10
  ENV PYTHONUNBUFFERED=1
11
  ENV PYTHONDONTWRITEBYTECODE=1
12
  ENV PYTHONPATH=/app
 
16
  ENV MPLCONFIGDIR=/tmp/matplotlib
17
  ENV STREAMLIT_CONFIG_DIR=/tmp/.streamlit
18
 
19
+ # HUGGING FACE SPACES specific networking fixes
20
  ENV MPLBACKEND=Agg
21
+ ENV HTTPX_HTTP2=false
22
+ ENV HTTPX_TIMEOUT=180
23
+ ENV REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
 
 
 
24
 
25
+ # Install system dependencies
 
 
 
 
 
26
  RUN apt-get update && apt-get install -y \
27
  gcc \
28
  g++ \
29
  curl \
 
30
  ca-certificates \
 
 
31
  && rm -rf /var/lib/apt/lists/* \
32
  && apt-get clean
33
 
34
+ # Copy requirements and install
 
 
 
35
  COPY requirements.txt .
36
  RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
37
+ pip install --no-cache-dir --timeout=600 -r requirements.txt
38
 
39
  # Copy application files
40
  COPY . .
41
 
42
  # Create necessary directories and set permissions
43
+ RUN mkdir -p /tmp/.streamlit /tmp/matplotlib /app/temp && \
44
+ chown -R app_user:app_user /app /tmp/.streamlit /tmp/matplotlib
 
45
 
46
  # Switch to non-root user
47
  USER app_user
48
 
 
 
 
49
  # Expose port
50
  EXPOSE 7860
51
 
52
+ # Run Streamlit
53
  CMD ["streamlit", "run", "app.py", \
54
  "--server.port=7860", \
55
  "--server.address=0.0.0.0", \
 
57
  "--server.enableCORS=false", \
58
  "--server.enableXsrfProtection=false", \
59
  "--server.fileWatcherType=none", \
60
+ "--browser.gatherUsageStats=false"]