-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.backend
More file actions
executable file
·52 lines (39 loc) · 2.03 KB
/
Dockerfile.backend
File metadata and controls
executable file
·52 lines (39 loc) · 2.03 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
# ---- Stage 0: Node.js base (for MCP server) ----
FROM node:20-slim AS node-base
# ---- Stage 1: Build ----
FROM python:3.11-slim-bookworm AS builder
WORKDIR /app
# Install curl (needed for crypt_shared download)
RUN apt-get update && apt-get install -y --no-install-recommends curl \
&& rm -rf /var/lib/apt/lists/*
# Download MongoDB crypt_shared library (Linux x86_64, Debian 12)
# Must match your Atlas server major version (8.0.x for MongoDB 8.x)
# Available versions: https://www.mongodb.com/try/download/enterprise-advanced/releases/archive
ARG CRYPT_SHARED_VERSION=8.0.4
RUN mkdir -p /opt/mongo_crypt \
&& curl -fSL "https://downloads.mongodb.com/linux/mongo_crypt_shared_v1-linux-x86_64-enterprise-debian12-${CRYPT_SHARED_VERSION}.tgz" \
| tar -xzf - -C /opt/mongo_crypt \
&& test -f /opt/mongo_crypt/lib/mongo_crypt_v1.so
# Install Poetry and dependencies (before copying app code for layer caching)
COPY /backend/pyproject.toml /backend/poetry.lock ./
RUN pip install --no-cache-dir poetry==1.8.4 \
&& poetry config virtualenvs.in-project true \
&& poetry install --no-interaction --no-cache --no-root
# ---- Stage 2: Runtime ----
FROM python:3.11-slim-bookworm
WORKDIR /app
# Copy Node.js runtime from official image (required for npx mongodb-mcp-server)
COPY --from=node-base /usr/local/bin/node /usr/local/bin/node
COPY --from=node-base /usr/local/lib/node_modules /usr/local/lib/node_modules
COPY --from=node-base /usr/local/include/node /usr/local/include/node
RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm \
&& ln -s /usr/local/lib/node_modules/npm/bin/npx-cli.js /usr/local/bin/npx
# Copy crypt_shared library and venv from builder
COPY --from=builder /opt/mongo_crypt/lib/mongo_crypt_v1.so /opt/mongo_crypt/lib/mongo_crypt_v1.so
COPY --from=builder /app/.venv /app/.venv
# Copy application code
COPY ./backend/ .
ENV CRYPT_SHARED_LIB_PATH=/opt/mongo_crypt/lib/mongo_crypt_v1.so
ENV PATH="/app/.venv/bin:$PATH"
EXPOSE 8080
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]