-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
95 lines (75 loc) · 2.23 KB
/
Dockerfile
File metadata and controls
95 lines (75 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Multi-stage Dockerfile for workerAI
# Optimized for production deployments
FROM python:3.11-slim as base
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl \
git \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy requirements first for better caching
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# ==================== Stage 2: Playwright Installation ====================
FROM base as playwright
# Install Playwright system dependencies
RUN apt-get update && apt-get install -y \
libnss3 \
libnspr4 \
libatk1.0-0 \
libatk-bridge2.0-0 \
libcups2 \
libdrm2 \
libdbus-1-3 \
libxkbcommon0 \
libxcomposite1 \
libxdamage1 \
libxfixes3 \
libxrandr2 \
libgbm1 \
libasound2 \
libpangocairo-1.0-0 \
libpango-1.0-0 \
libcairo2 \
libatspi2.0-0 \
libxshmfence1 \
&& rm -rf /var/lib/apt/lists/*
# Install Playwright browsers
RUN playwright install chromium
# ==================== Stage 3: Model Downloading ====================
FROM playwright as models
# Create model cache directory
RUN mkdir -p /app/models
# Pre-download embedding model
RUN python -c "import os; os.environ['SENTENCE_TRANSFORMERS_HOME'] = '/app/models'; from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')"
# ==================== Stage 4: Final Application ====================
FROM models as final
# Copy application code
COPY . .
# Create necessary directories
RUN mkdir -p \
/app/data/chroma_db \
/app/workspace \
/app/logs \
/app/models
# Create non-root user for security
RUN useradd -m -u 1000 workerai && \
chown -R workerai:workerai /app
# Switch to non-root user
USER workerai
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
SENTENCE_TRANSFORMERS_HOME=/app/models \
ENVIRONMENT=production \
LOG_JSON_FORMAT=true
# Expose ports
# 8001: Prometheus metrics
# 8002: Health checks
EXPOSE 8001 8002
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:8002/health || exit 1
# Default command (can be overridden)
CMD ["python", "-u", "main.py"]