-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile.demo
More file actions
92 lines (81 loc) · 3.31 KB
/
Dockerfile.demo
File metadata and controls
92 lines (81 loc) · 3.31 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
82
83
84
85
86
87
88
89
90
91
92
# SPDX-License-Identifier: MIT
# Copyright (c) 2025 Vinny Parla
# File: Dockerfile.demo
# Purpose: builds the SDK and runs client+server together without touching the main build Dockerfile
# 1) Build stage
FROM ubuntu:24.04 AS build
ARG TARGETPLATFORM
ARG TARGETARCH
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
cmake \
ninja-build \
libssl-dev \
libboost-dev \
ca-certificates \
openssl \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /src
COPY . .
# Configure and build (Release + tests)
# Show Ninja progress and limit parallelism to reduce resource contention inside Docker
ENV NINJA_STATUS="[%f/%t %o/sec %es] "
ENV CMAKE_BUILD_PARALLEL_LEVEL=6
RUN bash -lc 'set -euo pipefail; \
cmake -S . -B build -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DMCP_BUILD_TESTS=ON \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DCMAKE_CXX_FLAGS="-Wfatal-errors -fdiagnostics-color=always" \
-DCMAKE_C_FLAGS="-Wfatal-errors -fdiagnostics-color=always"; \
cmake --build build --parallel "${CMAKE_BUILD_PARALLEL_LEVEL:-6}" --'
# 1b) Test stage: run unit tests inside the build environment
FROM build AS test
ARG MCP_STDIOTRANSPORT_TIMEOUT_MS
ENV MCP_STDIOTRANSPORT_TIMEOUT_MS=${MCP_STDIOTRANSPORT_TIMEOUT_MS}
ENV MCP_IN_CONTAINER=1
ENV GTEST_COLOR=yes
ENV CTEST_OUTPUT_ON_FAILURE=1
WORKDIR /src
# Set a per-test timeout to avoid indefinite hangs and show verbose progress
ENV CTEST_PARALLEL_LEVEL=4
# NOTE: Shared-memory transport (Boost.Interprocess message_queue) uses POSIX mqueues.
# Recommended: run with host IPC so the container sees the host's /dev/mqueue:
# docker run --rm -t \
# --ipc=host \
# mcp-cpp-build \
# bash -lc 'cd /src && ctest --test-dir build -R TransportDemo.Run -VV --output-on-failure'
# Alternatively, mount mqueue explicitly if supported:
# docker run --rm -t \
# --mount type=mqueue,target=/dev/mqueue \
# mcp-cpp-build \
# bash -lc 'cd /src && ctest --test-dir build -R TransportDemo.Run -VV --output-on-failure'
# Docker build stages cannot mount host devices; SHM demos may fail here without a host-IPC setup.
# Architecture checks are the first gate before the full suite.
RUN ctest --test-dir build -VV --progress --timeout 180 -R "^Architecture" \
&& ctest --test-dir build -VV --progress --timeout 180
# 2) Demo runtime stage
FROM ubuntu:24.04 AS demo
# bash and coreutils are available by default; ensure minimal tools
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
bash \
coreutils \
ca-certificates \
openssl \
&& rm -rf /var/lib/apt/lists/*
# Route logs to stderr to avoid corrupting stdio JSON-RPC frames
ENV MCP_STDIO_MODE=1
# To enable the Shared-memory transport demo inside this container, prefer host IPC:
# docker run --rm -t --ipc=host mcp-cpp-demo
# Alternatively, mount POSIX mqueue explicitly:
# docker run --rm -t --mount type=mqueue,target=/dev/mqueue mcp-cpp-demo
# Binaries
COPY --from=build /src/build/examples/mcp_server/mcp_server /usr/local/bin/mcp_server
COPY --from=build /src/build/examples/mcp_client/mcp_client /usr/local/bin/mcp_client
# Runner script
COPY scripts/run_demo.sh /usr/local/bin/run_demo.sh
RUN chmod +x /usr/local/bin/run_demo.sh
# Default entrypoint runs both client and server wired over stdio via FIFOs
ENTRYPOINT ["/usr/local/bin/run_demo.sh"]