Search in sources :

Example 1 with ImageReference

use of org.springframework.boot.buildpack.platform.docker.type.ImageReference in project spring-boot by spring-projects.

the class PaketoBuilderTests method executableJarApp.

@Test
void executableJarApp() throws Exception {
    writeMainClass();
    String imageName = "paketo-integration/" + this.gradleBuild.getProjectDir().getName();
    ImageReference imageReference = ImageReference.of(ImageName.of(imageName));
    BuildResult result = buildImage(imageName);
    assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
    try (GenericContainer<?> container = new GenericContainer<>(imageName).withExposedPorts(8080)) {
        container.waitingFor(Wait.forHttp("/test")).start();
        ContainerConfig config = container.getContainerInfo().getConfig();
        assertLabelsMatchManifestAttributes(config);
        ImageAssertions.assertThat(config).buildMetadata((metadata) -> {
            metadata.buildpacks().contains("paketo-buildpacks/ca-certificates", "paketo-buildpacks/bellsoft-liberica", "paketo-buildpacks/executable-jar", "paketo-buildpacks/dist-zip", "paketo-buildpacks/spring-boot");
            metadata.processOfType("web").extracting("command", "args").containsExactly("java", Collections.singletonList("org.springframework.boot.loader.JarLauncher"));
            metadata.processOfType("executable-jar").extracting("command", "args").containsExactly("java", Collections.singletonList("org.springframework.boot.loader.JarLauncher"));
        });
        assertImageHasSbomLayer(imageReference, config, "executable-jar");
        assertImageLayersMatchLayersIndex(imageReference, config);
    } finally {
        removeImage(imageReference);
    }
}
Also used : ContainerConfig(com.github.dockerjava.api.model.ContainerConfig) ImageReference(org.springframework.boot.buildpack.platform.docker.type.ImageReference) BuildResult(org.gradle.testkit.runner.BuildResult) Test(org.junit.jupiter.api.Test)

Example 2 with ImageReference

use of org.springframework.boot.buildpack.platform.docker.type.ImageReference in project spring-boot by spring-projects.

the class PaketoBuilderTests method executableJarAppBuiltTwiceWithCaching.

@Test
void executableJarAppBuiltTwiceWithCaching() throws Exception {
    writeMainClass();
    String imageName = "paketo-integration/" + this.gradleBuild.getProjectDir().getName();
    ImageReference imageReference = ImageReference.of(ImageName.of(imageName));
    BuildResult result = buildImage(imageName);
    assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
    try (GenericContainer<?> container = new GenericContainer<>(imageName).withExposedPorts(8080)) {
        container.waitingFor(Wait.forHttp("/test")).start();
        container.stop();
    }
    this.gradleBuild.expectDeprecationMessages("BOM table is deprecated in this buildpack api version");
    result = buildImage(imageName);
    assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
    try (GenericContainer<?> container = new GenericContainer<>(imageName).withExposedPorts(8080)) {
        container.waitingFor(Wait.forHttp("/test")).start();
    } finally {
        removeImage(imageReference);
    }
}
Also used : ImageReference(org.springframework.boot.buildpack.platform.docker.type.ImageReference) BuildResult(org.gradle.testkit.runner.BuildResult) Test(org.junit.jupiter.api.Test)

Example 3 with ImageReference

use of org.springframework.boot.buildpack.platform.docker.type.ImageReference in project spring-boot by spring-projects.

the class PaketoBuilderTests method plainDistZipJarApp.

