# 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:9
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.
RUN dnf -q -y upgrade && dnf -q -y install \
  java-26-openjdk \
  java-26-openjdk-devel
ENV JAVA26_HOME=/usr/lib/jvm/java-26

## Use this when the java-26-openjdk* packages don't yet exist.
# # RUN curl --silent -o jdk-26_linux-x64_bin.tar.gz https://download.oracle.com/java/26/latest/jdk-26_linux-x64_bin.tar.gz \
# RUN curl --silent -o jdk-26_linux-x64_bin.tar.gz https://download.java.net/java/GA/jdk26/bd75d5f9689641da8e1daabeccb5528b/36/GPL/openjdk-26_linux-x64_bin.tar.gz \
# && tar xzf jdk-26_linux-x64_bin.tar.gz
# ENV PATH="/jdk-26/bin:/root/.local/bin:/root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
# ENV JAVA26_HOME=/jdk-26
# RUN chmod og+rx /root \
# && chmod og+r /root/*

RUN dnf -q -y upgrade && dnf -q -y install \
  ctags \
  devscripts-checkbashisms \
  gcc-c++ \
  graphviz \
  netpbm \
  netpbm-progs \
  python3 \
  python3-distutils-extra \
  ShellCheck \
  texlive \
  yamllint

## 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.6.1-bin.zip \
&& unzip -q -d /opt/gradle gradle-9.6.1-bin.zip \
&& rm gradle-9.6.1-bin.zip
ENV PATH=$PATH:/opt/gradle/gradle-9.6.1/bin

# Alternately, run: dnf --enablerepo=crb install PACKAGENAME
RUN dnf config-manager --set-enabled crb \
&& dnf -y install \
  dnf-plugins-core \
  texinfo \
  texinfo-tex

# 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).
RUN echo "installing uv" \
&& wget -qO- https://astral.sh/uv/install.sh | sh \
&& find /root -exec chmod +r {} \; \
&& find /root -type d -exec chmod +x {} \; \
&& find /root/.local/bin -type f -exec chmod +x {} \;
ENV PATH=/root/.local/bin:$PATH

# Clean up.
RUN dnf -q clean all
