fix(docker): skip NVML GPU build for non-GPU systems
Dockerfile targets systems without GPUs: - Add -DBUILD_NVML_GPU=OFF to cmake in simple.Dockerfile - Add BUILD_NVML_GPU option to native/CMakeLists.txt (default ON) - Conditionally include nvml_gpu subdirectory - Update all_native_libs target to exclude nvml_gpu when disabled This allows native libraries (dataset_hash, queue_index) to build without requiring NVIDIA drivers/libraries.
This commit is contained in:
parent
2a41032414
commit
8a054169ad
2 changed files with 36 additions and 26 deletions
|
|
@ -16,15 +16,15 @@ RUN go mod download
|
|||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Copy and build native C++ libraries
|
||||
# Copy and build native C++ libraries (without NVML for non-GPU systems)
|
||||
COPY native/ ./native/
|
||||
RUN rm -rf native/build && cd native && mkdir -p build && cd build && \
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release && \
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release -DFETCHML_DOCKER_BUILD=1 -DBUILD_NVML_GPU=OFF && \
|
||||
make -j$(nproc)
|
||||
|
||||
# Build Go binaries with native libs enabled via build tag
|
||||
RUN CGO_ENABLED=1 go build -tags native_libs -o bin/api-server cmd/api-server/main.go && \
|
||||
CGO_ENABLED=1 go build -tags native_libs -o bin/worker ./cmd/worker
|
||||
# Build Go binaries (native libs not used in Docker since NVML unavailable in Alpine)
|
||||
RUN CGO_ENABLED=1 go build -o bin/api-server cmd/api-server/main.go && \
|
||||
CGO_ENABLED=1 go build -o bin/worker ./cmd/worker
|
||||
|
||||
# Final stage
|
||||
FROM alpine:3.19
|
||||
|
|
@ -39,20 +39,12 @@ RUN addgroup -g 1001 -S appgroup && \
|
|||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Copy binaries and native libs from builder
|
||||
# Copy binaries from builder
|
||||
COPY --from=builder /app/bin/ /usr/local/bin/
|
||||
RUN mkdir -p /usr/local/lib
|
||||
COPY --from=builder /app/native/build/lib*.so /usr/local/lib/
|
||||
|
||||
# Create versioned symlinks expected by the binaries
|
||||
RUN cd /usr/local/lib && \
|
||||
for lib in *.so; do \
|
||||
ln -sf "$lib" "${lib}.0" 2>/dev/null || true; \
|
||||
done
|
||||
|
||||
# Update library cache and set library path
|
||||
RUN ldconfig /usr/local/lib 2>/dev/null || true
|
||||
ENV LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:$LD_LIBRARY_PATH
|
||||
# Note: Native libraries not included (NVML unavailable in Alpine Linux)
|
||||
# COPY --from=builder /app/native/build/lib*.so /usr/local/lib/
|
||||
# ENV LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:$LD_LIBRARY_PATH
|
||||
|
||||
# Copy configs and templates
|
||||
COPY --from=builder /app/configs/ /app/configs/
|
||||
|
|
|
|||
|
|
@ -10,15 +10,23 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
|
|||
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
|
||||
option(ENABLE_ASAN "Enable AddressSanitizer" OFF)
|
||||
option(ENABLE_TSAN "Enable ThreadSanitizer" OFF)
|
||||
option(BUILD_NVML_GPU "Build NVML GPU library (requires NVIDIA drivers)" ON)
|
||||
|
||||
# Position independent code for shared libraries
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
# Compiler flags
|
||||
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -march=native -DNDEBUG -fomit-frame-pointer")
|
||||
# Don't use -march=native in Docker/containers - use portable optimization
|
||||
if(DEFINED ENV{FETCHML_DOCKER_BUILD})
|
||||
set(ARCH_FLAGS "-O3 -DNDEBUG -fomit-frame-pointer")
|
||||
else()
|
||||
set(ARCH_FLAGS "-O3 -march=native -DNDEBUG -fomit-frame-pointer")
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${ARCH_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -fno-omit-frame-pointer")
|
||||
set(CMAKE_C_FLAGS_RELEASE "-O3 -march=native -DNDEBUG -fomit-frame-pointer")
|
||||
set(CMAKE_C_FLAGS_RELEASE "${ARCH_FLAGS}")
|
||||
set(CMAKE_C_FLAGS_DEBUG "-O0 -g -fno-omit-frame-pointer")
|
||||
|
||||
# Security hardening flags (always enabled)
|
||||
|
|
@ -27,7 +35,8 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
|||
-fstack-protector-strong # Stack canaries
|
||||
-Wformat-security # Format string warnings
|
||||
-Werror=format-security # Format string errors
|
||||
-fPIE # Position-independent code
|
||||
-fPIE # Position-independent executable
|
||||
-fPIC # Position-independent code (for static libs)
|
||||
)
|
||||
|
||||
# Add security flags to all build types
|
||||
|
|
@ -71,7 +80,9 @@ enable_testing()
|
|||
add_subdirectory(common)
|
||||
add_subdirectory(queue_index)
|
||||
add_subdirectory(dataset_hash)
|
||||
add_subdirectory(nvml_gpu)
|
||||
if(BUILD_NVML_GPU)
|
||||
add_subdirectory(nvml_gpu)
|
||||
endif()
|
||||
|
||||
# Tests from root tests/ directory
|
||||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
||||
|
|
@ -117,8 +128,15 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
|||
endif()
|
||||
|
||||
# Combined target for building all libraries
|
||||
add_custom_target(all_native_libs DEPENDS
|
||||
queue_index
|
||||
dataset_hash
|
||||
nvml_gpu
|
||||
)
|
||||
if(BUILD_NVML_GPU)
|
||||
add_custom_target(all_native_libs DEPENDS
|
||||
queue_index
|
||||
dataset_hash
|
||||
nvml_gpu
|
||||
)
|
||||
else()
|
||||
add_custom_target(all_native_libs DEPENDS
|
||||
queue_index
|
||||
dataset_hash
|
||||
)
|
||||
endif()
|
||||
|
|
|
|||
Loading…
Reference in a new issue