FROM debian:bookworm

ENV DEBIAN_FRONTEND=noninteractive
ENV TIMEZONE=Europe/Amsterdam

RUN apt update --fix-missing
RUN apt dist-upgrade -y --no-install-recommends

RUN echo $TIMEZONE > /etc/timezone
RUN dpkg-reconfigure -f noninteractive tzdata

RUN apt install -y libsensors5 liblzo2-2 collectd btrfs-progs libatasmart4 speedtest-cli

RUN apt install -y smartmontools

RUN apt install -y wget git

ENV HDDTEMP_VERSION=0.3.1
RUN wget https://github.com/slowpeek/hddtemp/archive/refs/tags/${HDDTEMP_VERSION}.tar.gz \
    && tar xvf ${HDDTEMP_VERSION}.tar.gz && mv hddtemp-${HDDTEMP_VERSION}/hddtemp-lt /usr/sbin/hddtemp

RUN apt -y install make g++ python3 python3-dev python3-pybind11 cmake

COPY PMT /pmt
#RUN git clone https://git.astron.nl:/RD/pmt
RUN cmake -Spmt -Bpmt/build -DPMT_BUILD_RAPL=1 -DPMT_BUILD_BINARY=1 -DPMT_BUILD_PYTHON=1 -DCMAKE_INSTALL_PREFIX=/opt/pmt
RUN make -Cpmt/build -j install
ENV LD_LIBRARY_PATH="/opt/pmt/lib"
ENV PYTHONPATH="/opt/pmt/lib/python3.11/site-packages"
ENV PATH="$PATH:/opt/pmt/bin"
RUN apt -y remove make g++ python3-dev python3-pybind11 cmake
RUN apt autoremove -y

RUN apt -y install sudo
RUN adduser collectd
RUN usermod -aG sudo collectd
RUN echo 'collectd ALL=(ALL) NOPASSWD:ALL' | sudo tee /etc/sudoers.d/collectd


RUN apt install -y --no-install-recommends python3-pip
RUN pip install --break-system-packages requests

RUN wget https://github.com/nickbabcock/pg-collectd/releases/download/v0.2.0/pg-collectd-collectd57_0.2.0_amd64.deb
RUN dpkg -i pg-collectd-collectd57_0.2.0_amd64.deb
RUN rm pg-collectd-collectd57_0.2.0_amd64.deb

CMD ["/usr/sbin/collectd", "-f"]
