Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
101 lines (81 loc) · 3.33 KB
/
Copy pathDockerfile
File metadata and controls
101 lines (81 loc) · 3.33 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
93
94
95
96
97
98
99
100
101
# syntax=docker/dockerfile:1.7
# =============================================================================
# Multi-stage Dockerfile
#
# Stage 1 (toolchain): ubuntu:26.04 - installs Conan 2 + C++ build tools.
# Stage 2 (conan-deps): cache-stable dependency resolution layer.
# Stage 3 (builder): configure + compile with ccache.
# Stage 4 (verified): run unit tests and collect runtime artifacts.
# Stage 5 (final): gcr.io/distroless/cc-debian12 runtime image.
# =============================================================================
# ---------------------------------------------------------------------------
# Stage 1: Toolchain
# ---------------------------------------------------------------------------
FROM ubuntu:26.04 AS toolchain
RUN apt-get update && apt-get install -y --no-install-recommends \
cmake \
ninja-build \
make \
clang-18 \
clang-tidy-18 \
lld \
ccache \
python3-pip \
git \
ca-certificates \
libssl-dev \
pkg-config \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*
RUN pip3 install "conan>=2.0" --break-system-packages \
&& conan profile detect --force
WORKDIR /app
# ---------------------------------------------------------------------------
# Stage 2: Conan dependencies
# Keep this layer stable by copying only dependency-defining files first.
# ---------------------------------------------------------------------------
FROM toolchain AS conan-deps
COPY conanfile.py CMakeLists.txt CMakePresets.json ./
COPY conan ./conan
RUN conan install . \
--profile:host conan/profiles/linux-clang18 \
--profile:build conan/profiles/linux-clang18 \
--build=missing \
-s:h build_type=Release \
-s:b build_type=Release
# ---------------------------------------------------------------------------
# Stage 3: Build
# ---------------------------------------------------------------------------
FROM conan-deps AS builder
COPY proto ./proto
COPY src ./src
COPY tests ./tests
RUN cmake --preset conan-release \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
RUN --mount=type=cache,target=/root/.cache/ccache,id=ccache-obj-cache \
cmake --build --preset conan-release --parallel "$(nproc)"
# ---------------------------------------------------------------------------
# Stage 4: Verify and collect runtime assets
# ---------------------------------------------------------------------------
FROM builder AS verified
RUN run-clang-tidy-18 -p build/Release src/
RUN ctest --test-dir build/Release --output-on-failure --parallel "$(nproc)"
RUN mkdir /runtime && \
cp /app/build/Release/src/hello_server /runtime/hello_server && \
ldd /runtime/hello_server 2>/dev/null \
| grep "=> /" \
| awk '{print $3}' \
| sort -u \
| while IFS= read -r lib; do \
cp --no-preserve=mode,ownership "$lib" /runtime/ || true; \
done
# ---------------------------------------------------------------------------
# Stage 5: Minimal runtime image
# ---------------------------------------------------------------------------
FROM gcr.io/distroless/cc-debian12 AS final
COPY --from=verified /runtime/hello_server /hello_server
COPY --from=verified /runtime/*.so* /usr/lib/
EXPOSE 50051
EXPOSE 9090
ENTRYPOINT ["/hello_server"]