From 691cceb116bebd4a0fd41f7dbbc216facf1f7355 Mon Sep 17 00:00:00 2001 From: johndoe6345789 Date: Thu, 22 Jan 2026 01:20:01 +0000 Subject: [PATCH] fix(dbal): fix Docker build for C++ DBAL daemon Dockerfile fixes: - Mirror original directory structure in container (/dbal not /build) - Copy CMakeLists.txt and conanfile.txt to build-config/ subdirectory - Fix Conan 2.x toolchain path (build/build/Release/generators/) - Update binary copy path for runtime stage CMakeLists.txt fixes: - Make test builds conditional on tests/ directory existing - Allows production builds to skip tests (excluded via .dockerignore) Tested: Successfully builds 38MB production image with 10MB daemon binary Co-Authored-By: Claude Opus 4.5 --- dbal/production/build-config/CMakeLists.txt | 53 +++++++++++---------- dbal/production/build-config/Dockerfile | 20 ++++---- 2 files changed, 40 insertions(+), 33 deletions(-) diff --git a/dbal/production/build-config/CMakeLists.txt b/dbal/production/build-config/CMakeLists.txt index 5f8f8589b..e939b23c5 100644 --- a/dbal/production/build-config/CMakeLists.txt +++ b/dbal/production/build-config/CMakeLists.txt @@ -65,38 +65,41 @@ if(spdlog_FOUND) target_link_libraries(dbal_core spdlog::spdlog) endif() -enable_testing() +# Only build tests if test directory exists +if(EXISTS "${DBAL_TEST_DIR}") + enable_testing() -add_executable(client_test - ${DBAL_TEST_DIR}/unit/client_test.cpp -) + add_executable(client_test + ${DBAL_TEST_DIR}/unit/client_test.cpp + ) -add_executable(query_test - ${DBAL_TEST_DIR}/unit/query_test.cpp -) + add_executable(query_test + ${DBAL_TEST_DIR}/unit/query_test.cpp + ) -add_executable(integration_tests - ${DBAL_TEST_DIR}/integration/sqlite_test.cpp -) + add_executable(integration_tests + ${DBAL_TEST_DIR}/integration/sqlite_test.cpp + ) -add_executable(conformance_tests - ${DBAL_TEST_DIR}/conformance/runner.cpp -) + add_executable(conformance_tests + ${DBAL_TEST_DIR}/conformance/runner.cpp + ) -add_executable(http_server_security_test - ${DBAL_TEST_DIR}/security/http_server_security_test.cpp -) + add_executable(http_server_security_test + ${DBAL_TEST_DIR}/security/http_server_security_test.cpp + ) -target_link_libraries(client_test dbal_core dbal_adapters) -target_link_libraries(query_test dbal_core dbal_adapters) -target_link_libraries(integration_tests dbal_core dbal_adapters) -target_link_libraries(conformance_tests dbal_core dbal_adapters) -target_link_libraries(http_server_security_test Threads::Threads) + target_link_libraries(client_test dbal_core dbal_adapters) + target_link_libraries(query_test dbal_core dbal_adapters) + target_link_libraries(integration_tests dbal_core dbal_adapters) + target_link_libraries(conformance_tests dbal_core dbal_adapters) + target_link_libraries(http_server_security_test Threads::Threads) -add_test(NAME client_test COMMAND client_test) -add_test(NAME query_test COMMAND query_test) -add_test(NAME integration_tests COMMAND integration_tests) -add_test(NAME conformance_tests COMMAND conformance_tests) + add_test(NAME client_test COMMAND client_test) + add_test(NAME query_test COMMAND query_test) + add_test(NAME integration_tests COMMAND integration_tests) + add_test(NAME conformance_tests COMMAND conformance_tests) +endif() install(TARGETS dbal_daemon DESTINATION bin) install(DIRECTORY ${DBAL_INCLUDE_DIR}/dbal DESTINATION include) diff --git a/dbal/production/build-config/Dockerfile b/dbal/production/build-config/Dockerfile index 26c39bae4..a959593c0 100644 --- a/dbal/production/build-config/Dockerfile +++ b/dbal/production/build-config/Dockerfile @@ -15,22 +15,26 @@ RUN apt-get update && apt-get install -y \ libsqlite3-dev \ && rm -rf /var/lib/apt/lists/* -# Set working directory -WORKDIR /build +# Set working directory - mirror the original structure +WORKDIR /dbal -# Copy source files -COPY CMakeLists.txt conanfile.txt ./ +# Copy entire dbal/production structure COPY include/ include/ COPY src/ src/ -COPY tests/ tests/ + +# Copy build-config as a subdirectory (maintains CMakeLists.txt paths) +COPY build-config/CMakeLists.txt build-config/CMakeLists.txt +COPY build-config/conanfile.txt build-config/conanfile.txt # Install Conan and dependencies RUN pip3 install --no-cache-dir conan && \ conan profile detect --force -# Build the daemon +# Build the daemon from build-config directory +WORKDIR /dbal/build-config RUN conan install . --output-folder=build --build=missing && \ - cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -S . -B build -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake && \ + cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -S . -B build \ + -DCMAKE_TOOLCHAIN_FILE=build/build/Release/generators/conan_toolchain.cmake && \ cmake --build build --target dbal_daemon # Stage 2: Runtime @@ -49,7 +53,7 @@ RUN useradd -r -u 1000 -m -s /bin/bash dbal WORKDIR /app # Copy binary from builder -COPY --from=builder /build/build/dbal_daemon /app/dbal_daemon +COPY --from=builder /dbal/build-config/build/dbal_daemon /app/dbal_daemon # Copy default config (can be overridden with volume mount) RUN echo "# DBAL Configuration" > /app/config.yaml