This directory contains Dockerfiles to create new Docker images for
running tests reproducibly.

The rest of this file explains how to build new Docker images.


Preliminaries:

  # Finish docker setup if necessary.
  sudo usermod -aG docker $(whoami)
  # Then log out and back in.

  # Obtain Docker credentials.
  # (This is only necessary once per machine; credentials are cached.)
  docker login


Cleanup:

After running any of the below, consider deleting the docker containers,
which can take up a lot of disk space.

To stop and remove/delete *all* docker containers:
  docker stop $(docker ps -a -q)
  docker rm -vf $(docker ps -aq)
To remove all images:
  docker rmi -f $(docker images -aq)
To remove most everything, including build cache objects:
  docker system prune -a -f


Create the Docker image:

# Alias to create the Docker image, in an empty directory, and upload to Docker Hub.
DOCKERTESTING=""
# When DOCKERTESTING is enabled, also edit any file containing the string "mdernst/".
# DOCKERTESTING="-testing"
# Arguments: project, OS, JDK version
function create_upload_docker_image {
  DPROJECT=$1
  OS=$2
  JDKVER=$3
  IMAGENAME=$DPROJECT-$OS-$JDKVER$DOCKERTESTING
  DOCKERIMAGE="mdernst/$IMAGENAME"
  DOCKERDIR=dockerdir-$IMAGENAME
  (rm -rf $DOCKERDIR && \
  mkdir -p $DOCKERDIR && \
  cd $DOCKERDIR && \
  \cp -pf ../Dockerfile-$OS-$JDKVER Dockerfile && \
  docker -l warn build -t $DOCKERIMAGE . && \
  docker -l warn push $DOCKERIMAGE && \
  cd .. &&
  rm -rf $DOCKERDIR && \
  echo "***** Success in $DOCKERIMAGE *****") || \
  (echo "*****"; echo "*****"; echo "FAILURE in $DOCKERIMAGE"; echo "*****"; echo "*****"; exit 1)
}


## Run sequentially.
(create_upload_docker_image cf ubuntu jdk11 && \
create_upload_docker_image cf ubuntu jdk11-plus) && \
(create_upload_docker_image cf ubuntu jdk17 && \
create_upload_docker_image cf ubuntu jdk17-plus) && \
(create_upload_docker_image cf ubuntu jdk21 && \
create_upload_docker_image cf ubuntu jdk21-plus) && \
(create_upload_docker_image cf ubuntu jdk25 && \
create_upload_docker_image cf ubuntu jdk25-plus) && \
git push && \
echo "success"


## This version might be faster with an SSD.  It might not be with a spinning disk.
# These first few need not be uploaded, just created and locally cached.
# Don't run this under Emacs.
(create_upload_docker_image cf ubuntu jdkbase && \
create_upload_docker_image cf ubuntu jdkplus) &
(create_upload_docker_image cf ubunturolling jdkbase && \
create_upload_docker_image cf ubunturolling jdkplus) &
sleep 1
if wait ; then
  (create_upload_docker_image cf ubuntu jdk11 && \
  create_upload_docker_image cf ubuntu jdk11-plus) &
  (create_upload_docker_image cf ubuntu jdk17 && \
  create_upload_docker_image cf ubuntu jdk17-plus) &
  (create_upload_docker_image cf ubuntu jdk21 && \
  create_upload_docker_image cf ubuntu jdk21-plus) &
  (create_upload_docker_image cf ubuntu jdk25 && \
  create_upload_docker_image cf ubuntu jdk25-plus) &
  sleep 1
  wait && \
  git push && \
  echo "success"
else
  echo "failure"
  false
fi



Note: when updating to a newer version of the JDK, it is necessary to
update the Gradle version to one that supports that JDK, in projects
such as wpi-many-tests-bcel-util.
