ayush2917 commited on
Commit
e13aa67
·
verified ·
1 Parent(s): 8d81f9d

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +34 -24
Dockerfile CHANGED
@@ -1,43 +1,53 @@
1
- FROM python:3.9-slim
 
2
 
3
  # Set environment variables
4
  ENV PYTHONDONTWRITEBYTECODE=1 \
5
  PYTHONUNBUFFERED=1 \
6
- PORT=8000 \
7
- HF_HOME=/cache \
8
- HUGGINGFACE_HUB_CACHE=/cache \
9
- TRANSFORMERS_CACHE=/cache \
10
- PIP_NO_CACHE_DIR=1 \
11
- TOKENIZERS_PARALLELISM=false
12
 
 
13
  WORKDIR /app
14
 
15
- # Create directory structure with correct permissions
16
- RUN mkdir -p /cache && \
17
- chmod 777 /cache && \
18
- mkdir -p /app/{data,src,config,templates,static/css,tests}
19
-
20
  # Install system dependencies
21
  RUN apt-get update && apt-get install -y --no-install-recommends \
22
  build-essential \
 
 
23
  && rm -rf /var/lib/apt/lists/*
24
 
25
- # Install Python requirements
 
 
 
26
  COPY requirements.txt .
27
- RUN pip install --upgrade pip && \
28
- pip install --no-cache-dir -r requirements.txt
29
 
30
- # Copy application files
31
- COPY . .
32
 
33
- # Verify src/history.py exists
34
- RUN test -f /app/src/history.py || { echo "Error: history.py missing!"; exit 1; }
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
- # Set proper permissions
37
- RUN chmod -R a+rw /cache && \
38
- chmod -R a+r /app && \
39
- find /app -type d -exec chmod a+rx {} \;
40
 
 
41
  EXPOSE 8000
42
 
43
- CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "2", "--timeout", "120", "app:app"]
 
 
1
+ # Use a slim Python 3.9 base image
2
+ FROM python:3.9-slim-buster@sha256:320a7a4250aba4249f458872adecf92eea88dc6abd2d76dc5c0f01cac9b53990
3
 
4
  # Set environment variables
5
  ENV PYTHONDONTWRITEBYTECODE=1 \
6
  PYTHONUNBUFFERED=1 \
7
+ HF_HOME=/app/cache \
8
+ HUGGINGFACE_HUB_DISABLE_XET=1 \
9
+ PIP_NO_CACHE_DIR=1
 
 
 
10
 
11
+ # Set working directory
12
  WORKDIR /app
13
 
 
 
 
 
 
14
  # Install system dependencies
15
  RUN apt-get update && apt-get install -y --no-install-recommends \
16
  build-essential \
17
+ gcc \
18
+ g++ \
19
  && rm -rf /var/lib/apt/lists/*
20
 
21
+ # Upgrade pip to the latest version
22
+ RUN pip install --upgrade pip
23
+
24
+ # Copy requirements first for better caching
25
  COPY requirements.txt .
 
 
26
 
27
+ # Install dependencies from requirements.txt
28
+ RUN pip install --no-cache-dir -r requirements.txt || { echo "Failed to install requirements"; exit 1; }
29
 
30
+ # Pre-download models
31
+ RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2', cache_folder='/app/cache')" || { echo "Failed to pre-download SentenceTransformer model"; exit 1; }
32
+ RUN python -c "from transformers import AutoModelForCausalLM, AutoTokenizer; AutoModelForCausalLM.from_pretrained('distilgpt2', cache_dir='/app/cache'); AutoTokenizer.from_pretrained('distilgpt2', cache_dir='/app/cache')" || { echo "Failed to pre-download transformer model"; exit 1; }
33
+ # Verify cache contents
34
+ RUN ls -l /app/cache && \
35
+ find /app/cache -type f || { echo "Cache verification failed"; exit 1; }
36
+
37
+ # Create directories, user, and set permissions
38
+ RUN mkdir -p /app/data /app/cache && \
39
+ useradd -m myuser && \
40
+ chown -R myuser:myuser /app && \
41
+ chmod -R u+rw /app/data
42
+
43
+ # Copy all project files
44
+ COPY . .
45
 
46
+ # Set non-root user
47
+ USER myuser
 
 
48
 
49
+ # Expose port for Gunicorn
50
  EXPOSE 8000
51
 
52
+ # Start Gunicorn with a single worker to reduce memory usage
53
+ CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "1", "--timeout", "120", "app:app"]