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

Commit 6db1e20

Browse files
committed
Add a very hacky version of dockerizerJVM property (manual rebase to refactored master)
1 parent d8a1753 commit 6db1e20

File tree

8 files changed

+52
-23
lines changed

8 files changed

+52
-23
lines changed

boost-common/src/main/java/io/openliberty/boost/common/docker/DockerBuildI.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ public abstract interface DockerBuildI extends AbstractDockerI {
3636

3737
// Default methods
3838

39-
default public void dockerBuild(String dockerizer, DockerClient dockerClient, File projectDirectory,
40-
File outputDirectory, String springBootVersion, boolean pullNewerImage, boolean noCache,
39+
default public void dockerBuild(String dockerizer, String dockerizerJVM, DockerClient dockerClient, File projectDirectory,
40+
File outputDirectory, String javaVersion, String springBootVersion, boolean pullNewerImage, boolean noCache,
4141
Map<String, String> buildArgs, String repository, String tag, DockerParameters params, BoostLoggerI log)
4242
throws BoostException {
4343
try {
4444
File appArchive = getAppArchive();
4545

4646
// Create a Dockerfile for the application
47-
SpringDockerizer springDockerizer = getDockerizer(dockerizer, projectDirectory, outputDirectory, appArchive,
48-
springBootVersion, params, log);
47+
SpringDockerizer springDockerizer = getDockerizer(dockerizer, dockerizerJVM, projectDirectory, outputDirectory, appArchive,
48+
javaVersion, springBootVersion, params, log);
4949
springDockerizer.createDockerFile();
5050
springDockerizer.createDockerIgnore();
5151

@@ -56,20 +56,37 @@ default public void dockerBuild(String dockerizer, DockerClient dockerClient, Fi
5656
}
5757
}
5858

59-
default public SpringDockerizer getDockerizer(String dockerizer, File projectDirectory, File outputDirectory,
60-
File appArchive, String springBootVersion, DockerParameters params, BoostLoggerI log) {
59+
default public SpringDockerizer getDockerizer(String dockerizer, String dockerizerJVM, File projectDirectory, File outputDirectory,
60+
File appArchive, String javaVersion, String springBootVersion, DockerParameters params, BoostLoggerI log) {
61+
62+
// TODO: This is a bad ugly hack, need a real implementation!
63+
// Things to be done:
64+
// 1. Probably create an abstraction for the JVM type?
65+
// 2. Definitely support more than just Java 8
66+
if ("1.8".equalsIgnoreCase(javaVersion)) {
67+
log.warn("Right now, boost dockerizer only supports Java 8");
68+
}
69+
70+
// Set default to be openj9
71+
String fromJVM = "FROM adoptopenjdk/openjdk8-openj9";
72+
if ("graalvm".equalsIgnoreCase(dockerizerJVM)) {
73+
fromJVM = "FROM oracle/graalvm-ce:1.0.0-rc9";
74+
}
75+
if ("hotspot".equalsIgnoreCase(dockerizerJVM)) {
76+
fromJVM = "FROM openjdk:8-jdk-alpine";
77+
}
6178

6279
// TODO: Needed future enhancements:
6380
// 1. Is it Spring or something else? sense with
6481
// MavenProjectUtil.findSpringBootVersion(project);
6582
// 2. Use OpenJ9 or HotSpot? sense with property boost.docker.jvm
6683
if ("jar".equalsIgnoreCase(dockerizer)) {
6784
return new DockerizeSpringBootJar(projectDirectory, outputDirectory, appArchive, springBootVersion, params,
68-
log);
85+
log, fromJVM);
6986
}
7087
if ("classpath".equalsIgnoreCase(dockerizer)) {
7188
return new DockerizeSpringBootClasspath(projectDirectory, outputDirectory, appArchive, springBootVersion,
72-
params, log);
89+
params, log, fromJVM);
7390
}
7491
// TODO: Maybe don't make the Spring Boot dockerizer default after EE stuff is
7592
// added
@@ -78,7 +95,7 @@ default public SpringDockerizer getDockerizer(String dockerizer, File projectDir
7895
// generic so that they can be applied irrespective of the project type (Spring
7996
// vs EE)
8097
return new DockerizeLibertySpringBootJar(projectDirectory, outputDirectory, appArchive, springBootVersion,
81-
params, log);
98+
params, log, fromJVM);
8299
}
83100

84101
/**

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ public abstract class Dockerizer {
3535
protected final File outputDirectory;
3636
protected final File appArchive;
3737
protected final BoostLoggerI log;
38+
protected final String fromJVM;
3839

39-
public Dockerizer(File projectDirectory, File outputDirectory, File appArchive, BoostLoggerI log) {
40+
public Dockerizer(File projectDirectory, File outputDirectory, File appArchive, BoostLoggerI log, String fromJVM) {
4041
this.projectDirectory = projectDirectory;
4142
this.outputDirectory = outputDirectory;
4243
this.appArchive = appArchive;
4344
this.log = log;
45+
this.fromJVM = fromJVM;
4446
}
4547

4648
/**

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

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

35+
// This does not actually use fromJVM right now
3536
public DockerizeLibertySpringBootJar(File projectDirectory, File outputDirectory, File appArchive,
36-
String springBootVersion, DockerParameters params, BoostLoggerI log) {
37-
super(projectDirectory, outputDirectory, appArchive, springBootVersion, params, log);
37+
String springBootVersion, DockerParameters params, BoostLoggerI log, String fromJVM) {
38+
super(projectDirectory, outputDirectory, appArchive, springBootVersion, params, log, fromJVM);
3839
}
3940

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

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
public class DockerizeSpringBootClasspath extends SpringDockerizer {
2424

2525
public DockerizeSpringBootClasspath(File projectDirectory, File outputDirectory, File appArchive,
26-
String springBootVersion, DockerParameters params, BoostLoggerI log) {
27-
super(projectDirectory, outputDirectory, appArchive, springBootVersion, params, log);
26+
String springBootVersion, DockerParameters params, BoostLoggerI log, String fromJVM) {
27+
super(projectDirectory, outputDirectory, appArchive, springBootVersion, params, log, fromJVM);
2828
}
2929

3030
public Map<String, String> getBuildArgs() {
@@ -36,7 +36,7 @@ public Map<String, String> getBuildArgs() {
3636
public List<String> getDockerfileLines() throws BoostException {
3737
ArrayList<String> lines = new ArrayList<>();
3838
lines.add(BOOST_GEN);
39-
lines.add("FROM adoptopenjdk/openjdk8-openj9");
39+
lines.add(fromJVM);
4040
lines.add("VOLUME /tmp");
4141
lines.add("ARG DEPENDENCY=" + params.getDependencyFolder());
4242
lines.add("COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib");

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
public class DockerizeSpringBootJar extends SpringDockerizer {
2424

2525
public DockerizeSpringBootJar(File projectDirectory, File outputDirectory, File appArchive,
26-
String springBootVersion, DockerParameters params, BoostLoggerI log) {
27-
super(projectDirectory, outputDirectory, appArchive, springBootVersion, params, log);
26+
String springBootVersion, DockerParameters params, BoostLoggerI log, String fromJVM) {
27+
super(projectDirectory, outputDirectory, appArchive, springBootVersion, params, log, fromJVM);
2828
}
2929

3030
public Map<String, String> getBuildArgs() {
@@ -36,7 +36,7 @@ public Map<String, String> getBuildArgs() {
3636
public List<String> getDockerfileLines() throws BoostException {
3737
ArrayList<String> lines = new ArrayList<>();
3838
lines.add(BOOST_GEN);
39-
lines.add("FROM adoptopenjdk/openjdk8-openj9");
39+
lines.add(fromJVM);
4040
lines.add("VOLUME /tmp");
4141
lines.add("ARG JAR_FILE");
4242
lines.add("COPY ${JAR_FILE} app.jar");

boost-common/src/main/java/io/openliberty/boost/common/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
public final String SPRING_BOOT_VERSION;
3333
public final DockerParameters params;
3434

35-
public SpringDockerizer(File projectDirectory, File outputDirectory, File appArchive, String springBootVersion, DockerParameters params, BoostLoggerI log) {
36-
super(projectDirectory, outputDirectory, appArchive, log);
35+
public SpringDockerizer(File projectDirectory, File outputDirectory, File appArchive, String springBootVersion, DockerParameters params, BoostLoggerI log, String fromJVM) {
36+
super(projectDirectory, outputDirectory, appArchive, log, fromJVM);
3737
this.SPRING_BOOT_VERSION = springBootVersion;
3838
this.params = params;
3939
}

boost-maven/boost-maven-plugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<dependency>
2323
<groupId>io.openliberty.boost</groupId>
2424
<artifactId>boost-common</artifactId>
25-
<version>0.1.2</version>
25+
<version>0.1.3-SNAPSHOT</version>
2626
</dependency>
2727
<dependency>
2828
<groupId>net.wasdev.wlp.maven.plugins</groupId>

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,27 @@ public class DockerBuildMojo extends AbstractDockerMojo implements DockerBuildI
9090
private Map<String, String> buildArgs;
9191

9292
/**
93-
* Sets the type of docker build to run.
93+
* Determine the type of Dockerfile to create.<br>
94+
* Supported values are: liberty, jar, classpath
9495
*/
9596
@Parameter(property = "dockerizer", defaultValue = "liberty")
9697
private String dockerizer;
9798

99+
/**
100+
* Determine the JVM to use in the Dockerfile to create.<br>
101+
* Supported values are: openj9, hotspot, graalvm
102+
*/
103+
@Parameter(property = "dockerizerJVM", defaultValue = "openj9")
104+
private String dockerizerJVM;
105+
98106
@Override
99107
public void execute(DockerClient dockerClient) throws BoostException {
100108
File projectDirectory = project.getBasedir();
101109
File outputDirectory = new File(project.getBuild().getDirectory());
110+
String javaVersion = project.getProperties().getProperty("java.version", "1.8");
102111
String springBootVersion = MavenProjectUtil.findSpringBootVersion(project);
103112
DockerParameters params = new DockerParameters("target/dependency");
104-
dockerBuild(dockerizer, dockerClient, projectDirectory, outputDirectory, springBootVersion, pullNewerImage,
113+
dockerBuild(dockerizer, dockerizerJVM, dockerClient, projectDirectory, outputDirectory, javaVersion, springBootVersion, pullNewerImage,
105114
noCache, buildArgs, repository, tag, params, BoostLogger.getInstance());
106115
}
107116

0 commit comments

Comments
 (0)