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 (manual rebase to …
Browse files Browse the repository at this point in the history
…refactored master)
  • Loading branch information
barecode committed Nov 14, 2018
1 parent d8a1753 commit 6db1e20
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ public abstract interface DockerBuildI extends AbstractDockerI {

// Default methods

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

// Create a Dockerfile for the application
SpringDockerizer springDockerizer = getDockerizer(dockerizer, projectDirectory, outputDirectory, appArchive,
springBootVersion, params, log);
SpringDockerizer springDockerizer = getDockerizer(dockerizer, dockerizerJVM, projectDirectory, outputDirectory, appArchive,
javaVersion, springBootVersion, params, log);
springDockerizer.createDockerFile();
springDockerizer.createDockerIgnore();

Expand All @@ -56,20 +56,37 @@ default public void dockerBuild(String dockerizer, DockerClient dockerClient, Fi
}
}

default public SpringDockerizer getDockerizer(String dockerizer, File projectDirectory, File outputDirectory,
File appArchive, String springBootVersion, DockerParameters params, BoostLoggerI log) {
default public SpringDockerizer getDockerizer(String dockerizer, String dockerizerJVM, File projectDirectory, File outputDirectory,
File appArchive, String javaVersion, String springBootVersion, DockerParameters params, BoostLoggerI 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
if ("1.8".equalsIgnoreCase(javaVersion)) {
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(projectDirectory, outputDirectory, appArchive, springBootVersion, params,
log);
log, fromJVM);
}
if ("classpath".equalsIgnoreCase(dockerizer)) {
return new DockerizeSpringBootClasspath(projectDirectory, outputDirectory, appArchive, springBootVersion,
params, log);
params, log, fromJVM);
}
// TODO: Maybe don't make the Spring Boot dockerizer default after EE stuff is
// added
Expand All @@ -78,7 +95,7 @@ default public SpringDockerizer getDockerizer(String dockerizer, File projectDir
// generic so that they can be applied irrespective of the project type (Spring
// vs EE)
return new DockerizeLibertySpringBootJar(projectDirectory, outputDirectory, appArchive, springBootVersion,
params, log);
params, log, fromJVM);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ public abstract class Dockerizer {
protected final File outputDirectory;
protected final File appArchive;
protected final BoostLoggerI log;
protected final String fromJVM;

public Dockerizer(File projectDirectory, File outputDirectory, File appArchive, BoostLoggerI log) {
public Dockerizer(File projectDirectory, File outputDirectory, File appArchive, BoostLoggerI log, String fromJVM) {
this.projectDirectory = projectDirectory;
this.outputDirectory = outputDirectory;
this.appArchive = appArchive;
this.log = log;
this.fromJVM = fromJVM;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ public class DockerizeLibertySpringBootJar extends SpringDockerizer {
private static final String COPY = "COPY ";
private static final String RUN = "RUN ";

// This does not actually use fromJVM right now
public DockerizeLibertySpringBootJar(File projectDirectory, File outputDirectory, File appArchive,
String springBootVersion, DockerParameters params, BoostLoggerI log) {
super(projectDirectory, outputDirectory, appArchive, springBootVersion, params, log);
String springBootVersion, DockerParameters params, BoostLoggerI log, String fromJVM) {
super(projectDirectory, outputDirectory, appArchive, springBootVersion, params, log, fromJVM);
}

public Map<String, String> getBuildArgs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
public class DockerizeSpringBootClasspath extends SpringDockerizer {

public DockerizeSpringBootClasspath(File projectDirectory, File outputDirectory, File appArchive,
String springBootVersion, DockerParameters params, BoostLoggerI log) {
super(projectDirectory, outputDirectory, appArchive, springBootVersion, params, log);
String springBootVersion, DockerParameters params, BoostLoggerI log, String fromJVM) {
super(projectDirectory, outputDirectory, appArchive, springBootVersion, params, log, fromJVM);
}

public Map<String, String> getBuildArgs() {
Expand All @@ -36,7 +36,7 @@ public Map<String, String> getBuildArgs() {
public List<String> getDockerfileLines() throws BoostException {
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=" + params.getDependencyFolder());
lines.add("COPY ${DEPENDENCY}/BOOT-INF/lib /app/lib");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
public class DockerizeSpringBootJar extends SpringDockerizer {

public DockerizeSpringBootJar(File projectDirectory, File outputDirectory, File appArchive,
String springBootVersion, DockerParameters params, BoostLoggerI log) {
super(projectDirectory, outputDirectory, appArchive, springBootVersion, params, log);
String springBootVersion, DockerParameters params, BoostLoggerI log, String fromJVM) {
super(projectDirectory, outputDirectory, appArchive, springBootVersion, params, log, fromJVM);
}

public Map<String, String> getBuildArgs() {
Expand All @@ -36,7 +36,7 @@ public Map<String, String> getBuildArgs() {
public List<String> getDockerfileLines() throws BoostException {
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 {
public final String SPRING_BOOT_VERSION;
public final DockerParameters params;

public SpringDockerizer(File projectDirectory, File outputDirectory, File appArchive, String springBootVersion, DockerParameters params, BoostLoggerI log) {
super(projectDirectory, outputDirectory, appArchive, log);
public SpringDockerizer(File projectDirectory, File outputDirectory, File appArchive, String springBootVersion, DockerParameters params, BoostLoggerI log, String fromJVM) {
super(projectDirectory, outputDirectory, appArchive, log, fromJVM);
this.SPRING_BOOT_VERSION = springBootVersion;
this.params = params;
}
Expand Down
2 changes: 1 addition & 1 deletion boost-maven/boost-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<dependency>
<groupId>io.openliberty.boost</groupId>
<artifactId>boost-common</artifactId>
<version>0.1.2</version>
<version>0.1.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.wasdev.wlp.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,27 @@ public class DockerBuildMojo extends AbstractDockerMojo implements DockerBuildI
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 Dockerfile to create.<br>
* Supported values are: openj9, hotspot, graalvm
*/
@Parameter(property = "dockerizerJVM", defaultValue = "openj9")
private String dockerizerJVM;

@Override
public void execute(DockerClient dockerClient) throws BoostException {
File projectDirectory = project.getBasedir();
File outputDirectory = new File(project.getBuild().getDirectory());
String javaVersion = project.getProperties().getProperty("java.version", "1.8");
String springBootVersion = MavenProjectUtil.findSpringBootVersion(project);
DockerParameters params = new DockerParameters("target/dependency");
dockerBuild(dockerizer, dockerClient, projectDirectory, outputDirectory, springBootVersion, pullNewerImage,
dockerBuild(dockerizer, dockerizerJVM, dockerClient, projectDirectory, outputDirectory, javaVersion, springBootVersion, pullNewerImage,
noCache, buildArgs, repository, tag, params, BoostLogger.getInstance());
}

Expand Down

0 comments on commit 6db1e20

Please sign in to comment.