Spaces:
Running
Running
Update Dockerfile
Browse files- Dockerfile +20 -8
Dockerfile
CHANGED
@@ -1,16 +1,28 @@
|
|
1 |
-
|
2 |
-
# Use a lighter base image and optimize layer caching
|
3 |
FROM python:3.9-slim
|
4 |
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
COPY requirements.txt .
|
7 |
RUN pip install --no-cache-dir -r requirements.txt
|
8 |
|
9 |
-
# Copy
|
10 |
-
COPY
|
11 |
|
12 |
-
#
|
13 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
14 |
-
CMD
|
15 |
|
16 |
-
|
|
|
|
|
|
|
|
1 |
FROM python:3.9-slim
|
2 |
|
3 |
+
WORKDIR /code
|
4 |
+
|
5 |
+
# Redirect HF cache to /tmp/.cache for better performance
|
6 |
+
ENV HF_HOME=/tmp/.cache
|
7 |
+
ENV TRANSFORMERS_CACHE=/tmp/.cache
|
8 |
+
|
9 |
+
# Add additional environment variables for optimization
|
10 |
+
ENV PYTHONUNBUFFERED=1
|
11 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
12 |
+
|
13 |
+
# Install system dependencies if needed (uncomment if you need curl for health checks)
|
14 |
+
# RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
|
15 |
+
|
16 |
+
# Copy and install Python dependencies first (better Docker layer caching)
|
17 |
COPY requirements.txt .
|
18 |
RUN pip install --no-cache-dir -r requirements.txt
|
19 |
|
20 |
+
# Copy the app directory with your main.py file
|
21 |
+
COPY app ./app
|
22 |
|
23 |
+
# Add health check to monitor container health
|
24 |
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
25 |
+
CMD python -c "import requests; requests.get('http://localhost:7860/health', timeout=5)" || exit 1
|
26 |
|
27 |
+
# Start the application
|
28 |
+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|