divyarspoton commited on
Commit
cfc0aae
·
verified ·
1 Parent(s): 60c0001

Update Dockerfile

Browse files
Files changed (1) hide show
  1. 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
- # Install dependencies first (better caching)
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  COPY requirements.txt .
7
  RUN pip install --no-cache-dir -r requirements.txt
8
 
9
- # Copy code
10
- COPY . .
11
 
12
- # Set proper health check
13
  HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
14
- CMD curl -f http://localhost:7860/health || exit 1
15
 
16
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
 
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"]