# DO NOT EDIT this file.  Edit Dockerfile-rockylinux.m4 instead.

# Create a Docker image that is ready to run the full Daikon tests,
# including building the manual and Javadoc.
# But it's used primarily for running miscellaneous tests such as the manual
# and Javadoc.

FROM rockylinux/rockylinux:10
LABEL org.opencontainers.image.authors="Michael Ernst <mernst@cs.washington.edu>"

# According to
# https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/:
#  * Put "apt-get update" and "apt-get install" in the same RUN command.
#  * Do not run "apt-get upgrade"; instead get upstream to update.

# The EPEL repository contains certain packages.
RUN dnf -q -y upgrade && dnf -q -y install \
  epel-release

# curl is installed by default on Rocky Linux.
RUN dnf -q -y upgrade && dnf -q -y install \
  autoconf \
  automake \
  bc \
  binutils-devel \
  diffutils \
  findutils \
  gcc \
  git \
  jq \
  libxcrypt-devel \
  m4 \
  make \
  perl-English \
  perl-filetest \
  rsync \
  tar \
  unzip \
  wget \
  which

# Install the JDK.
# Not every OS packages a non-LTS JDK, so download the JDK.
# RUN curl --silent -o jdk-27_linux-x64_bin.tar.gz https://download.oracle.com/java/27/latest/jdk-27_linux-x64_bin.tar.gz \
RUN curl --silent -o jdk-27_linux-x64_bin.tar.gz https://download.java.net/java/GA/jdk27/55ce5470a6294008af0057ff4626d0e5/35/GPL/openjdk-27_linux-x64_bin.tar.gz \
&& tar xzf jdk-27_linux-x64_bin.tar.gz \
&& rm jdk-27_linux-x64_bin.tar.gz
ENV PATH="/jdk-27/bin:/root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
ENV JAVA27_HOME=/jdk-27

# The CRB repository contains certain packages, including dependencies of
# EPEL packages such as yamllint.  `crb` uses `dnf config-manager`, which is
# in dnf-plugins-core.
RUN dnf -q -y install dnf-plugins-core && crb enable

RUN dnf -q -y upgrade && dnf -q -y install \
  ctags \
  devscripts-checkbashisms \
  gcc-c++ \
  gdb \
  python3 \
  python3-distutils-extra \
  ShellCheck \
  texinfo \
  texinfo-tex \
  texlive \
  yamllint

# Valgrind's gdbserver regression tests, run by Fjalar's CI, need gdb (above)
# and glibc's debugging information.  (On Ubuntu, that is package libc6-dbg.)
# `dnf debuginfo-install` is in dnf-plugins-core.  It can succeed without
# installing anything, so check that glibc-debuginfo got installed.
RUN dnf -q -y config-manager --set-enabled baseos-debuginfo \
&& dnf -q -y upgrade && dnf -q -y debuginfo-install glibc \
&& rpm -q glibc-debuginfo

## Other ways to install gradle:
##  * The `dnf` package repository has a very old version of gradle.
##  * Need zip to install SDKMAN, need SDKMAN to install gradle.
##    However, SDKMAN requires bash, which would prevent the Docker container
##    from testing that Daikon runs under POSIX sh.
# Install gradle (needed for building daikon-plumelib.jar).
RUN wget -q https://services.gradle.org/distributions/gradle-9.8.0-bin.zip \
&& unzip -q -d /opt/gradle gradle-9.8.0-bin.zip \
&& rm gradle-9.8.0-bin.zip
ENV PATH=$PATH:/opt/gradle/gradle-9.8.0/bin

# Install shfmt.
RUN dnf -q -y upgrade && dnf -q -y install \
  golang \
&& go install mvdan.cc/sh/v3/cmd/shfmt@latest
ENV PATH=/root/go/bin:$PATH

# Install Python dependencies (obsolete, to be removed).
# `pipx ensurepath` only adds to the path in newly-started shells.
# BUT, setting the path for the current user is not enough.
# Azure creates a new user and runs jobs as it.
# So, install into /usr/local/bin which is already on every user's path.
RUN dnf -q -y install \
  pipx \
&& PIPX_HOME=/opt/pipx PIPX_BIN_DIR=/usr/local/bin pipx install mypy \
&& PIPX_HOME=/opt/pipx PIPX_BIN_DIR=/usr/local/bin pipx install ruff

# Install uv (manages Python dependencies).
# UV_NO_MODIFY_PATH=1 keeps the installer from editing shell startup files and
# from writing /root/.local/bin/env, a script for those files to source.  This
# Dockerfile sets the PATH instead.
# Download the installer to a file because a failure on the left side of a
# pipe would not fail the build.
RUN echo "installing uv" \
&& wget -qO /tmp/uv-install.sh https://astral.sh/uv/install.sh \
&& UV_NO_MODIFY_PATH=1 sh /tmp/uv-install.sh \
&& rm /tmp/uv-install.sh
ENV PATH=/root/.local/bin:$PATH

# Azure runs jobs as a non-root user, who must be able to read files in /root
# and run programs installed there.  Rocky Linux makes /root inaccessible to
# other users.  This step must follow every step that writes to /root.
RUN chmod -R og+rX /root

# Clean up.
RUN dnf -q clean all
