# Dockerfile for running unit tests (monorepo root build context)
FROM rockylinux:8

# Install build and test dependencies
RUN dnf install -y epel-release && \
    dnf install -y \
    gcc \
    make \
    httpd \
    httpd-devel \
    apr-devel \
    apr-util-devel \
    cmake \
    python3 \
    curl \
    git \
    pkgconfig \
    libxml2-devel \
    && dnf clean all

# Build and install cmocka from source
RUN cd /tmp && \
    git clone https://git.cryptomilk.org/projects/cmocka.git && \
    cd cmocka && \
    git checkout cmocka-1.1.5 && \
    mkdir build && cd build && \
    cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release && \
    make && \
    make install && \
    ldconfig && \
    cd / && \
    rm -rf /tmp/cmocka

WORKDIR /build

COPY services/mod-reqin-log/src/ src/
COPY services/mod-reqin-log/tests/ tests/
COPY services/mod-reqin-log/CMakeLists.txt CMakeLists.txt
COPY services/mod-reqin-log/Makefile Makefile

RUN mkdir -p build/tests && cd build/tests && cmake ../../ && make

CMD ["ctest", "--output-on-failure"]
