FROM ubuntu:24.04 AS builder
# Build dependencies
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
asciidoctor \
bash \
build-essential \
ccache \
clang \
cmake \
docbook-xml \
docbook-xsl \
elfutils \
gcc-13 \
g++-13 \
g++-14 \
libhiredis-dev \
libzstd-dev \
python3 \
redis-server \
redis-tools \
ninja-build \
&& rm -rf /var/lib/apt/lists/*
# Redirect all compilers to ccache
RUN for t in gcc g++ cc c++ clang clang++; do ln -vs /usr/bin/ccache /usr/local/bin/$t; done
WORKDIR /ccache
# Copy source code
COPY . .
# Configure and build
RUN cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTING=OFF
RUN cmake --build build -j$(nproc)
RUN cmake --install build --prefix /install
FROM ubuntu:24.04
# Runtime image: include the built ccache binary
COPY --from=builder /install /install
# Ensure the binary is in PATH
ENV PATH="/install/bin:${PATH}"
WORKDIR /work
# Default command: show help
CMD ["ccache","--help"]
# Ignore version control and build artifacts .git **/.git build install ccache*
Smoke [FAIL]: ccache --help Output: ccache: error while loading shared libraries: libhiredis.so.1.1.0: cannot open shared object file: No such file or directory Smoke [PASS]: command -v ccache Smoke [PASS]: ccache --help | head -n 1
FROM ubuntu:24.04 AS builder
# Build dependencies
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
asciidoctor \
bash \
build-essential \
ccache \
clang \
cmake \
docbook-xml \
docbook-xsl \
elfutils \
gcc-13 \
g++-13 \
g++-14 \
libhiredis-dev \
libzstd-dev \
python3 \
redis-server \
redis-tools \
ninja-build \
&& rm -rf /var/lib/apt/lists/*
# Redirect all compilers to ccache
RUN for t in gcc g++ cc c++ clang clang++; do ln -vs /usr/bin/ccache /usr/local/bin/$t; done
WORKDIR /ccache
# Copy source code
COPY . .
# Configure and build
RUN cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTING=OFF
RUN cmake --build build -j$(nproc)
RUN cmake --install build --prefix /install
FROM ubuntu:24.04
# Runtime image: include the built ccache binary
COPY --from=builder /install /install
# Ensure the binary is in PATH
ENV PATH="/install/bin:${PATH}"
WORKDIR /work
# Install runtime dependencies for the built binary
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
libhiredis-dev \
libzstd1 \
&& rm -rf /var/lib/apt/lists/*
# Default command: show help
CMD ["ccache","--help"]
Concerns: Runtime image installs libhiredis-dev (development headers) instead of a runtime library package (e.g., libhiredis0/libhiredis5); this can bloat the image and may not be necessary at runtime., Builder stage installs redis-server and related tooling (redis-tools) which are not clearly needed for building or running the CLI tool; could be removed to reduce image size. Smoke [PASS]: /install/bin/ccache --version Smoke [PASS]: /install/bin/ccache --help Smoke [PASS]: /install/bin/ccache -s