# Create a Docker image that is ready to run the full Checker Framework tests,
# including building the manual and Javadoc, using JDK 23.
# (This is OpenJDK, not Oracle JDK.  There are different instructions for
# installing a LTS release of Java.)
# To convert this file to use a newer JDK, search (from the top level of the
# Checker Framework and Annotation Tools repositories) for: (java|jdk).?23\b

# "ubuntu" is the latest LTS release.  "ubuntu:rolling" is the latest release.
# Both might lag behind; as of 2024-11-16, ubuntu:rolling was still 24.04 rather than 24.10.
# See releases at https://hub.docker.com/_/ubuntu for available images.
# See https://packages.ubuntu.com/search?suite=default&section=all&arch=any&keywords=openjdk-23-jdk&searchon=names
# to see what Ubuntu versions support a particular OpenJDK version.
FROM ubuntu:oracular
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" and "apt cleanup" in the same RUN command.
#  * Do not run "apt-get upgrade"; instead get upstream to update.

RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get -qqy update \
&& apt-get install -y locales \
&& rm -rf /var/lib/apt/lists/* \
&& locale-gen "en_US.UTF-8"
ENV LANG=en_US.UTF-8 \
    LANGUAGE=en_US:en \
    LC_ALL=en_US.UTF-8

RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get -qqy update \
&& apt-get -y install aptitude \
&& aptitude -y install \
  apt-utils

# ca-certificates-java is a dependency of openjdk-20-jdk, but the installation
# process seems to fail sometimes when only openjdk-20-jdk is specified.
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get -qqy update \
&& aptitude -y install \
  ca-certificates-java \
&& aptitude -y install \
  openjdk-17-jdk \
  openjdk-23-jdk

# Known good combinations of JTReg and the JDK appear at https://builds.shipilev.net/jtreg/ .

RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get -qqy update \
&& aptitude -y install \
  ant \
  cpp \
  git \
  jq \
  libcurl3-gnutls \
  make \
  maven \
  python3-requests \
  python3-setuptools \
  unzip \
  wget \
&& aptitude -y install \
  jtreg7

# Maven 3.8.7 is the default on Ubuntu 23.04, so the below is not needed.
# (Don't try to use a variable here for the Maven version.)
# RUN export DEBIAN_FRONTEND=noninteractive \
# && wget https://mirrors.sonic.net/apache/maven/maven-3/3.9.5/binaries/apache-maven-3.9.5-bin.tar.gz \
# && tar xzvf apache-maven-3.9.5-bin.tar.gz
# ENV PATH="/apache-maven-3.9.5/bin:$PATH"

# Bug fix to make jtreg runnable: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=754942;msg=2
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get -qqy update \
&& aptitude -y install \
  default-jre-headless

RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get -qqy update \
&& aptitude -y install \
  autoconf \
  devscripts \
  dia \
  hevea \
  imagemagick \
  junit \
  latexmk \
  librsvg2-bin \
  libasound2-dev libcups2-dev libfontconfig1-dev \
  libx11-dev libxext-dev libxrender-dev libxrandr-dev libxtst-dev libxt-dev \
  pdf2svg \
  rsync \
  shellcheck \
  texlive-font-utils \
  texlive-fonts-recommended \
  texlive-latex-base \
  texlive-latex-extra \
  texlive-latex-recommended

# `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 export DEBIAN_FRONTEND=noninteractive \
&& apt-get -qqy update \
&& aptitude -y install \
  pipx \
&& PIPX_HOME=/opt/pipx PIPX_BIN_DIR=/usr/local/bin pipx install black \
&& PIPX_HOME=/opt/pipx PIPX_BIN_DIR=/usr/local/bin pipx install flake8 \
&& PIPX_HOME=/opt/pipx PIPX_BIN_DIR=/usr/local/bin pipx install html5validator

RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