@Test
void plainDistZipJarApp() throws Exception {
    writeMainClass();
    String projectName = this.gradleBuild.getProjectDir().getName();
    String imageName = "paketo-integration/" + projectName;
    ImageReference imageReference = ImageReference.of(ImageName.of(imageName));
    BuildResult result = buildImage(imageName, "assemble", "bootDistZip");
    assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
    try (GenericContainer<?> container = new GenericContainer<>(imageName).withExposedPorts(8080)) {
        container.waitingFor(Wait.forHttp("/test")).start();
        ContainerConfig config = container.getContainerInfo().getConfig();
        ImageAssertions.assertThat(config).buildMetadata((metadata) -> {
            metadata.buildpacks().contains("paketo-buildpacks/ca-certificates", "paketo-buildpacks/bellsoft-liberica", "paketo-buildpacks/dist-zip", "paketo-buildpacks/spring-boot");
            metadata.processOfType("web").extracting("command", "args").containsExactly("/workspace/" + projectName + "/bin/" + projectName, Collections.emptyList());
            metadata.processOfType("dist-zip").extracting("command", "args").containsExactly("/workspace/" + projectName + "/bin/" + projectName, Collections.emptyList());
        });
        assertImageHasSbomLayer(imageReference, config, "dist-zip");
        DigestCapturingCondition digest = new DigestCapturingCondition();
        ImageAssertions.assertThat(config).lifecycleMetadata((metadata) -> metadata.appLayerShas().haveExactly(1, digest));
        ImageAssertions.assertThat(imageReference).layer(digest.getDigest(), (layer) -> layer.entries().contains(projectName + "/bin/" + projectName, projectName + "/lib/" + projectName + "-plain.jar").anyMatch((s) -> s.startsWith(projectName + "/lib/spring-boot-")).anyMatch((s) -> s.startsWith(projectName + "/lib/spring-core-")).anyMatch((s) -> s.startsWith(projectName + "/lib/spring-web-")));
    } finally {
        removeImage(imageReference);
    }
}
Also used : ContainerConfig(com.github.dockerjava.api.model.ContainerConfig) ImageName(org.springframework.boot.buildpack.platform.docker.type.ImageName) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) ContainerConfig(com.github.dockerjava.api.model.ContainerConfig) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TaskOutcome(org.gradle.testkit.runner.TaskOutcome) ImageReference(org.springframework.boot.buildpack.platform.docker.type.ImageReference) JarFile(java.util.jar.JarFile) ArrayList(java.util.ArrayList) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) GradleBuildInjectionExtension(org.springframework.boot.image.junit.GradleBuildInjectionExtension) GradleBuildExtension(org.springframework.boot.testsupport.gradle.testkit.GradleBuildExtension) GenericContainer(org.testcontainers.containers.GenericContainer) PrintWriter(java.io.PrintWriter) Wait(org.testcontainers.containers.wait.strategy.Wait) GradleBuild(org.springframework.boot.testsupport.gradle.testkit.GradleBuild) ImageAssertions(org.springframework.boot.image.assertions.ImageAssertions) Predicate(java.util.function.Predicate) FileWriter(java.io.FileWriter) IOException(java.io.IOException) BuildResult(org.gradle.testkit.runner.BuildResult) Attributes(java.util.jar.Attributes) Assertions.entry(org.assertj.core.api.Assertions.entry) File(java.io.File) DockerApi(org.springframework.boot.buildpack.platform.docker.DockerApi) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) List(java.util.List) Condition(org.assertj.core.api.Condition) Collections(java.util.Collections) StringUtils(org.springframework.util.StringUtils) ImageReference(org.springframework.boot.buildpack.platform.docker.type.ImageReference) BuildResult(org.gradle.testkit.runner.BuildResult) Test(org.junit.jupiter.api.Test)

Example 4 with ImageReference

use of org.springframework.boot.buildpack.platform.docker.type.ImageReference in project spring-boot by spring-projects.

the class PaketoBuilderTests method executableJarAppWithAdditionalArgs.

@Test
void executableJarAppWithAdditionalArgs() throws Exception {
    writeMainClass();
    String imageName = "paketo-integration/" + this.gradleBuild.getProjectDir().getName();
    ImageReference imageReference = ImageReference.of(ImageName.of(imageName));
    BuildResult result = buildImage(imageName);
    assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
    try (GenericContainer<?> container = new GenericContainer<>(imageName).withCommand("--server.port=9090").withExposedPorts(9090)) {
        container.waitingFor(Wait.forHttp("/test")).start();
    } finally {
        removeImage(imageReference);
    }
}
Also used : ImageReference(org.springframework.boot.buildpack.platform.docker.type.ImageReference) BuildResult(org.gradle.testkit.runner.BuildResult) GenericContainer(org.testcontainers.containers.GenericContainer) Test(org.junit.jupiter.api.Test)

Example 5 with ImageReference

use of org.springframework.boot.buildpack.platform.docker.type.ImageReference in project spring-boot by spring-projects.

the class EphemeralBuilderTests method getArchiveHasTag.

@Test
void getArchiveHasTag() throws Exception {
    EphemeralBuilder builder = new EphemeralBuilder(this.owner, this.image, this.targetImage, this.metadata, this.creator, this.env, this.buildpacks);
    ImageReference tag = builder.getArchive().getTag();
    assertThat(tag.toString()).startsWith("pack.local/builder/").endsWith(":latest");
}
Also used : ImageReference(org.springframework.boot.buildpack.platform.docker.type.ImageReference) Test(org.junit.jupiter.api.Test)

Aggregations

ImageReference (org.springframework.boot.buildpack.platform.docker.type.ImageReference)18 Test (org.junit.jupiter.api.Test)14 BuildResult (org.gradle.testkit.runner.BuildResult)8 Image (org.springframework.boot.buildpack.platform.docker.type.Image)7 ContainerConfig (com.github.dockerjava.api.model.ContainerConfig)5 DockerApi (org.springframework.boot.buildpack.platform.docker.DockerApi)5 IOException (java.io.IOException)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 GenericContainer (org.testcontainers.containers.GenericContainer)3 File (java.io.File)2 FileWriter (java.io.FileWriter)2 InputStreamReader (java.io.InputStreamReader)2 PrintWriter (java.io.PrintWriter)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 Consumer (java.util.function.Consumer)2 Predicate (java.util.function.Predicate)2