-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
84 lines (66 loc) · 2.39 KB
/
Dockerfile
File metadata and controls
84 lines (66 loc) · 2.39 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
# Multi-stage Docker build for optimized image size
# Stage 1: Builder
FROM python:3.11-slim as builder
# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Set working directory
WORKDIR /app
# Copy dependency files first for better layer caching
COPY pyproject.toml ./
# Install dependencies using uv (extract dependencies from pyproject.toml)
# This layer will be cached unless pyproject.toml changes
RUN uv pip install --system --no-cache \
fastapi>=0.104.1 \
uvicorn[standard]>=0.24.0 \
sqlalchemy>=2.0.23 \
alembic>=1.12.1 \
asyncpg>=0.29.0 \
redis>=5.0.1 \
authlib>=1.2.1 \
python-jose[cryptography]>=3.3.0 \
bcrypt>=4.0.1 \
python-multipart>=0.0.6 \
pydantic>=2.5.0 \
pydantic[email]>=2.5.0 \
pydantic-settings>=2.1.0 \
openai>=1.3.0 \
instructor>=0.4.5 \
langgraph>=0.0.40 \
pdfplumber>=0.10.0 \
aiofiles>=23.2.1 \
python-dotenv>=1.0.0 \
livekit>=0.11.0 \
livekit-agents>=0.7.0 \
docker>=6.1.0
# Stage 2: Runtime
FROM python:3.11-slim
# Install runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
libpq5 \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN useradd -m -u 1000 appuser && mkdir -p /app && chown -R appuser:appuser /app
# Set working directory
WORKDIR /app
# Copy uv from builder
COPY --from=builder /usr/local/bin/uv /usr/local/bin/uv
# Copy installed packages from builder
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Ensure PATH includes /usr/local/bin for livekit-agents command
ENV PATH="/usr/local/bin:${PATH}"
# Copy only necessary application files (excludes frontend, tests, etc. via .dockerignore)
# Copy source code last for better layer caching
COPY --chown=appuser:appuser src/ ./src/
COPY --chown=appuser:appuser alembic.ini ./
COPY --chown=appuser:appuser alembic/ ./alembic/
# Switch to non-root user
USER appuser
# Expose port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import requests; requests.get('http://localhost:8000/health')" || exit 1
# Run migrations and start application
# Railway will override PORT via $PORT environment variable
CMD ["sh", "-c", "alembic upgrade head && uvicorn src.main:app --host 0.0.0.0 --port ${PORT:-8000}"]