Search in sources :

Example 1 with BuildRequest

use of org.springframework.boot.buildpack.platform.build.BuildRequest in project spring-boot by spring-projects.

the class BuildImageMojo method getBuildRequest.

private BuildRequest getBuildRequest(Libraries libraries) throws MojoExecutionException {
    ImagePackager imagePackager = new ImagePackager(getArchiveFile(), getBackupFile());
    Function<Owner, TarArchive> content = (owner) -> getApplicationContent(owner, libraries, imagePackager);
    Image image = (this.image != null) ? this.image : new Image();
    if (image.name == null && this.imageName != null) {
        image.setName(this.imageName);
    }
    if (image.builder == null && this.imageBuilder != null) {
        image.setBuilder(this.imageBuilder);
    }
    if (image.runImage == null && this.runImage != null) {
        image.setRunImage(this.runImage);
    }
    if (image.cleanCache == null && this.cleanCache != null) {
        image.setCleanCache(this.cleanCache);
    }
    if (image.pullPolicy == null && this.pullPolicy != null) {
        image.setPullPolicy(this.pullPolicy);
    }
    if (image.publish == null && this.publish != null) {
        image.setPublish(this.publish);
    }
    if (image.network == null && this.network != null) {
        image.setNetwork(this.network);
    }
    if (image.publish != null && image.publish && publishRegistryNotConfigured()) {
        throw new MojoExecutionException("Publishing an image requires docker.publishRegistry to be configured");
    }
    return customize(image.getBuildRequest(this.project.getArtifact(), content));
}
Also used : AbstractBuildLog(org.springframework.boot.buildpack.platform.build.AbstractBuildLog) TotalProgressEvent(org.springframework.boot.buildpack.platform.docker.TotalProgressEvent) Parameter(org.apache.maven.plugins.annotations.Parameter) Function(java.util.function.Function) Supplier(java.util.function.Supplier) TarConstants(org.apache.commons.compress.archivers.tar.TarConstants) Execute(org.apache.maven.plugins.annotations.Execute) TarArchiveOutputStream(org.apache.commons.compress.archivers.tar.TarArchiveOutputStream) Mojo(org.apache.maven.plugins.annotations.Mojo) LayoutFactory(org.springframework.boot.loader.tools.LayoutFactory) TarArchiveEntry(org.apache.commons.compress.archivers.tar.TarArchiveEntry) TarArchive(org.springframework.boot.buildpack.platform.io.TarArchive) Duration(java.time.Duration) Artifact(org.apache.maven.artifact.Artifact) LifecyclePhase(org.apache.maven.plugins.annotations.LifecyclePhase) ResolutionScope(org.apache.maven.plugins.annotations.ResolutionScope) ZipEntry(java.util.zip.ZipEntry) OutputStream(java.io.OutputStream) DockerConfiguration(org.springframework.boot.buildpack.platform.docker.configuration.DockerConfiguration) ImagePackager(org.springframework.boot.loader.tools.ImagePackager) PullPolicy(org.springframework.boot.buildpack.platform.build.PullPolicy) BuildLog(org.springframework.boot.buildpack.platform.build.BuildLog) Builder(org.springframework.boot.buildpack.platform.build.Builder) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Log(org.apache.maven.plugin.logging.Log) Creator(org.springframework.boot.buildpack.platform.build.Creator) Libraries(org.springframework.boot.loader.tools.Libraries) File(java.io.File) Consumer(java.util.function.Consumer) BuildRequest(org.springframework.boot.buildpack.platform.build.BuildRequest) Owner(org.springframework.boot.buildpack.platform.io.Owner) EntryWriter(org.springframework.boot.loader.tools.EntryWriter) Collections(java.util.Collections) StringUtils(org.springframework.util.StringUtils) Owner(org.springframework.boot.buildpack.platform.io.Owner) TarArchive(org.springframework.boot.buildpack.platform.io.TarArchive) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ImagePackager(org.springframework.boot.loader.tools.ImagePackager)

Example 2 with BuildRequest

use of org.springframework.boot.buildpack.platform.build.BuildRequest in project spring-boot by spring-projects.

the class BuildImageMojo method buildImage.

