forked from eclipse-jkube/jkube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ported PR fabric8io/fabric8-maven-plugin#1711
+ Add a generator for Open Liberty that extends the java-exec generator. It defaults webPort to the Liberty default port (9080) and adds an environment variable for use by S2I if it detects a Liberty runnable jar. + Add Liberty's default web ports (9080, 9443) to the ExposeEnricher so that routes get generated.
- Loading branch information
1 parent
ec8582b
commit 35da441
Showing
13 changed files
with
277 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2019 Red Hat, Inc. | ||
This program and the accompanying materials are made | ||
available under the terms of the Eclipse Public License 2.0 | ||
which is available at: | ||
https://www.eclipse.org/legal/epl-2.0/ | ||
SPDX-License-Identifier: EPL-2.0 | ||
Contributors: | ||
Red Hat, Inc. - initial API and implementation | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>jkube-kit-parent</artifactId> | ||
<groupId>org.eclipse.jkube</groupId> | ||
<version>0.1.1-SNAPSHOT</version> | ||
<relativePath>../parent/pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>jkube-kit-openliberty</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.jkube</groupId> | ||
<artifactId>jkube-maven-enricher-api</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.jkube</groupId> | ||
<artifactId>jkube-maven-enricher-specific</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.jkube</groupId> | ||
<artifactId>jkube-maven-generator-api</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.jkube</groupId> | ||
<artifactId>jkube-maven-generator-java-exec</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.jkube</groupId> | ||
<artifactId>jkube-kit-common</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.jkube</groupId> | ||
<artifactId>jkube-kit-config-image</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-all</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jmockit</groupId> | ||
<artifactId>jmockit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
141 changes: 141 additions & 0 deletions
141
...enliberty/src/main/java/org/eclipse/jkube/openliberty/generator/OpenLibertyGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/** | ||
* Copyright (c) 2019 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at: | ||
* | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.jkube.openliberty.generator; | ||
|
||
|
||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugins.assembly.model.Assembly; | ||
import org.apache.maven.plugins.assembly.model.DependencySet; | ||
import org.apache.maven.plugins.assembly.model.FileSet; | ||
import org.apache.maven.project.MavenProject; | ||
import org.eclipse.jkube.generator.api.GeneratorContext; | ||
import org.eclipse.jkube.generator.javaexec.FatJarDetector; | ||
import org.eclipse.jkube.generator.javaexec.JavaExecGenerator; | ||
import org.eclipse.jkube.kit.build.service.docker.ImageConfiguration; | ||
import org.eclipse.jkube.kit.common.util.MavenUtil; | ||
import org.eclipse.jkube.kit.config.image.build.AssemblyConfiguration; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.eclipse.jkube.kit.common.util.FileUtil.getRelativePath; | ||
|
||
public class OpenLibertyGenerator extends JavaExecGenerator { | ||
|
||
protected static final String LIBERTY_SELF_EXTRACTOR = "wlp.lib.extract.SelfExtractRun"; | ||
protected static final String LIBERTY_RUNNABLE_JAR = "LIBERTY_RUNNABLE_JAR"; | ||
protected static final String JAVA_APP_JAR = "JAVA_APP_JAR"; | ||
|
||
private String runnableJarName = null; | ||
|
||
public OpenLibertyGenerator(GeneratorContext context) { | ||
super(context, "openliberty"); | ||
} | ||
|
||
// Override so that the generator kicks in when the liberty-maven-plugin is used | ||
@Override | ||
public boolean isApplicable(List<ImageConfiguration> configs) { | ||
return shouldAddImageConfiguration(configs) | ||
&& MavenUtil.hasPlugin(getProject(), "io.openliberty.tools", "liberty-maven-plugin"); | ||
|
||
} | ||
|
||
// Override extractPorts so that we default to 9080 rather than 8080 for the web port. | ||
@Override | ||
protected List<String> extractPorts() { | ||
List<String> ret = new ArrayList<>(); | ||
addPortIfValid(ret, getConfig(JavaExecGenerator.Config.webPort, "9080")); | ||
addPortIfValid(ret, getConfig(JavaExecGenerator.Config.jolokiaPort)); | ||
addPortIfValid(ret, getConfig(JavaExecGenerator.Config.prometheusPort)); | ||
return ret; | ||
} | ||
|
||
|
||
@Override | ||
protected Map<String, String> getEnv(boolean prePackagePhase) throws MojoExecutionException { | ||
Map<String,String> ret = super.getEnv(prePackagePhase); | ||
if ( runnableJarName != null) { | ||
ret.put(LIBERTY_RUNNABLE_JAR, runnableJarName); | ||
ret.put(JAVA_APP_JAR, runnableJarName); | ||
} | ||
return ret; | ||
} | ||
@Override | ||
protected AssemblyConfiguration createAssembly() throws MojoExecutionException { | ||
AssemblyConfiguration.Builder builder = new AssemblyConfiguration.Builder().targetDir(getConfig(Config.targetDir)); | ||
addAssembly(builder); | ||
return builder.build(); | ||
} | ||
|
||
@Override | ||
protected void addAssembly(AssemblyConfiguration.Builder builder) throws MojoExecutionException { | ||
String assemblyRef = getConfig(Config.assemblyRef); | ||
if (assemblyRef != null) { | ||
builder.descriptorRef(assemblyRef); | ||
} else { | ||
Assembly assembly = new Assembly(); | ||
addAdditionalFiles(assembly); | ||
if (isFatJar()) { | ||
FatJarDetector.Result fatJar = detectFatJar(); | ||
MavenProject project = getProject(); | ||
if (fatJar == null) { | ||
DependencySet dependencySet = new DependencySet(); | ||
dependencySet.addInclude(project.getGroupId() + ":" + project.getArtifactId()); | ||
assembly.addDependencySet(dependencySet); | ||
} else { | ||
FileSet fileSet = getOutputDirectoryFileSet(fatJar, project); | ||
if ( LIBERTY_SELF_EXTRACTOR.equals(fatJar.getMainClass())) { | ||
this.runnableJarName = fatJar.getArchiveFile().getName(); | ||
} | ||
assembly.addFileSet(fileSet); | ||
} | ||
} else { | ||
builder.descriptorRef("artifact-with-dependencies"); | ||
} | ||
builder.assemblyDef(assembly); | ||
} | ||
} | ||
|
||
private void addAdditionalFiles(Assembly assembly) { | ||
assembly.addFileSet(createFileSet("src/main/fabric8-includes/bin","bin","0755","0755")); | ||
assembly.addFileSet(createFileSet("src/main/fabric8-includes",".","0644","0755")); | ||
// Add server.xml file | ||
assembly.addFileSet(createFileSet("src/main/liberty/config","src/wlp/config","0644", "0755")); | ||
|
||
} | ||
|
||
private FileSet getOutputDirectoryFileSet(FatJarDetector.Result fatJar, MavenProject project) { | ||
FileSet fileSet = new FileSet(); | ||
File buildDir = new File(project.getBuild().getDirectory()); | ||
fileSet.setDirectory(getRelativePath(project.getBasedir(), buildDir).getPath()); | ||
fileSet.addInclude(getRelativePath(buildDir, fatJar.getArchiveFile()).getPath()); | ||
fileSet.setOutputDirectory("."); | ||
fileSet.setFileMode("0640"); | ||
return fileSet; | ||
} | ||
|
||
private FileSet createFileSet(String sourceDir, String outputDir, String fileMode, String directoryMode) { | ||
FileSet fileSet = new FileSet(); | ||
fileSet.setDirectory(sourceDir); | ||
fileSet.setOutputDirectory(outputDir); | ||
fileSet.setFileMode(fileMode); | ||
fileSet.setDirectoryMode(directoryMode); | ||
return fileSet; | ||
} | ||
|
||
|
||
|
||
} |
5 changes: 5 additions & 0 deletions
5
jkube-kit/jkube-kit-openliberty/src/main/resources/META-INF/jkube/generator-default
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# The order of the generators used is defined in the active profile | ||
# (which is the profile "default" by default) | ||
# You can find the default profiles in "profiles-default.yml" | ||
|
||
org.eclipse.jkube.openliberty.generator.OpenLibertyGenerator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
kubernetes-maven-plugin/doc/src/main/asciidoc/inc/generator/_openliberty.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[[generator-openliberty]] | ||
=== Open Liberty | ||
|
||
The Open Liberty generator runs when the Open Liberty plugin is enabled in the maven build. | ||
|
||
The generator is similar to the <<generator-java-exec,java-exec generator>>. It supports the <<generator-options-common, common generator options>> and the <<generator-java-exec-options, `java-exec` options>>. | ||
|
||
For Open Liberty, the default value of webPort is 9080. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
openshift-maven-plugin/doc/src/main/asciidoc/inc/generator/_openliberty.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[[generator-openliberty]] | ||
=== Open Liberty | ||
|
||
The Open Liberty generator runs when the Open Liberty plugin is enabled in the maven build. | ||
|
||
The generator is similar to the <<generator-java-exec,java-exec generator>>. It supports the <<generator-options-common, common generator options>> and the <<generator-java-exec-options, `java-exec` options>>. | ||
|
||
For Open Liberty, the default value of webPort is 9080. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters