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

Commit

Permalink
Add a very hacky version of dockerizerJVM property
Browse files Browse the repository at this point in the history
  • Loading branch information
barecode committed Nov 12, 2018
1 parent ffa72a1 commit a220b9b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,19 @@ public class DockerBuildMojo extends AbstractDockerMojo {
private Map<String, String> buildArgs;

/**
* Sets the type of docker build to run.
* Determine the type of Dockerfile to create.<br>
* 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.<br>
* Supported values are: openj9, hotspot, graalvm
*/
@Parameter(property = "dockerizerJVM", defaultValue = "openj9")
private String dockerizerJVM;

@Override
protected void execute(DockerClient dockerClient) throws MojoExecutionException, MojoFailureException {
try {
Expand Down Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> getBuildArgs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> getBuildArgs() {
Expand All @@ -35,7 +35,7 @@ public Map<String, String> getBuildArgs() {
public List<String> getDockerfileLines() throws MojoExecutionException {
ArrayList<String> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> getBuildArgs() {
Expand All @@ -35,7 +35,7 @@ public Map<String, String> getBuildArgs() {
public List<String> getDockerfileLines() throws MojoExecutionException {
ArrayList<String> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit a220b9b

Please sign in to comment.