-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
68 lines (55 loc) · 1.72 KB
/
Dockerfile
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
FROM python:3.11-slim as builder
# Install build dependencies and uv
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/* \
&& pip install uv
# Create and switch to a non-root user
RUN useradd --create-home appuser
USER appuser
WORKDIR /home/appuser
# Copy only the files needed for installation
COPY --chown=appuser:appuser pyproject.toml .
# Create virtual environment and install dependencies
RUN uv venv /home/appuser/venv && \
. /home/appuser/venv/bin/activate && \
uv pip install \
aiosqlite==0.20.0 \
alembic==1.14.0 \
boto3==1.35.92 \
chromadb==0.6.1 \
fastapi==0.115.6 \
greenlet==3.1.1 \
openai==1.59.3 \
pydantic==2.10.4 \
python-dotenv==1.0.1 \
python-multipart==0.0.20 \
tiktoken==0.8.0 \
uvicorn==0.34.0 \
ollama==0.3.3
# Final stage
FROM python:3.11-slim
# Install curl for healthcheck
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create and switch to a non-root user
RUN useradd --create-home appuser
USER appuser
WORKDIR /home/appuser
# Create data directories with proper permissions
RUN mkdir -p /home/appuser/data
RUN mkdir -p /home/appuser/chroma_db
# Copy virtual environment and application code
COPY --from=builder --chown=appuser:appuser /home/appuser/venv /home/appuser/venv
COPY --chown=appuser:appuser . .
# Make entrypoint script executable
RUN chmod +x /home/appuser/docker-entrypoint.sh
# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV PORT=8000
ENV PATH="/home/appuser/venv/bin:$PATH"
# Expose the port the app runs on
EXPOSE 8000
# Use the entrypoint script
ENTRYPOINT ["/home/appuser/docker-entrypoint.sh"]