# Build stage with full CUDA toolkit
FROM nvidia/cuda:12.8.0-devel-ubuntu22.04 as builder

# Install build dependencies
RUN apt-get update && apt-get install -y \
    build-essential \
    cmake \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /build

# Copy source code
COPY . .

# Build the application
RUN cmake . && make

# Runtime stage with minimal CUDA runtime
FROM nvidia/cuda:12.8.0-runtime-ubuntu22.04

# Install runtime dependencies only
RUN apt-get update && apt-get install -y \
    libgomp1 \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

# Copy built application from builder stage
COPY --from=builder /build/app /usr/local/bin/app

# Set the entrypoint
ENTRYPOINT ["/usr/local/bin/app"]