rewrite-migrate-java
rewrite-migrate-java copied to clipboard
Upgrade Docker base images when upgrading Java
This came up in Slack; when upgrading to newer versions of Java a common step is to also replace the Docker base images in the FROM line in Dockerfiles. Pending a proper dockerfile parser through language tools, we can for now use the FindAndReplace text replacement recipe that was developed for this purpose originally.
For now we can do substitutions on common base images such as those for OpenJDK, Maven, Gradle, ..., which typically have the version number in the tag.
Care should be taken not to do any replacements when docker image digests are present; perhaps a marker could be added in those cases, to note the possible new version for now.
When implemented initially as yaml recipes tagged onto for instance java-version-17.yml it ought to be easy to swap that out for a Docker parser based recipe should that become available in the future.
As an example, we've seen the following used already; initially we can add a few more of these for the common use cases above.
- org.openrewrite.text.FindAndReplace:
find: FROM openjdk:15-.*
replace: FROM eclipse-temurin:17-jre-jammy
regex: true
fileMatcher: Dockerfile