private void buildImage() throws MojoExecutionException {
    Libraries libraries = getLibraries(Collections.emptySet());
    try {
        DockerConfiguration dockerConfiguration = (this.docker != null) ? this.docker.asDockerConfiguration() : null;
        BuildRequest request = getBuildRequest(libraries);
        Builder builder = new Builder(new MojoBuildLog(this::getLog), dockerConfiguration);
        builder.build(request);
    } catch (IOException ex) {
        throw new MojoExecutionException(ex.getMessage(), ex);
    }
}
Also used : DockerConfiguration(org.springframework.boot.buildpack.platform.docker.configuration.DockerConfiguration) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Builder(org.springframework.boot.buildpack.platform.build.Builder) Libraries(org.springframework.boot.loader.tools.Libraries) IOException(java.io.IOException) BuildRequest(org.springframework.boot.buildpack.platform.build.BuildRequest)

Example 3 with BuildRequest

use of org.springframework.boot.buildpack.platform.build.BuildRequest in project spring-boot by spring-projects.

the class BootBuildImageTests method whenProjectVersionIsSpecifiedThenItIsUsedInTagOfImageName.

@Test
void whenProjectVersionIsSpecifiedThenItIsUsedInTagOfImageName() {
    this.project.setVersion("1.2.3");
    assertThat(this.buildImage.getImageName()).isEqualTo("docker.io/library/build-image-test:1.2.3");
    BuildRequest request = this.buildImage.createRequest();
    assertThat(request.getName().getDomain()).isEqualTo("docker.io");
    assertThat(request.getName().getName()).isEqualTo("library/build-image-test");
    assertThat(request.getName().getTag()).isEqualTo("1.2.3");
    assertThat(request.getName().getDigest()).isNull();
}
Also used : BuildRequest(org.springframework.boot.buildpack.platform.build.BuildRequest) Test(org.junit.jupiter.api.Test)

Example 4 with BuildRequest

use of org.springframework.boot.buildpack.platform.build.BuildRequest in project spring-boot by spring-projects.

the class BootBuildImageTests method whenProjectVersionIsUnspecifiedThenItIsIgnoredWhenDerivingImageName.

@Test
void whenProjectVersionIsUnspecifiedThenItIsIgnoredWhenDerivingImageName() {
    assertThat(this.buildImage.getImageName()).isEqualTo("docker.io/library/build-image-test");
    BuildRequest request = this.buildImage.createRequest();
    assertThat(request.getName().getDomain()).isEqualTo("docker.io");
    assertThat(request.getName().getName()).isEqualTo("library/build-image-test");
    assertThat(request.getName().getTag()).isEqualTo("latest");
    assertThat(request.getName().getDigest()).isNull();
}
Also used : BuildRequest(org.springframework.boot.buildpack.platform.build.BuildRequest) Test(org.junit.jupiter.api.Test)

Example 5 with BuildRequest

use of org.springframework.boot.buildpack.platform.build.BuildRequest in project spring-boot by spring-projects.

the class BootBuildImageTests method springBootVersionDefaultValueIsUsed.

@Test
void springBootVersionDefaultValueIsUsed() {
    BuildRequest request = this.buildImage.createRequest();
    assertThat(request.getCreator().getName()).isEqualTo("Spring Boot");
    assertThat(request.getCreator().getVersion()).isEqualTo("");
}
Also used : BuildRequest(org.springframework.boot.buildpack.platform.build.BuildRequest) Test(org.junit.jupiter.api.Test)

Aggregations

BuildRequest (org.springframework.boot.buildpack.platform.build.BuildRequest)23 Test (org.junit.jupiter.api.Test)20 Builder (org.springframework.boot.buildpack.platform.build.Builder)3 IOException (java.io.IOException)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 DockerConfiguration (org.springframework.boot.buildpack.platform.docker.configuration.DockerConfiguration)2 Libraries (org.springframework.boot.loader.tools.Libraries)2 VolumeCacheInfo (org.springframework.boot.maven.CacheInfo.VolumeCacheInfo)2 File (java.io.File)1 OutputStream (java.io.OutputStream)1 Duration (java.time.Duration)1 Collections (java.util.Collections)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 ZipEntry (java.util.zip.ZipEntry)1 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)1 TarArchiveOutputStream (org.apache.commons.compress.archivers.tar.TarArchiveOutputStream)1 TarConstants (org.apache.commons.compress.archivers.tar.TarConstants)1 Artifact (org.apache.maven.artifact.Artifact)1