Spaces:
Sleeping
Sleeping
Commit ·
8932ce6
1
Parent(s): acb846e
优化 docker
Browse files- Dockerfile +17 -13
- app.py +8 -0
Dockerfile
CHANGED
|
@@ -1,6 +1,13 @@
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
|
| 3 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
|
| 5 |
|
| 6 |
# Set up a new user named "user" with user ID 1000
|
|
@@ -9,10 +16,6 @@ RUN useradd -m -u 1000 user
|
|
| 9 |
# Switch to the "user" user
|
| 10 |
USER user
|
| 11 |
|
| 12 |
-
# Set home to the user's home directory
|
| 13 |
-
ENV HOME=/home/user \
|
| 14 |
-
PATH=/home/user/.local/bin:$PATH
|
| 15 |
-
|
| 16 |
# Set the working directory to the user's home directory
|
| 17 |
WORKDIR $HOME/app
|
| 18 |
|
|
@@ -20,21 +23,22 @@ WORKDIR $HOME/app
|
|
| 20 |
COPY --chown=user requirements.txt $HOME/app/requirements.txt
|
| 21 |
|
| 22 |
# Install requirements
|
| 23 |
-
RUN pip install --no-cache-dir --upgrade
|
|
|
|
| 24 |
|
| 25 |
# Copy the rest of the application
|
| 26 |
COPY --chown=user . $HOME/app
|
| 27 |
|
| 28 |
# Create the webfonts directory and download fonts
|
| 29 |
-
#
|
| 30 |
RUN mkdir -p static/webfonts && \
|
| 31 |
-
curl -fLo static/webfonts/fa-solid-900.woff2 https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/webfonts/fa-solid-900.woff2 && \
|
| 32 |
-
curl -fLo static/webfonts/fa-solid-900.ttf https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/webfonts/fa-solid-900.ttf && \
|
| 33 |
-
curl -fLo static/webfonts/fa-regular-400.woff2 https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/webfonts/fa-regular-400.woff2 && \
|
| 34 |
-
curl -fLo static/webfonts/fa-regular-400.ttf https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/webfonts/fa-regular-400.ttf
|
| 35 |
|
| 36 |
# Expose port 7860
|
| 37 |
EXPOSE 7860
|
| 38 |
|
| 39 |
-
# Command to run the application
|
| 40 |
-
CMD ["gunicorn", "-b", "0.0.0.0:7860", "app:app"]
|
|
|
|
| 1 |
FROM python:3.9-slim
|
| 2 |
|
| 3 |
+
# Set environment variables
|
| 4 |
+
# PYTHONUNBUFFERED=1 ensures logs are visible in real-time
|
| 5 |
+
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 6 |
+
PYTHONUNBUFFERED=1 \
|
| 7 |
+
HOME=/home/user \
|
| 8 |
+
PATH=/home/user/.local/bin:$PATH
|
| 9 |
+
|
| 10 |
+
# Install curl and clean up
|
| 11 |
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
|
| 12 |
|
| 13 |
# Set up a new user named "user" with user ID 1000
|
|
|
|
| 16 |
# Switch to the "user" user
|
| 17 |
USER user
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
# Set the working directory to the user's home directory
|
| 20 |
WORKDIR $HOME/app
|
| 21 |
|
|
|
|
| 23 |
COPY --chown=user requirements.txt $HOME/app/requirements.txt
|
| 24 |
|
| 25 |
# Install requirements
|
| 26 |
+
RUN pip install --no-cache-dir --upgrade pip && \
|
| 27 |
+
pip install --no-cache-dir --upgrade -r requirements.txt
|
| 28 |
|
| 29 |
# Copy the rest of the application
|
| 30 |
COPY --chown=user . $HOME/app
|
| 31 |
|
| 32 |
# Create the webfonts directory and download fonts
|
| 33 |
+
# Added --retry and --connect-timeout for robustness to prevent build hangs
|
| 34 |
RUN mkdir -p static/webfonts && \
|
| 35 |
+
curl -fLo static/webfonts/fa-solid-900.woff2 --connect-timeout 20 --retry 3 https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/webfonts/fa-solid-900.woff2 && \
|
| 36 |
+
curl -fLo static/webfonts/fa-solid-900.ttf --connect-timeout 20 --retry 3 https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/webfonts/fa-solid-900.ttf && \
|
| 37 |
+
curl -fLo static/webfonts/fa-regular-400.woff2 --connect-timeout 20 --retry 3 https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/webfonts/fa-regular-400.woff2 && \
|
| 38 |
+
curl -fLo static/webfonts/fa-regular-400.ttf --connect-timeout 20 --retry 3 https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/webfonts/fa-regular-400.ttf
|
| 39 |
|
| 40 |
# Expose port 7860
|
| 41 |
EXPOSE 7860
|
| 42 |
|
| 43 |
+
# Command to run the application with verbose logging
|
| 44 |
+
CMD ["gunicorn", "-b", "0.0.0.0:7860", "--access-logfile", "-", "--error-logfile", "-", "--log-level", "info", "app:app"]
|
app.py
CHANGED
|
@@ -1,8 +1,16 @@
|
|
| 1 |
from flask import Flask, render_template, send_from_directory, jsonify
|
| 2 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
app = Flask(__name__)
|
| 5 |
|
|
|
|
|
|
|
|
|
|
| 6 |
@app.route('/')
|
| 7 |
def index():
|
| 8 |
try:
|
|
|
|
| 1 |
from flask import Flask, render_template, send_from_directory, jsonify
|
| 2 |
import os
|
| 3 |
+
import logging
|
| 4 |
+
|
| 5 |
+
# Configure logging
|
| 6 |
+
logging.basicConfig(level=logging.INFO)
|
| 7 |
+
logger = logging.getLogger(__name__)
|
| 8 |
|
| 9 |
app = Flask(__name__)
|
| 10 |
|
| 11 |
+
# Log startup
|
| 12 |
+
logger.info("Starting Growth Loop Simulator application...")
|
| 13 |
+
|
| 14 |
@app.route('/')
|
| 15 |
def index():
|
| 16 |
try:
|