Spaces:
Runtime error
Runtime error
Update Dockerfile
Browse files- Dockerfile +39 -34
Dockerfile
CHANGED
|
@@ -1,34 +1,39 @@
|
|
| 1 |
-
# Use the official Python slim image for a smaller footprint
|
| 2 |
-
FROM python:3.11-slim
|
| 3 |
-
|
| 4 |
-
# Set the working directory
|
| 5 |
-
WORKDIR /app
|
| 6 |
-
|
| 7 |
-
# Install system dependencies
|
| 8 |
-
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 9 |
-
gcc \
|
| 10 |
-
python3-dev \
|
| 11 |
-
libpq-dev \
|
| 12 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 13 |
-
|
| 14 |
-
# Copy
|
| 15 |
-
COPY requirements.txt .
|
| 16 |
-
|
| 17 |
-
# Install Python dependencies
|
| 18 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
| 19 |
-
|
| 20 |
-
# Copy the entire application code
|
| 21 |
-
COPY . .
|
| 22 |
-
|
| 23 |
-
# Ensure static files
|
| 24 |
-
RUN mkdir -p /app/static
|
| 25 |
-
|
| 26 |
-
# Expose
|
| 27 |
-
EXPOSE 5000
|
| 28 |
-
|
| 29 |
-
# Set environment variables for
|
| 30 |
-
ENV FLASK_ENV=production
|
| 31 |
-
ENV PYTHONUNBUFFERED=1
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use the official Python slim image for a smaller footprint
|
| 2 |
+
FROM python:3.11-slim
|
| 3 |
+
|
| 4 |
+
# Set the working directory
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Install system dependencies for psycopg2 and other potential native extensions
|
| 8 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 9 |
+
gcc \
|
| 10 |
+
python3-dev \
|
| 11 |
+
libpq-dev \
|
| 12 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 13 |
+
|
| 14 |
+
# Copy requirements file to leverage Docker cache
|
| 15 |
+
COPY requirements.txt .
|
| 16 |
+
|
| 17 |
+
# Install Python dependencies
|
| 18 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 19 |
+
|
| 20 |
+
# Copy the entire application code
|
| 21 |
+
COPY . .
|
| 22 |
+
|
| 23 |
+
# Ensure static files directory exists
|
| 24 |
+
RUN mkdir -p /app/static /app/templates
|
| 25 |
+
|
| 26 |
+
# Expose port 5000 (Render may override)
|
| 27 |
+
EXPOSE 5000
|
| 28 |
+
|
| 29 |
+
# Set environment variables for production
|
| 30 |
+
ENV FLASK_ENV=production
|
| 31 |
+
ENV PYTHONUNBUFFERED=1
|
| 32 |
+
ENV GUNICORN_CMD_ARGS="--workers=3 --timeout=120 --log-level=info"
|
| 33 |
+
|
| 34 |
+
# Command to run the application with gunicorn
|
| 35 |
+
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "app:app"]
|
| 36 |
+
|
| 37 |
+
# Health check to ensure the app is responsive
|
| 38 |
+
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
| 39 |
+
CMD curl -f http://localhost:5000/health || exit 1
|