1
1
# Use a Python image with uv pre-installed
2
2
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS uv
3
3
4
- # Set build argument
5
- ARG DEBUG
6
-
7
- # Set environment variable based on the build argument
8
- ENV DEBUG=${DEBUG}
9
- ENV PIP_NO_CACHE_DIR=true
10
-
4
+ # Install the project into `/app`
11
5
WORKDIR /app
12
6
13
7
# Enable bytecode compilation
@@ -16,20 +10,27 @@ ENV UV_COMPILE_BYTECODE=1
16
10
# Copy from the cache instead of linking since it's a mounted volume
17
11
ENV UV_LINK_MODE=copy
18
12
19
- RUN apt-get update && apt-get install -y \
20
- gcc \
21
- libpq-dev
13
+ # Install the project's dependencies using the lockfile and settings
14
+ RUN --mount=type=cache,target=/root/.cache/uv \
15
+ --mount=type=bind,source=uv.lock,target=uv.lock \
16
+ --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
17
+ uv sync --frozen --no-install-project --no-dev --no-editable
22
18
23
- COPY . /app
19
+ # Then, add the rest of the project source code and install it
20
+ # Installing separately from its dependencies allows optimal layer caching
21
+ ADD . /app
22
+ RUN --mount=type=cache,target=/root/.cache/uv \
23
+ uv sync --frozen --no-dev --no-editable
24
24
25
- RUN uv sync --reinstall
25
+ FROM python:3.12-slim-bookworm
26
26
27
- # Place executables in the environment at the front of the path
28
- ENV PATH="/app:/app/.venv/bin:$PATH"
27
+ WORKDIR /app
28
+
29
+ COPY --from=uv /root/.local /root/.local
30
+ COPY --from=uv --chown=app:app /app/.venv /app/.venv
31
+ COPY --from=uv --chown=app:app /app/src /app/src
29
32
30
- # Set environment variables for MCP server
31
- ENV PYTHONUNBUFFERED=1
32
- ENV MCP_LOG_LEVEL=DEBUG
33
- ENV PYTHONPATH=/app
33
+ # Place executables in the environment at the front of the path
34
+ ENV PATH="/app/.venv/bin:$PATH"
34
35
35
36
ENTRYPOINT ["cognee" ]
0 commit comments