ButterM40 commited on
Commit
baebe62
·
1 Parent(s): ef99828

Update Dockerfile with proper caching and build dependencies

Browse files
Files changed (1) hide show
  1. Dockerfile +22 -4
Dockerfile CHANGED
@@ -1,18 +1,36 @@
 
1
  FROM python:3.11-slim
2
 
3
  # Set working directory
4
- WORKDIR /app
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  # Copy requirements first for better caching
7
  COPY requirements.txt .
 
 
8
  RUN pip install --no-cache-dir --upgrade pip && \
9
  pip install --no-cache-dir -r requirements.txt
10
 
11
  # Copy the rest of the application
12
  COPY . .
13
 
14
- # Hugging Face Spaces uses port 7860
15
- ENV PORT=7860
 
 
 
16
 
17
  # Run the FastAPI server
18
- CMD ["bash", "-c", "uvicorn server:app --host 0.0.0.0 --port ${PORT}"]
 
1
+ # Use Python 3.11 slim image
2
  FROM python:3.11-slim
3
 
4
  # Set working directory
5
+ WORKDIR /code
6
+
7
+ # Set environment variables
8
+ ENV PORT=7860
9
+ ENV PYTHONPATH=/code
10
+ ENV TRANSFORMERS_CACHE=/code/.cache/transformers
11
+
12
+ # Install system dependencies
13
+ RUN apt-get update && \
14
+ apt-get install -y --no-install-recommends \
15
+ build-essential \
16
+ git \
17
+ && rm -rf /var/lib/apt/lists/*
18
 
19
  # Copy requirements first for better caching
20
  COPY requirements.txt .
21
+
22
+ # Install Python dependencies
23
  RUN pip install --no-cache-dir --upgrade pip && \
24
  pip install --no-cache-dir -r requirements.txt
25
 
26
  # Copy the rest of the application
27
  COPY . .
28
 
29
+ # Create cache directory for transformers
30
+ RUN mkdir -p /code/.cache/transformers
31
+
32
+ # Make port 7860 available
33
+ EXPOSE 7860
34
 
35
  # Run the FastAPI server
36
+ CMD ["bash", "-c", "uvicorn server:app --host 0.0.0.0 --port ${PORT} --workers 1"]