File size: 1,867 Bytes
613683c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Multi-stage build for optimization
FROM python:3.9-slim as builder

# Install system dependencies for building
RUN apt-get update && apt-get install -y \
    build-essential \
    gcc \
    g++ \
    && rm -rf /var/lib/apt/lists/*

# Create virtual environment
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"

# Copy and install requirements
COPY requirements.txt /tmp/requirements.txt
COPY webui/requirements.txt /tmp/webui_requirements.txt

# Install main project dependencies
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r /tmp/requirements.txt

# Install webui dependencies
RUN pip install --no-cache-dir -r /tmp/webui_requirements.txt

# Install production WSGI server
RUN pip install --no-cache-dir gunicorn

# Production stage
FROM python:3.9-slim

# Install runtime dependencies
RUN apt-get update && apt-get install -y \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Create non-root user
RUN useradd -m -u 1000 user && \
    mkdir -p /app && \
    chown -R user:user /app

# Copy virtual environment from builder stage
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"

# Set working directory
WORKDIR /app

# Copy application code
COPY --chown=user:user . /app

# Make startup script executable
RUN chmod +x /app/webui/docker_start.sh

# Switch to non-root user
USER user

# Expose the Flask app port
EXPOSE 7860

# Add health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD curl -f http://localhost:7860/ || exit 1

# Set environment variables
ENV PYTHONPATH=/app
ENV FLASK_APP=webui/app.py
ENV FLASK_ENV=production
ENV PORT=7860
ENV HF_HOME=/home/user/.cache/huggingface
ENV HUGGINGFACE_HUB_CACHE=/home/user/.cache/huggingface
ENV HF_HUB_DISABLE_TELEMETRY=1
ENV PIP_NO_CACHE_DIR=1

# Run the Flask app directly
CMD ["python", "webui/app.py"]