Allow image application directory to be configurable

An `applicationDirectory` option on the Maven
`spring-boot:build-image` goal and the Gradle `bootBuildImage` task
can be configured to set the location that will be used to upload
application contents to the builder image, and will contain the
application contents in the generated image.

Closes gh-34786
This commit is contained in:
Scott Frederick
2023-04-07 14:00:00 -05:00
parent df542849be
commit 56bc6d2fa0
16 changed files with 292 additions and 22 deletions

View File

@@ -270,6 +270,16 @@ public abstract class BootBuildImage extends DefaultTask {
@Option(option = "createdDate", description = "The date to use as the created date of the image")
public abstract Property<String> getCreatedDate();
/**
* Returns the directory that contains application content in the image. When
* {@code null}, a default location will be used.
* @return the application directory
*/
@Input
@Optional
@Option(option = "applicationDirectory", description = "The directory containing application content in the image")
public abstract Property<String> getApplicationDirectory();
/**
* Returns the Docker configuration the builder will use.
* @return docker configuration.
@@ -316,6 +326,7 @@ public abstract class BootBuildImage extends DefaultTask {
request = customizeCaches(request);
request = request.withNetwork(getNetwork().getOrNull());
request = customizeCreatedDate(request);
request = customizeApplicationDirectory(request);
return request;
}
@@ -406,4 +417,12 @@ public abstract class BootBuildImage extends DefaultTask {
return request;
}
private BuildRequest customizeApplicationDirectory(BuildRequest request) {
String applicationDirectory = getApplicationDirectory().getOrNull();
if (applicationDirectory != null) {
return request.withApplicationDirectory(applicationDirectory);
}
return request;
}
}