Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
77 lines (56 loc) · 2.54 KB
/
Copy pathDockerfile
File metadata and controls
77 lines (56 loc) · 2.54 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
# Multi-stage Docker build for agent-memory
FROM python:3.11-slim AS builder
# Build argument for version (passed from CI)
ARG VERSION=0.0.0
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
&& rm -rf /var/lib/apt/lists/*
# Install build backend dependencies (required for --no-build-isolation)
RUN pip install --no-cache-dir hatchling hatch-vcs
# Set working directory
WORKDIR /app
# Copy project files
COPY pyproject.toml README.md ./
COPY agent_memory/ ./agent_memory/
COPY mcp_server/ ./mcp_server/
# Set version for hatch-vcs (since .git is not available in build context)
ENV SETUPTOOLS_SCM_PRETEND_VERSION=${VERSION}
# Debug: print version
RUN echo "Building version: ${VERSION}" && echo "SETUPTOOLS_SCM_PRETEND_VERSION=${SETUPTOOLS_SCM_PRETEND_VERSION}"
# Install runtime dependencies including chromadb (without editable to avoid VCS version detection)
RUN SETUPTOOLS_SCM_PRETEND_VERSION=${VERSION} pip install --no-cache-dir --no-build-isolation ".[chromadb]"
# Runtime stage - use slim for pip availability, but keep it minimal
FROM python:3.11-slim AS runtime
# Build argument for version (passed from CI)
ARG VERSION=0.0.0
# Set version for hatch-vcs in runtime stage too
ENV SETUPTOOLS_SCM_PRETEND_VERSION=${VERSION}
# Install runtime dependencies only
RUN apt-get update && apt-get install -y --no-install-recommends \
libstdc++6 \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN useradd --create-home --shell /bin/bash appuser
# Set working directory to user's home directory
WORKDIR /home/appuser
# Copy installed packages from builder (only runtime deps)
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
# Copy source code and install in runtime (without dev dependencies)
COPY --from=builder /app/agent_memory ./agent_memory
COPY --from=builder /app/mcp_server ./mcp_server
COPY --from=builder /app/pyproject.toml ./pyproject.toml
COPY --from=builder /app/README.md ./README.md
# Install package in runtime (without dev dependencies, with build isolation for build backend)
RUN SETUPTOOLS_SCM_PRETEND_VERSION=${VERSION} pip install --no-cache-dir --no-deps .
# Create data directory for persistence
RUN mkdir -p /home/appuser/.agent_memory && chown -R appuser:appuser /home/appuser
# Switch to non-root user
USER appuser
ENV HOME=/home/appuser
ENV AGENT_MEMORY_DIR=/home/appuser/.agent_memory
# Expose MCP server port (if needed)
EXPOSE 8000
# Set entrypoint
ENTRYPOINT ["agent-memory"]