Skip to content

Commit

Permalink
Support "INHERIT" for quarkus.jib.jvm-entrypoint and quarkus.jib.nati…
Browse files Browse the repository at this point in the history
…ve-entrypoint

jib-maven-plugin and jib-gradle-plugin both support this option to inherit entrypoint
from base image, so make Quarkus learn it.

Fixed #28071
  • Loading branch information
Dieken committed Sep 20, 2022
1 parent 71445ca commit e676c2a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class JibConfig {
* If this is set, then it will be used as the entry point of the container image.
* There are a few things to be aware of when creating an entry point
* <ul>
* <li>Entrypoint "INHERIT" means to inherit entrypoint from base image, {@code jvmArguments} field is used for
* arguments</li>
* <li>A valid entrypoint is jar package specific (see {@code quarkus.package.type})</li>
* <li>A valid entrypoint depends on the location of both the launching scripts and the application jar file. To that
* end it's helpful to remember that when {@code fast-jar} packaging is used (the default), all necessary application
Expand All @@ -62,7 +64,7 @@ public class JibConfig {
* jars
* are unpacked under the {@code /app} directory
* and that directory is used as the working directory.</li>
* <li>Even if the {@code jvmArguments} field is set, it is ignored completely</li>
* <li>Even if the {@code jvmArguments} field is set, it is ignored completely unless entrypoint is "INHERIT"</li>
* </ul>
*
* When this is not set, a proper default entrypoint will be constructed.
Expand All @@ -77,10 +79,12 @@ public class JibConfig {
* If this is set, then it will be used as the entry point of the container image.
* There are a few things to be aware of when creating an entry point
* <ul>
* <li>Entrypoint "INHERIT" means to inherit entrypoint from base image, {@code nativeArguments} field is used for
* arguments</li>
* <li>A valid entrypoint depends on the location of both the launching scripts and the native binary file. To that end
* it's helpful to remember that the native application is added to the {@code /work} directory and that and the same
* directory is also used as the working directory</li>
* <li>Even if the {@code nativeArguments} field is set, it is ignored completely</li>
* <li>Even if the {@code nativeArguments} field is set, it is ignored completely unless entrypoint is "INHERIT"</li>
* </ul>
*
* When this is not set, a proper default entrypoint will be constructed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,8 @@ private JibContainerBuilder createContainerBuilderFromFastJar(String baseJvmImag
.setEnvironment(getEnvironmentVariables(jibConfig))
.setLabels(allLabels(jibConfig, containerImageConfig, containerImageLabels));

mayInheritEntrypoint(jibContainerBuilder, entrypoint, jibConfig.jvmArguments);

if (jibConfig.useCurrentTimestamp) {
jibContainerBuilder.setCreationTime(now);
}
Expand Down Expand Up @@ -596,6 +598,15 @@ public JibContainerBuilder addLayer(JibContainerBuilder jibContainerBuilder, Lis
return jibContainerBuilder.addFileEntriesLayer(layerConfigurationBuilder.build());
}

private void mayInheritEntrypoint(JibContainerBuilder jibContainerBuilder, List<String> entrypoint,
List<String> arguments) {
if (entrypoint.size() == 1 && "INHERIT".equals(entrypoint.get(0))) {
jibContainerBuilder
.setEntrypoint((List<String>) null)
.setProgramArguments(arguments);
}
}

private List<String> determineEffectiveJvmArguments(JibConfig jibConfig, Optional<AppCDSResultBuildItem> appCDSResult) {
List<String> effectiveJvmArguments = new ArrayList<>(jibConfig.jvmArguments);
jibConfig.jvmAdditionalArguments.ifPresent(effectiveJvmArguments::addAll);
Expand Down Expand Up @@ -666,6 +677,7 @@ private JibContainerBuilder createContainerBuilderFromLegacyJar(String baseJvmIm

if (jibConfig.jvmEntrypoint.isPresent()) {
jibContainerBuilder.setEntrypoint(jibConfig.jvmEntrypoint.get());
mayInheritEntrypoint(jibContainerBuilder, jibConfig.jvmEntrypoint.get(), jibConfig.jvmArguments);
}

return jibContainerBuilder;
Expand Down Expand Up @@ -702,6 +714,8 @@ private JibContainerBuilder createContainerBuilderFromNative(JibConfig jibConfig
.setEnvironment(getEnvironmentVariables(jibConfig))
.setLabels(allLabels(jibConfig, containerImageConfig, containerImageLabels));

mayInheritEntrypoint(jibContainerBuilder, entrypoint, jibConfig.nativeArguments.orElse(null));

if (jibConfig.useCurrentTimestamp) {
jibContainerBuilder.setCreationTime(Instant.now());
}
Expand Down

0 comments on commit e676c2a

Please sign in to comment.