Merge pull request #22918 from jnizet
* pr/22918: Fix custom image name example and documentation Closes gh-22918
This commit is contained in:
commit
d452bbbea8
|
@ -59,7 +59,7 @@ The following table summarizes the available properties and their default values
|
|||
| `imageName`
|
||||
| `--imageName`
|
||||
| {spring-boot-api}/buildpack/platform/docker/type/ImageReference.html#of-java.lang.String-[Image name] for the generated image.
|
||||
| `docker.io/library/${project.artifactId}:${project.version}`
|
||||
| `docker.io/library/${project.name}:${project.version}`
|
||||
|
||||
| `environment`
|
||||
|
|
||||
|
@ -149,7 +149,7 @@ include::../gradle/packaging/boot-build-image-env-proxy.gradle.kts[tags=env]
|
|||
|
||||
[[build-image-example-custom-image-name]]
|
||||
==== Custom Image Name
|
||||
By default, the image name is inferred from the `artifactId` and the `version` of the project, something like `docker.io/library/${project.artifactId}:${project.version}`.
|
||||
By default, the image name is inferred from the `name` and the `version` of the project, something like `docker.io/library/${project.name}:${project.version}`.
|
||||
You can take control over the name by setting task properties, as shown in the following example:
|
||||
|
||||
[source,groovy,indent=0,subs="verbatim,attributes",role="primary"]
|
||||
|
|
|
@ -3,12 +3,14 @@ plugins {
|
|||
id 'org.springframework.boot' version '{gradle-project-version}'
|
||||
}
|
||||
|
||||
bootJar {
|
||||
mainClassName 'com.example.ExampleApplication'
|
||||
}
|
||||
|
||||
// tag::image-name[]
|
||||
bootBuildImage {
|
||||
imageName = "example.com/library/${project.artifactId}"
|
||||
imageName = "example.com/library/${project.name}"
|
||||
}
|
||||
// end::image-name[]
|
||||
|
||||
task bootBuildImageName {
|
||||
doFirst {
|
||||
println(tasks.bootBuildImage.imageName)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
import org.springframework.boot.gradle.tasks.bundling.BootJar
|
||||
import org.springframework.boot.gradle.tasks.bundling.BootBuildImage
|
||||
|
||||
plugins {
|
||||
java
|
||||
id("org.springframework.boot") version "{gradle-project-version}"
|
||||
}
|
||||
|
||||
tasks.getByName<BootJar>("bootJar") {
|
||||
mainClassName = "com.example.ExampleApplication"
|
||||
}
|
||||
|
||||
// tag::image-name[]
|
||||
tasks.getByName<BootBuildImage>("bootBuildImage") {
|
||||
imageName = "example.com/library/${project.artifactId}"
|
||||
imageName = "example.com/library/${project.name}"
|
||||
}
|
||||
// end::image-name[]
|
||||
|
||||
tasks.register("bootBuildImageName") {
|
||||
doFirst {
|
||||
println(tasks.getByName<BootBuildImage>("bootBuildImage").imageName)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -237,6 +237,13 @@ class PackagingDocumentationTests {
|
|||
.contains("HTTPS_PROXY=https://proxy.example.com");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void bootBuildImageWithCustomImageName() throws IOException {
|
||||
BuildResult result = this.gradleBuild.script("src/docs/gradle/packaging/boot-build-image-name")
|
||||
.build("bootBuildImageName");
|
||||
assertThat(result.getOutput()).contains("example.com/library/" + this.gradleBuild.getProjectDir().getName());
|
||||
}
|
||||
|
||||
protected void jarFile(File file) throws IOException {
|
||||
try (JarOutputStream jar = new JarOutputStream(new FileOutputStream(file))) {
|
||||
jar.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));
|
||||
|
|
Loading…
Reference in New Issue