Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
81 lines (61 loc) · 1.88 KB
/
Copy pathDockerfile
File metadata and controls
81 lines (61 loc) · 1.88 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
# Multi-stage build for optimal image size
FROM python:3.13.7-slim AS builder
# Install UV using the recommended method
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
git \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Create virtual environment
RUN uv venv /opt/venv
ENV VIRTUAL_ENV=/opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Copy dependency files first for better caching
COPY pyproject.toml README.md ./
# Install dependencies without the project itself (better caching)
RUN --mount=type=cache,target=/root/.cache/uv \
UV_LINK_MODE=copy \
uv pip install -e . --compile
# Copy the rest of the application
COPY . .
# Final stage
FROM python:3.13.7-slim
# Install runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
postgresql-client \
curl \
netcat-openbsd \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN useradd -m -u 1000 -s /bin/bash appuser
# Set working directory
WORKDIR /app
# Copy virtual environment from builder
COPY --from=builder /opt/venv /opt/venv
ENV VIRTUAL_ENV=/opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Copy application code
COPY --chown=appuser:appuser . .
# Create necessary directories
RUN mkdir -p logs repositories .embeddings_cache && \
chown -R appuser:appuser /app
# Switch to non-root user
USER appuser
# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONPATH=/app
# Expose port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
# Entrypoint script
COPY --chown=appuser:appuser docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["server"]