content: FROM cr.eu-north1.nebius.cloud/soperator/ubuntu:noble AS controller_slurmctld
  
  ARG SLURM_VERSION
  
  ARG DEBIAN_FRONTEND=noninteractive
  
  # Install dependencies
  RUN apt-get update && \
      apt -y install \
          wget \
          curl \
          libssl-dev \
          libpam0g-dev \
          libtool \
          libjansson-dev \
          libjson-c-dev \
          libmunge-dev \
          libhwloc-dev \
          liblz4-dev \
          flex \
          libevent-dev \
          jq \
          squashfs-tools \
          zstd \
          iputils-ping \
          dnsutils \
          telnet \
          strace \
          vim \
          tree \
          lsof \
          daemontools && \
      apt-get clean && \
      rm -rf /var/lib/apt/lists/*
  
  # Add Nebius public registry
  RUN curl -fsSL https://dr.nebius.cloud/public.gpg -o /usr/share/keyrings/nebius.gpg.pub && \
      codename="$(. /etc/os-release && echo $VERSION_CODENAME)" && \
      echo "deb [signed-by=/usr/share/keyrings/nebius.gpg.pub] https://dr.nebius.cloud/ $codename main" > /etc/apt/sources.list.d/nebius.list && \
      echo "deb [signed-by=/usr/share/keyrings/nebius.gpg.pub] https://dr.nebius.cloud/ stable main" >> /etc/apt/sources.list.d/nebius.list
  
  RUN apt-get update && \
      apt -y install \
        slurm-smd-client=${SLURM_VERSION}-1 \
        slurm-smd-dev=${SLURM_VERSION}-1 \
        slurm-smd-libnss-slurm=${SLURM_VERSION}-1 \
        slurm-smd=${SLURM_VERSION}-1 \
        slurm-smd-slurmctld=${SLURM_VERSION}-1 && \
      apt-get clean && \
      rm -rf /var/lib/apt/lists/*
  
  # Create single folder with slurm plugins for all architectures
  RUN mkdir -p /usr/lib/slurm && \
      for dir in /usr/lib/*-linux-gnu/slurm; do \
        [ -d "$dir" ] && ln -sf $dir/* /usr/lib/slurm/ 2>/dev/null || true; \
      done
  # Update linker cache
  RUN ldconfig
  
  # Delete users & home because they will be linked from jail
  RUN rm /etc/passwd* /etc/group* /etc/shadow* /etc/gshadow*
  RUN rm -rf /home
  
  # Expose the port used for accessing slurmctld
  EXPOSE 6817
  
  # Create dir and file for multilog hack
  RUN mkdir -p /var/log/slurm/multilog && \
      touch /var/log/slurm/multilog/current && \
      ln -s /var/log/slurm/multilog/current /var/log/slurm/slurmctld.log
  
  # Copy & run the entrypoint script
  COPY images/controller/slurmctld_entrypoint.sh /opt/bin/slurm/
  RUN chmod +x /opt/bin/slurm/slurmctld_entrypoint.sh
  ENTRYPOINT ["/opt/bin/slurm/slurmctld_entrypoint.sh"]
  