heyunfei commited on
Commit
613683c
·
verified ·
1 Parent(s): 6067e63

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +76 -71
Dockerfile CHANGED
@@ -1,71 +1,76 @@
1
- # Multi-stage build for optimization
2
- FROM python:3.9-slim as builder
3
-
4
- # Install system dependencies for building
5
- RUN apt-get update && apt-get install -y \
6
- build-essential \
7
- gcc \
8
- g++ \
9
- && rm -rf /var/lib/apt/lists/*
10
-
11
- # Create virtual environment
12
- RUN python -m venv /opt/venv
13
- ENV PATH="/opt/venv/bin:$PATH"
14
-
15
- # Copy and install requirements
16
- COPY requirements.txt /tmp/requirements.txt
17
- COPY webui/requirements.txt /tmp/webui_requirements.txt
18
-
19
- # Install main project dependencies
20
- RUN pip install --no-cache-dir --upgrade pip && \
21
- pip install --no-cache-dir -r /tmp/requirements.txt
22
-
23
- # Install webui dependencies
24
- RUN pip install --no-cache-dir -r /tmp/webui_requirements.txt
25
-
26
- # Install production WSGI server
27
- RUN pip install --no-cache-dir gunicorn
28
-
29
- # Production stage
30
- FROM python:3.9-slim
31
-
32
- # Install runtime dependencies
33
- RUN apt-get update && apt-get install -y \
34
- curl \
35
- && rm -rf /var/lib/apt/lists/*
36
-
37
- # Create non-root user
38
- RUN useradd -m -u 1000 user && \
39
- mkdir -p /app && \
40
- chown -R user:user /app
41
-
42
- # Copy virtual environment from builder stage
43
- COPY --from=builder /opt/venv /opt/venv
44
- ENV PATH="/opt/venv/bin:$PATH"
45
-
46
- # Set working directory
47
- WORKDIR /app
48
-
49
- # Copy application code
50
- COPY --chown=user:user . /app
51
-
52
- # Make startup script executable
53
- RUN chmod +x /app/webui/docker_start.sh
54
-
55
- # Switch to non-root user
56
- USER user
57
-
58
- # Expose the correct port (Flask app runs on 7070)
59
- EXPOSE 7860
60
-
61
- # Add health check
62
- HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
63
- CMD curl -f http://localhost:7860/ || exit 1
64
-
65
- # Set environment variables
66
- ENV PYTHONPATH=/app
67
- ENV FLASK_APP=webui/app.py
68
- ENV FLASK_ENV=production
69
-
70
- # Use the startup script
71
- CMD ["/app/webui/docker_start.sh"]
 
 
 
 
 
 
1
+ # Multi-stage build for optimization
2
+ FROM python:3.9-slim as builder
3
+
4
+ # Install system dependencies for building
5
+ RUN apt-get update && apt-get install -y \
6
+ build-essential \
7
+ gcc \
8
+ g++ \
9
+ && rm -rf /var/lib/apt/lists/*
10
+
11
+ # Create virtual environment
12
+ RUN python -m venv /opt/venv
13
+ ENV PATH="/opt/venv/bin:$PATH"
14
+
15
+ # Copy and install requirements
16
+ COPY requirements.txt /tmp/requirements.txt
17
+ COPY webui/requirements.txt /tmp/webui_requirements.txt
18
+
19
+ # Install main project dependencies
20
+ RUN pip install --no-cache-dir --upgrade pip && \
21
+ pip install --no-cache-dir -r /tmp/requirements.txt
22
+
23
+ # Install webui dependencies
24
+ RUN pip install --no-cache-dir -r /tmp/webui_requirements.txt
25
+
26
+ # Install production WSGI server
27
+ RUN pip install --no-cache-dir gunicorn
28
+
29
+ # Production stage
30
+ FROM python:3.9-slim
31
+
32
+ # Install runtime dependencies
33
+ RUN apt-get update && apt-get install -y \
34
+ curl \
35
+ && rm -rf /var/lib/apt/lists/*
36
+
37
+ # Create non-root user
38
+ RUN useradd -m -u 1000 user && \
39
+ mkdir -p /app && \
40
+ chown -R user:user /app
41
+
42
+ # Copy virtual environment from builder stage
43
+ COPY --from=builder /opt/venv /opt/venv
44
+ ENV PATH="/opt/venv/bin:$PATH"
45
+
46
+ # Set working directory
47
+ WORKDIR /app
48
+
49
+ # Copy application code
50
+ COPY --chown=user:user . /app
51
+
52
+ # Make startup script executable
53
+ RUN chmod +x /app/webui/docker_start.sh
54
+
55
+ # Switch to non-root user
56
+ USER user
57
+
58
+ # Expose the Flask app port
59
+ EXPOSE 7860
60
+
61
+ # Add health check
62
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
63
+ CMD curl -f http://localhost:7860/ || exit 1
64
+
65
+ # Set environment variables
66
+ ENV PYTHONPATH=/app
67
+ ENV FLASK_APP=webui/app.py
68
+ ENV FLASK_ENV=production
69
+ ENV PORT=7860
70
+ ENV HF_HOME=/home/user/.cache/huggingface
71
+ ENV HUGGINGFACE_HUB_CACHE=/home/user/.cache/huggingface
72
+ ENV HF_HUB_DISABLE_TELEMETRY=1
73
+ ENV PIP_NO_CACHE_DIR=1
74
+
75
+ # Run the Flask app directly
76
+ CMD ["python", "webui/app.py"]