Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Commit a220b9b

Browse files
committed
Add a very hacky version of dockerizerJVM property
1 parent ffa72a1 commit a220b9b

File tree

6 files changed

+45
-15
lines changed

6 files changed

+45
-15
lines changed

boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/DockerBuildMojo.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,19 @@ public class DockerBuildMojo extends AbstractDockerMojo {
101101
private Map<String, String> buildArgs;
102102

103103
/**
104-
* Sets the type of docker build to run.
104+
* Determine the type of Dockerfile to create.<br>
105+
* Supported values are: liberty, jar, classpath
105106
*/
106107
@Parameter(property = "dockerizer", defaultValue = "liberty")
107108
private String dockerizer;
108109

110+
/**
111+
* Determine the JVM to use in the FROM line of Dockerfile to create.<br>
112+
* Supported values are: openj9, hotspot, graalvm
113+
*/
114+
@Parameter(property = "dockerizerJVM", defaultValue = "openj9")
115+
private String dockerizerJVM;
116+
109117
@Override
110118
protected void execute(DockerClient dockerClient) throws MojoExecutionException, MojoFailureException {
111119
try {
@@ -174,19 +182,38 @@ private File getAppArchive() throws BoostException {
174182
}
175183

176184
private Dockerizer getDockerizer(MavenProject project, File appArchive, Log log) {
185+
186+
// TODO: This is a bad ugly hack, need a real implementation!
187+
// Things to be done:
188+
// 1. Probably create an abstraction for the JVM type?
189+
// 2. Definitely support more than just Java 8
190+
String jvmLevel = project.getProperties().getProperty("java.version", "1.8");
191+
if ("1.8".equalsIgnoreCase(jvmLevel)) {
192+
log.warn("Right now, boost dockerizer only supports Java 8");
193+
}
194+
195+
// Set default to be openj9
196+
String fromJVM = "FROM adoptopenjdk/openjdk8-openj9";
197+
if ("graalvm".equalsIgnoreCase(dockerizerJVM)) {
198+
fromJVM = "FROM oracle/graalvm-ce:1.0.0-rc9";
199+
}
200+
if ("hotspot".equalsIgnoreCase(dockerizerJVM)) {
201+
fromJVM = "FROM openjdk:8-jdk-alpine";
202+
}
203+
177204
// TODO: Needed future enhancements:
178205
// 1. Is it Spring or something else? sense with MavenProjectUtil.findSpringBootVersion(project);
179206
// 2. Use OpenJ9 or HotSpot? sense with property boost.docker.jvm
180207
if ("jar".equalsIgnoreCase(dockerizer)) {
181-
return new DockerizeSpringBootJar(project, appArchive, log);
208+
return new DockerizeSpringBootJar(project, appArchive, log, fromJVM);
182209
}
183210
if ("classpath".equalsIgnoreCase(dockerizer)) {
184-
return new DockerizeSpringBootClasspath(project, appArchive, log);
211+
return new DockerizeSpringBootClasspath(project, appArchive, log, fromJVM);
185212
}
186213
// TODO: Maybe don't make the Spring Boot dockerizer default after EE stuff is added
187214
// The current property values of 'jar', 'classpath' and 'liberty' are intentionally
188215
// generic so that they can be applied irrespective of the project type (Spring vs EE)
189-
return new DockerizeLibertySpringBootJar(project, appArchive, log);
216+
return new DockerizeLibertySpringBootJar(project, appArchive, log, fromJVM);
190217
}
191218

192219
/**

boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/Dockerizer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ public abstract class Dockerizer {
3737
protected final File outputDirectory;
3838
protected final File appArchive;
3939
protected final Log log;
40+
protected final String fromJVM;
4041

41-
public Dockerizer(MavenProject project, File appArchive, Log log) {
42+
public Dockerizer(MavenProject project, File appArchive, Log log, String fromJVM) {
4243
this.project = project;
4344
this.projectDirectory = project.getBasedir();
4445
this.outputDirectory = new File(project.getBuild().getDirectory());
4546
this.appArchive = appArchive;
4647
this.log = log;
48+
this.fromJVM = fromJVM;
4749
}
4850

4951
/**

boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/spring/DockerizeLibertySpringBootJar.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ public class DockerizeLibertySpringBootJar extends SpringDockerizer {
3232
private static final String COPY = "COPY ";
3333
private static final String RUN = "RUN ";
3434

35-
public DockerizeLibertySpringBootJar(MavenProject project, File appArchive, Log log) {
36-
super(project, appArchive, log);
35+
// This does not actually use fromJVM right now
36+
public DockerizeLibertySpringBootJar(MavenProject project, File appArchive, Log log, String fromJVM) {
37+
super(project, appArchive, log, fromJVM);
3738
}
3839

3940
public Map<String, String> getBuildArgs() {

boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/spring/DockerizeSpringBootClasspath.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
public class DockerizeSpringBootClasspath extends SpringDockerizer {
2424

25-
public DockerizeSpringBootClasspath(MavenProject project, File appArchive, Log log) {
26-
super(project, appArchive, log);
25+
public DockerizeSpringBootClasspath(MavenProject project, File appArchive, Log log, String fromJVM) {
26+
super(project, appArchive, log, fromJVM);
2727
}
2828

2929
public Map<String, String> getBuildArgs() {
@@ -35,7 +35,7 @@ public Map<String, String> getBuildArgs() {
3535
public List<String> getDockerfileLines() throws MojoExecutionException {
3636
ArrayList<String> lines = new ArrayList<>();
3737
lines.add(BOOST_GEN);
38-
lines.add("FROM adoptopenjdk/openjdk8-openj9");
38+
lines.add(fromJVM);
3939
lines.add("VOLUME /tmp");
4040
lines.add("ARG DEPENDENCY=target/dependency");
4141
lines.add("COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib");

boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/spring/DockerizeSpringBootJar.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
public class DockerizeSpringBootJar extends SpringDockerizer {
2424

25-
public DockerizeSpringBootJar(MavenProject project, File appArchive, Log log) {
26-
super(project, appArchive, log);
25+
public DockerizeSpringBootJar(MavenProject project, File appArchive, Log log, String fromJVM) {
26+
super(project, appArchive, log, fromJVM);
2727
}
2828

2929
public Map<String, String> getBuildArgs() {
@@ -35,7 +35,7 @@ public Map<String, String> getBuildArgs() {
3535
public List<String> getDockerfileLines() throws MojoExecutionException {
3636
ArrayList<String> lines = new ArrayList<>();
3737
lines.add(BOOST_GEN);
38-
lines.add("FROM adoptopenjdk/openjdk8-openj9");
38+
lines.add(fromJVM);
3939
lines.add("VOLUME /tmp");
4040
lines.add("ARG JAR_FILE");
4141
lines.add("COPY ${JAR_FILE} app.jar");

boost-maven/boost-maven-plugin/src/main/java/io/openliberty/boost/docker/dockerizer/spring/SpringDockerizer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public abstract class SpringDockerizer extends Dockerizer {
3232

3333
protected final String springBootVersion = MavenProjectUtil.findSpringBootVersion(project);
3434

35-
public SpringDockerizer(MavenProject project, File appArchive, Log log) {
36-
super(project, appArchive, log);
35+
public SpringDockerizer(MavenProject project, File appArchive, Log log, String fromJVM) {
36+
super(project, appArchive, log, fromJVM);
3737
}
3838

3939
/**

0 commit comments

Comments
 (0)