File size: 1,498 Bytes
1d75522
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
FROM python:3.10-slim

# Set environment variables
ENV PYTHONUNBUFFERED=1 \
    DEBIAN_FRONTEND=noninteractive \
    REQUESTS_TIMEOUT=30 \
    PYTHONPATH=/app

# Install system dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    curl \
    git \
    dnsutils \
    iputils-ping \
    && rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Set up DNS configuration with multiple DNS servers for redundancy
RUN echo "nameserver 8.8.8.8" > /etc/resolv.conf && \
    echo "nameserver 8.8.4.4" >> /etc/resolv.conf && \
    echo "nameserver 1.1.1.1" >> /etc/resolv.conf && \
    echo "options timeout:1 attempts:5" >> /etc/resolv.conf

# Copy requirements first to leverage Docker cache
COPY requirements.txt .

# Install Python dependencies with retry mechanism and explicit Gradio upgrade
RUN pip install --no-cache-dir -r requirements.txt || \
    (sleep 5 && pip install --no-cache-dir -r requirements.txt) || \
    (sleep 10 && pip install --no-cache-dir -r requirements.txt) && \
    pip install --no-cache-dir gradio==4.44.1

# Copy application code
COPY . .

# Expose port
EXPOSE 7860

# Add network verification script
RUN echo '#!/bin/sh\n\
ping -c 1 huggingface.co || ping -c 1 8.8.8.8\n\
' > /healthcheck.sh && chmod +x /healthcheck.sh

# Healthcheck with more lenient settings
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=5 \
    CMD /healthcheck.sh || exit 1

# Command to run the application
CMD ["python", "app.py"]