-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
76 lines (61 loc) · 3.15 KB
/
Copy pathDockerfile
File metadata and controls
76 lines (61 loc) · 3.15 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
# context-broker-langgraph — Application container
# All LangGraph flows, queue workers, Imperator, and ASGI server.
#
# Build context: project root (.)
FROM python:3.12.10-slim
ARG USER_NAME=context-broker
ARG USER_UID=1000
ARG USER_GID=1000
# Root phase: system packages, user creation
RUN apt-get update && \
apt-get install -y --no-install-recommends \
curl \
build-essential \
libpq-dev && \
rm -rf /var/lib/apt/lists/* && \
groupadd --gid ${USER_GID} ${USER_NAME} && \
useradd --uid ${USER_UID} --gid ${USER_GID} --shell /bin/bash --create-home ${USER_NAME}
USER ${USER_NAME}
WORKDIR /app
# REQ-001 §10: Enable --user pip installs for runtime StateGraph packages
ENV PYTHONUSERBASE=/home/${USER_NAME}/.local
ENV PATH="/home/${USER_NAME}/.local/bin:${PATH}"
# Copy requirements and install dependencies
COPY --chown=${USER_NAME}:${USER_NAME} requirements.txt ./
# Package source is configurable: local wheels, pypi, or devpi
# Default: pypi (wheels can be placed in /app/packages for local mode)
ARG PACKAGE_SOURCE=pypi
ARG DEVPI_URL=""
RUN if [ "$PACKAGE_SOURCE" = "local" ]; then \
pip install --no-cache-dir --no-index --find-links=/app/packages -r requirements.txt; \
elif [ "$PACKAGE_SOURCE" = "devpi" ] && [ -n "$DEVPI_URL" ]; then \
pip install --no-cache-dir --index-url "$DEVPI_URL" -r requirements.txt; \
else \
pip install --no-cache-dir -r requirements.txt; \
fi
USER root
RUN apt-get purge -y --auto-remove build-essential && rm -rf /var/lib/apt/lists/*
USER ${USER_NAME}
# Copy application code and entrypoint
COPY --chown=${USER_NAME}:${USER_NAME} app/ ./app/
COPY --chown=${USER_NAME}:${USER_NAME} entrypoint.sh ./entrypoint.sh
RUN chmod +x ./entrypoint.sh
# REQ-001 §10: Copy and pre-build StateGraph packages as wheels.
# Built to /app/stategraph-wheels/ (not /app/packages/ which may be volume-mounted).
# entrypoint.sh installs them at startup via pip install --user --no-deps.
COPY --chown=${USER_NAME}:${USER_NAME} packages/context-broker-ae/ ./sg-src/context-broker-ae/
COPY --chown=${USER_NAME}:${USER_NAME} packages/context-broker-te/ ./sg-src/context-broker-te/
RUN mkdir -p ./stategraph-wheels && \
pip wheel --no-deps -w ./stategraph-wheels/ ./sg-src/context-broker-ae/ && \
pip wheel --no-deps -w ./stategraph-wheels/ ./sg-src/context-broker-te/ && \
rm -rf ./sg-src
# Mem0 fork: overlay modified files on top of stock mem0ai (installed via requirements.txt).
# The fork only modifies mem0/memory/main.py and mem0/memory/graph_memory.py.
# It cannot be a separate wheel because pip would uninstall stock mem0ai first,
# losing all other submodules (configs, embeddings, llms, graphs, etc.).
COPY --chown=${USER_NAME}:${USER_NAME} packages/mem0-fork/mem0/memory/main.py /home/${USER_NAME}/.local/lib/python3.12/site-packages/mem0/memory/main.py
COPY --chown=${USER_NAME}:${USER_NAME} packages/mem0-fork/mem0/memory/graph_memory.py /home/${USER_NAME}/.local/lib/python3.12/site-packages/mem0/memory/graph_memory.py
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=3s --start-period=300s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
ENTRYPOINT ["./entrypoint.sh"]