Add runImage option for image building

This commit adds a runImage property to the Maven plugin build-image
goal and the Gradle bootBuildImage task. The property allows the user
to override the run image reference provided in the builder metadata
with an alternate run image. The runImage property can be specified
in the build file or on the command line.

Fixes gh-21534
This commit is contained in:
Scott Frederick
2020-06-11 16:20:39 -05:00
parent 025d7aaac8
commit 6119d69679
27 changed files with 427 additions and 89 deletions

View File

@@ -94,7 +94,7 @@ public class BuildImageMojo extends AbstractPackagerMojo {
private String classifier;
/**
* Image configuration, with `builder`, `name`, `env`, `cleanCache` and
* Image configuration, with `builder`, `runImage`, `name`, `env`, `cleanCache` and
* `verboseLogging` options.
* @since 2.3.0
*/
@@ -115,6 +115,14 @@ public class BuildImageMojo extends AbstractPackagerMojo {
@Parameter(property = "spring-boot.build-image.builder", readonly = true)
String imageBuilder;
/**
* Alias for {@link Image#runImage} to support configuration via command-line
* property.
* @since 2.3.1
*/
@Parameter(property = "spring-boot.build-image.runImage", readonly = true)
String runImage;
@Override
public void execute() throws MojoExecutionException {
if (this.project.getPackaging().equals("pom")) {
@@ -149,6 +157,9 @@ public class BuildImageMojo extends AbstractPackagerMojo {
if (image.builder == null && this.imageBuilder != null) {
image.setBuilder(this.imageBuilder);
}
if (image.runImage == null && this.runImage != null) {
image.setRunImage(this.runImage);
}
return customize(image.getBuildRequest(this.project.getArtifact(), content));
}

View File

@@ -47,6 +47,11 @@ public class Image {
*/
String builder;
/**
* The run image used to launch the built image.
*/
String runImage;
/**
* Environment properties that should be passed to the builder.
*/
@@ -70,6 +75,10 @@ public class Image {
this.builder = builder;
}
void setRunImage(String runImage) {
this.runImage = runImage;
}
BuildRequest getBuildRequest(Artifact artifact, Function<Owner, TarArchive> applicationContent) {
return customize(BuildRequest.of(getOrDeduceName(artifact), applicationContent));
}
@@ -86,6 +95,9 @@ public class Image {
if (StringUtils.hasText(this.builder)) {
request = request.withBuilder(ImageReference.of(this.builder));
}
if (StringUtils.hasText(this.runImage)) {
request = request.withRunImage(ImageReference.of(this.runImage));
}
if (this.env != null && !this.env.isEmpty()) {
request = request.withEnv(this.env);
}