FROM ubuntu:jammy-20260210.1
# Non-interactive apt installs
ENV DEBIAN_FRONTEND=noninteractive
# Install build tools and optional docs
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential cmake libomp-dev doxygen graphviz \
&& rm -rf /var/lib/apt/lists/*
# Copy source and build from source
WORKDIR /src
COPY . /src
# Configure, build, and install the project from source
RUN cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
RUN cmake --build build --parallel 4
RUN cmake --install build
# Default to an interactive shell
CMD ["/bin/bash"]
# Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C/C++ build products build/ CMakeFiles/ CMakeCache.txt cmake_install.cmake Makefile # OS / IDE files *.swp *.swo .DS_Store # Git .git/ .gitignore # Others docs/ .doc/
# Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C/C++ build products build/ CMakeFiles/ CMakeCache.txt cmake_install.cmake Makefile # OS / IDE files *.swp *.swo .DS_Store # Git .git/ .gitignore # Documentation doc/ docs/ # Others *.log
Concerns: Final image includes the entire source tree under /src; consider using a multi-stage build or removing sources to reduce image size., No non-root user is configured; consider adding a non-privileged user for security. Smoke [PASS]: test -f /src/build/compile_commands.json || test -f /src/compile_commands.json Smoke [FAIL]: cmake --version >/dev/null 2>&1 && echo 'cmake available' || echo 'cmake missing Output: sh: 1: Syntax error: Unterminated quoted string Smoke [PASS]: ls -l /usr/local/bin | head -n 5
# Multi-stage build for TheAlgorithms/C++ repo
# Stage 1: builder
FROM ubuntu:jammy-20260210.1 AS builder
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential cmake libomp-dev doxygen graphviz \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /src
COPY . /src
# Configure and build
RUN cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
RUN cmake --build build --parallel 4
RUN cmake --install build
# Stage 2: runtime
FROM ubuntu:jammy-20260210.1
ENV DEBIAN_FRONTEND=noninteractive
# Create non-root user for security
RUN useradd -m appuser
USER appuser
WORKDIR /home/appuser
# Copy built artifacts and build files needed for runtime checks
COPY --from=builder /usr/bin /usr/bin
COPY --from=builder /usr/local /usr/local
COPY --from=builder /src/build /src/build
CMD ["/bin/bash"]
Smoke [FAIL]: test -d /usr/local/bin && echo 'bin_dir_present' || echo 'bin_dir_missing Output: sh: 1: Syntax error: Unterminated quoted string Smoke [FAIL]: test -d /src/build && echo 'src_build_present' || echo 'src_build_missing Output: sh: 1: Syntax error: Unterminated quoted string Smoke [PASS]: ls -1 /usr/local/bin | head -n 1
# Base image
FROM ubuntu:jammy-20260210.1
ENV DEBIAN_FRONTEND=noninteractive
# Install build dependencies (OpenMP is optional, but libomp is useful)
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential cmake libomp-dev doxygen graphviz \
&& rm -rf /var/lib/apt/lists/*
# Copy source and build from source
WORKDIR /src
COPY . /src
# Configure and build
RUN cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
RUN cmake --build build --parallel 4
RUN cmake --install build
# Create a non-root user for running the container
RUN useradd -m appuser
USER appuser
# Default command
CMD ["/bin/bash"]
Concerns: The default CMD is /bin/bash, which is not a runnable entrypoint for a deployed application and may require override for typical use cases., Smoke tests assume a CMake build configuration outputs (CMakeCache.txt, compile_commands.json, Makefile) in /src/build; if the project uses a different workflow or generator, these tests may not be reliable. Smoke [PASS]: test -f /src/build/CMakeCache.txt && echo cmake-configured Smoke [PASS]: test -f /src/build/compile_commands.json && echo compile-commands-exported Smoke [PASS]: test -f /src/build/Makefile && echo makefile-present