ayush2917 commited on
Commit
8cf422b
·
verified ·
1 Parent(s): 3578784

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +49 -3
Dockerfile CHANGED
@@ -1,15 +1,61 @@
1
- FROM python:3.9-slim
 
2
 
3
  WORKDIR /app
4
 
 
 
 
 
 
 
 
 
5
  COPY requirements.txt .
6
- RUN pip install --no-cache-dir -r requirements.txt
 
 
 
 
 
 
 
 
7
 
 
 
 
 
 
 
 
 
 
8
  COPY . .
9
 
 
 
 
 
10
  ENV FLASK_APP=app.py
11
  ENV FLASK_ENV=production
 
 
 
12
 
 
 
 
 
 
 
 
 
13
  EXPOSE 8080
14
 
15
- CMD ["gunicorn", "--bind", "0.0.0.0:8080", "app:app"]
 
 
 
 
 
 
1
+ # Stage 1: Build environment
2
+ FROM python:3.9-slim as builder
3
 
4
  WORKDIR /app
5
 
6
+ # Install system dependencies
7
+ RUN apt-get update && apt-get install -y \
8
+ gcc \
9
+ python3-dev \
10
+ git \
11
+ && rm -rf /var/lib/apt/lists/*
12
+
13
+ # Install Python dependencies
14
  COPY requirements.txt .
15
+ RUN pip install --user --no-cache-dir -r requirements.txt
16
+
17
+ # Stage 2: Runtime environment
18
+ FROM python:3.9-slim
19
+
20
+ WORKDIR /app
21
+
22
+ # Copy Python dependencies from builder
23
+ COPY --from=builder /root/.local /root/.local
24
 
25
+ # Ensure scripts in .local are usable
26
+ ENV PATH=/root/.local/bin:$PATH
27
+
28
+ # Install runtime dependencies
29
+ RUN apt-get update && apt-get install -y \
30
+ libgomp1 \
31
+ && rm -rf /var/lib/apt/lists/*
32
+
33
+ # Copy application files
34
  COPY . .
35
 
36
+ # Create directory for database
37
+ RUN mkdir -p /app/data && touch /app/data/news.db
38
+
39
+ # Environment variables
40
  ENV FLASK_APP=app.py
41
  ENV FLASK_ENV=production
42
+ ENV DATABASE_URL=/app/data/news.db
43
+ ENV TRANSFORMERS_CACHE=/app/cache
44
+ ENV TORCH_HOME=/app/cache
45
 
46
+ # Create cache directory for models
47
+ RUN mkdir -p /app/cache
48
+
49
+ # Pre-download smaller versions of models (optional)
50
+ # RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('paraphrase-MiniLM-L6-v2', cache_folder='/app/cache')"
51
+ # RUN python -c "from transformers import pipeline; pipeline('summarization', model='facebook/bart-large-cnn', cache_dir='/app/cache')"
52
+
53
+ # Expose port
54
  EXPOSE 8080
55
 
56
+ # Health check
57
+ HEALTHCHECK --interval=30s --timeout=10s \
58
+ CMD curl -f http://localhost:8080/ || exit 1
59
+
60
+ # Run application
61
+ CMD ["gunicorn", "--bind", "0.0.0.0:8080", "--timeout", "120", "--workers", "2", "app:app"]