-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
61 lines (45 loc) · 1.6 KB
/
Copy pathDockerfile
File metadata and controls
61 lines (45 loc) · 1.6 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
# Build stage
FROM python:3.11-slim AS builder
WORKDIR /app
# Install system dependencies for building
RUN apt-get update && apt-get install -y \
gcc \
g++ \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements first for better caching
COPY requirements.txt .
RUN pip install --no-cache-dir --user -r requirements.txt
# Runtime stage
FROM python:3.11-slim
WORKDIR /app
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user for security first
RUN useradd -m -u 1000 appuser
# Copy Python packages from builder to appuser's home
COPY --from=builder --chown=appuser:appuser /root/.local /home/appuser/.local
# Make sure scripts in .local are available
ENV PATH=/home/appuser/.local/bin:$PATH
# Copy application code
COPY --chown=appuser:appuser . .
# Create directories with proper permissions
RUN mkdir -p /app/logs /app/chroma_db && \
touch /app/filient.log && \
chown -R appuser:appuser /app/logs /app/chroma_db /app/filient.log && \
chmod 666 /app/filient.log
# Switch to non-root user
USER appuser
# Environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PORT=8000
# Health check - ChromaDB pre-initialized from S3, conservative start-period for safety
HEALTHCHECK --interval=30s --timeout=10s --start-period=240s --retries=3 \
CMD curl -f http://localhost:${PORT}/health || exit 1
# Expose port
EXPOSE ${PORT}
# Start command - use main_simple instead of main
CMD ["python", "-m", "uvicorn", "main_simple:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4"]