Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Maven support for containerizing packaged JAR #1746

Merged
merged 34 commits into from
Jun 17, 2019
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
af2e106
wip
chanseokoh May 10, 2019
bc98dac
wip
chanseokoh May 10, 2019
759a8b7
Merge branch 'master' into jar-experiment
chanseokoh May 15, 2019
526a1ba
Add containerizingMode config
chanseokoh May 15, 2019
17d5dd0
Refactor code
chanseokoh May 15, 2019
e63bc7e
fix
chanseokoh May 17, 2019
4ec572d
Update example
chanseokoh May 17, 2019
56562cc
fix example
chanseokoh May 17, 2019
a7728fa
Merge branch 'master' into jar-experiment
chanseokoh May 29, 2019
4d8e81c
Remove debug output
chanseokoh May 29, 2019
bee3268
Fix existing tests
chanseokoh May 29, 2019
c8af0ff
wip
chanseokoh May 29, 2019
13db40c
Add tests
chanseokoh May 30, 2019
17d5ebc
Merge remote-tracking branch 'origin/master' into jar-experiment
chanseokoh May 30, 2019
c0d2c0b
Merge remote-tracking branch 'origin/master' into jar-experiment
chanseokoh May 30, 2019
9a33978
Set appRoot / update error message
chanseokoh May 30, 2019
8135c97
Add tests
chanseokoh May 30, 2019
24ee519
Refactor code
chanseokoh May 30, 2019
8fd5d18
Merge branch 'master' into jar-experiment
chanseokoh May 31, 2019
f0af7af
Merge remote-tracking branch 'origin/master' into jar-experiment
chanseokoh May 31, 2019
4c715c2
Add tests
chanseokoh May 31, 2019
c73eac3
Add integration test
chanseokoh May 31, 2019
185ed13
Define constant for containerizingMode
chanseokoh May 31, 2019
6ff148f
Specialize error message on mode / refactor code
chanseokoh May 31, 2019
2c34f80
Remove unused method introduced briefly
chanseokoh Jun 3, 2019
9365ae7
Get generated JAR in various ways
chanseokoh Jun 4, 2019
c6e5f7c
mainArtifact should be JAR
chanseokoh Jun 4, 2019
dc83f69
Target maven-jar-plugin's JAR path
chanseokoh Jun 4, 2019
279cb1e
Define constant for default mode (exploded)
chanseokoh Jun 12, 2019
32edbba
Error on "packaged" mode with WAR
chanseokoh Jun 12, 2019
19c41e7
Merge remote-tracking branch 'origin/master' into jar-experiment
chanseokoh Jun 12, 2019
ea170e1
Fix test
chanseokoh Jun 12, 2019
bbfff1c
Do not use context classloader
chanseokoh Jun 12, 2019
be7610b
Merge remote-tracking branch 'origin/master' into jar-experiment
chanseokoh Jun 14, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
wip
chanseokoh committed May 10, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit af2e106d1ee1029d2c098356760e28ad794393d4
Original file line number Diff line number Diff line change
@@ -473,21 +473,15 @@ public JibContainerBuilder toContainerBuilder() throws IOException {
.collect(Collectors.toList());
for (Path file : addedDependencies) {
// Add dependencies to layer configuration
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is simple code cleanup. No change to the logic.

String jarName = file.getFileName().toString();
if (duplicates.contains(jarName)) {
jarName = jarName.replaceFirst("\\.jar$", "-" + Files.size(file)) + ".jar";
}
addFileToLayer(
layerBuilders,
file.getFileName().toString().contains("SNAPSHOT")
? LayerType.SNAPSHOT_DEPENDENCIES
: LayerType.DEPENDENCIES,
jarName.contains("SNAPSHOT") ? LayerType.SNAPSHOT_DEPENDENCIES : LayerType.DEPENDENCIES,
file,
appRoot
.resolve(dependenciesDestination)
.resolve(
duplicates.contains(file.getFileName().toString())
? file.getFileName()
.toString()
.replaceFirst("\\.jar$", "-" + Files.size(file))
+ ".jar"
: file.getFileName().toString()));
appRoot.resolve(dependenciesDestination).resolve(jarName));
}

// Add others to layer configuration
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
@@ -200,11 +201,20 @@ static int getVersionFromString(String versionString) {

@Override
public JibContainerBuilder createContainerBuilder(RegistryImage baseImage) throws IOException {
boolean putRunnableArtifact = true;
try {
if (isWarProject()) {
chanseokoh marked this conversation as resolved.
Show resolved Hide resolved
Path explodedWarPath =
Paths.get(project.getBuild().getDirectory()).resolve(project.getBuild().getFinalName());
return JavaContainerBuilderHelper.fromExplodedWar(baseImage, explodedWarPath, appRoot);
} else if (putRunnableArtifact) {
Path artifact =
Paths.get(project.getBuild().getDirectory())
.resolve(project.getBuild().getFinalName() + "." + project.getPackaging());
return JavaContainerBuilder.from(baseImage)
.addDependencies(getDependencies())
.addToClasspath(artifact)
.toContainerBuilder();
}

Path classesOutputDirectory = Paths.get(project.getBuild().getOutputDirectory());
@@ -215,13 +225,7 @@ public JibContainerBuilder createContainerBuilder(RegistryImage baseImage) throw
.setAppRoot(appRoot)
.addResources(classesOutputDirectory, isClassFile.negate())
.addClasses(classesOutputDirectory, isClassFile)
.addDependencies(
project
.getArtifacts()
.stream()
.map(Artifact::getFile)
.map(File::toPath)
.collect(Collectors.toList()))
.addDependencies(getDependencies())
chanseokoh marked this conversation as resolved.
Show resolved Hide resolved
.toContainerBuilder();

} catch (IOException ex) {
@@ -342,4 +346,9 @@ public int getMajorJavaVersion() {
public boolean isOffline() {
return session.isOffline();
}

private List<Path> getDependencies() {
Set<Artifact> artifacts = project.getArtifacts();
return artifacts.stream().map(Artifact::getFile).map(File::toPath).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -274,7 +274,13 @@ static List<String> computeEntrypoint(
}

List<String> classpath = new ArrayList<>(rawExtraClasspath);
classpath.addAll(JavaEntrypointConstructor.defaultClasspath(appRoot));
boolean packagedApp = true;
if (packagedApp) {
classpath.add("/app/classpath");
classpath.add("/app/libs/*");
} else {
classpath.addAll(JavaEntrypointConstructor.defaultClasspath(appRoot));
}
String mainClass =
MainClassResolver.resolveMainClass(
rawConfiguration.getMainClass().orElse(null), projectProperties);