From a220b9bf9158f1e48cfbe0987b5142a7916df3bf Mon Sep 17 00:00:00 2001 From: "Michael C. Thompson" Date: Mon, 12 Nov 2018 15:27:29 +0100 Subject: [PATCH] Add a very hacky version of dockerizerJVM property --- .../boost/docker/DockerBuildMojo.java | 35 ++++++++++++++++--- .../boost/docker/dockerizer/Dockerizer.java | 4 ++- .../spring/DockerizeLibertySpringBootJar.java | 5 +-- .../spring/DockerizeSpringBootClasspath.java | 6 ++-- .../spring/DockerizeSpringBootJar.java | 6 ++-- .../dockerizer/spring/SpringDockerizer.java | 4 +-- 6 files changed, 45 insertions(+), 15 deletions(-) diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/DockerBuildMojo.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/DockerBuildMojo.java index 34b254e6..975a4668 100644 --- a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/DockerBuildMojo.java +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/DockerBuildMojo.java @@ -101,11 +101,19 @@ public class DockerBuildMojo extends AbstractDockerMojo { private Map buildArgs; /** - * Sets the type of docker build to run. + * Determine the type of Dockerfile to create.
+ * Supported values are: liberty, jar, classpath */ @Parameter(property = "dockerizer", defaultValue = "liberty") private String dockerizer; + /** + * Determine the JVM to use in the FROM line of Dockerfile to create.
+ * Supported values are: openj9, hotspot, graalvm + */ + @Parameter(property = "dockerizerJVM", defaultValue = "openj9") + private String dockerizerJVM; + @Override protected void execute(DockerClient dockerClient) throws MojoExecutionException, MojoFailureException { try { @@ -174,19 +182,38 @@ private File getAppArchive() throws BoostException { } private Dockerizer getDockerizer(MavenProject project, File appArchive, Log log) { + + // TODO: This is a bad ugly hack, need a real implementation! + // Things to be done: + // 1. Probably create an abstraction for the JVM type? + // 2. Definitely support more than just Java 8 + String jvmLevel = project.getProperties().getProperty("java.version", "1.8"); + if ("1.8".equalsIgnoreCase(jvmLevel)) { + log.warn("Right now, boost dockerizer only supports Java 8"); + } + + // Set default to be openj9 + String fromJVM = "FROM adoptopenjdk/openjdk8-openj9"; + if ("graalvm".equalsIgnoreCase(dockerizerJVM)) { + fromJVM = "FROM oracle/graalvm-ce:1.0.0-rc9"; + } + if ("hotspot".equalsIgnoreCase(dockerizerJVM)) { + fromJVM = "FROM openjdk:8-jdk-alpine"; + } + // TODO: Needed future enhancements: // 1. Is it Spring or something else? sense with MavenProjectUtil.findSpringBootVersion(project); // 2. Use OpenJ9 or HotSpot? sense with property boost.docker.jvm if ("jar".equalsIgnoreCase(dockerizer)) { - return new DockerizeSpringBootJar(project, appArchive, log); + return new DockerizeSpringBootJar(project, appArchive, log, fromJVM); } if ("classpath".equalsIgnoreCase(dockerizer)) { - return new DockerizeSpringBootClasspath(project, appArchive, log); + return new DockerizeSpringBootClasspath(project, appArchive, log, fromJVM); } // TODO: Maybe don't make the Spring Boot dockerizer default after EE stuff is added // The current property values of 'jar', 'classpath' and 'liberty' are intentionally // generic so that they can be applied irrespective of the project type (Spring vs EE) - return new DockerizeLibertySpringBootJar(project, appArchive, log); + return new DockerizeLibertySpringBootJar(project, appArchive, log, fromJVM); } /** diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/Dockerizer.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/Dockerizer.java index 1eb138a1..8c1faa1b 100644 --- a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/Dockerizer.java +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/Dockerizer.java @@ -37,13 +37,15 @@ public abstract class Dockerizer { protected final File outputDirectory; protected final File appArchive; protected final Log log; + protected final String fromJVM; - public Dockerizer(MavenProject project, File appArchive, Log log) { + public Dockerizer(MavenProject project, File appArchive, Log log, String fromJVM) { this.project = project; this.projectDirectory = project.getBasedir(); this.outputDirectory = new File(project.getBuild().getDirectory()); this.appArchive = appArchive; this.log = log; + this.fromJVM = fromJVM; } /** diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/spring/DockerizeLibertySpringBootJar.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/spring/DockerizeLibertySpringBootJar.java index 7da88c47..bd35d3dc 100644 --- a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/spring/DockerizeLibertySpringBootJar.java +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/spring/DockerizeLibertySpringBootJar.java @@ -32,8 +32,9 @@ public class DockerizeLibertySpringBootJar extends SpringDockerizer { private static final String COPY = "COPY "; private static final String RUN = "RUN "; - public DockerizeLibertySpringBootJar(MavenProject project, File appArchive, Log log) { - super(project, appArchive, log); + // This does not actually use fromJVM right now + public DockerizeLibertySpringBootJar(MavenProject project, File appArchive, Log log, String fromJVM) { + super(project, appArchive, log, fromJVM); } public Map getBuildArgs() { diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/spring/DockerizeSpringBootClasspath.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/spring/DockerizeSpringBootClasspath.java index a3358cf1..b20a758b 100644 --- a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/spring/DockerizeSpringBootClasspath.java +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/spring/DockerizeSpringBootClasspath.java @@ -22,8 +22,8 @@ public class DockerizeSpringBootClasspath extends SpringDockerizer { - public DockerizeSpringBootClasspath(MavenProject project, File appArchive, Log log) { - super(project, appArchive, log); + public DockerizeSpringBootClasspath(MavenProject project, File appArchive, Log log, String fromJVM) { + super(project, appArchive, log, fromJVM); } public Map getBuildArgs() { @@ -35,7 +35,7 @@ public Map getBuildArgs() { public List getDockerfileLines() throws MojoExecutionException { ArrayList lines = new ArrayList<>(); lines.add(BOOST_GEN); - lines.add("FROM adoptopenjdk/openjdk8-openj9"); + lines.add(fromJVM); lines.add("VOLUME /tmp"); lines.add("ARG DEPENDENCY=target/dependency"); lines.add("COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib"); diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/spring/DockerizeSpringBootJar.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/spring/DockerizeSpringBootJar.java index 79e6a78f..5d0ee992 100644 --- a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/spring/DockerizeSpringBootJar.java +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/spring/DockerizeSpringBootJar.java @@ -22,8 +22,8 @@ public class DockerizeSpringBootJar extends SpringDockerizer { - public DockerizeSpringBootJar(MavenProject project, File appArchive, Log log) { - super(project, appArchive, log); + public DockerizeSpringBootJar(MavenProject project, File appArchive, Log log, String fromJVM) { + super(project, appArchive, log, fromJVM); } public Map getBuildArgs() { @@ -35,7 +35,7 @@ public Map getBuildArgs() { public List getDockerfileLines() throws MojoExecutionException { ArrayList lines = new ArrayList<>(); lines.add(BOOST_GEN); - lines.add("FROM adoptopenjdk/openjdk8-openj9"); + lines.add(fromJVM); lines.add("VOLUME /tmp"); lines.add("ARG JAR_FILE"); lines.add("COPY ${JAR_FILE} app.jar"); diff --git a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/spring/SpringDockerizer.java b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/spring/SpringDockerizer.java index 8e7d3cea..f89d0a92 100644 --- a/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/spring/SpringDockerizer.java +++ b/boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/spring/SpringDockerizer.java @@ -32,8 +32,8 @@ public abstract class SpringDockerizer extends Dockerizer { protected final String springBootVersion = MavenProjectUtil.findSpringBootVersion(project); - public SpringDockerizer(MavenProject project, File appArchive, Log log) { - super(project, appArchive, log); + public SpringDockerizer(MavenProject project, File appArchive, Log log, String fromJVM) { + super(project, appArchive, log, fromJVM); } /**