Search in sources :

Example 11 with ImageReference

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

the class BootBuildImageRegistryIntegrationTests method buildsImageAndPublishesToRegistry.

@TestTemplate
void buildsImageAndPublishesToRegistry() throws IOException {
    writeMainClass();
    String repoName = "test-image";
    String imageName = this.registryAddress + "/" + repoName;
    BuildResult result = this.gradleBuild.build("bootBuildImage", "--imageName=" + imageName);
    assertThat(result.task(":bootBuildImage").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
    assertThat(result.getOutput()).contains("Building image").contains("Successfully built image").contains("Pushing image '" + imageName + ":latest" + "'").contains("Pushed image '" + imageName + ":latest" + "'");
    ImageReference imageReference = ImageReference.of(imageName);
    Image pulledImage = new DockerApi().image().pull(imageReference, UpdateListener.none());
    assertThat(pulledImage).isNotNull();
    new DockerApi().image().remove(imageReference, false);
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) ImageReference(org.springframework.boot.buildpack.platform.docker.type.ImageReference) DockerApi(org.springframework.boot.buildpack.platform.docker.DockerApi) Image(org.springframework.boot.buildpack.platform.docker.type.Image) TestTemplate(org.junit.jupiter.api.TestTemplate)

Example 12 with ImageReference

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

the class ImageBuildpackTests method resolveReferenceWithDigestUsesDigest.

@Test
void resolveReferenceWithDigestUsesDigest() throws Exception {
    Image image = Image.of(getContent("buildpack-image.json"));
    String digest = "sha256:4acb6bfd6c4f0cabaf7f3690e444afe51f1c7de54d51da7e63fac709c56f1c30";
    ImageReference imageReference = ImageReference.of("example/buildpack1@" + digest);
    BuildpackResolverContext resolverContext = mock(BuildpackResolverContext.class);
    given(resolverContext.fetchImage(eq(imageReference), eq(ImageType.BUILDPACK))).willReturn(image);
    willAnswer(this::withMockLayers).given(resolverContext).exportImageLayers(eq(imageReference), any());
    BuildpackReference reference = BuildpackReference.of("example/buildpack1@" + digest);
    Buildpack buildpack = ImageBuildpack.resolve(resolverContext, reference);
    assertThat(buildpack.getCoordinates()).hasToString("example/hello-universe@0.0.1");
    assertHasExpectedLayers(buildpack);
}
Also used : ImageReference(org.springframework.boot.buildpack.platform.docker.type.ImageReference) Image(org.springframework.boot.buildpack.platform.docker.type.Image) Test(org.junit.jupiter.api.Test)

Example 13 with ImageReference

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

the class ImageBuildpackTests method resolveWhenFullyQualifiedReferenceReturnsBuilder.

@Test
void resolveWhenFullyQualifiedReferenceReturnsBuilder() throws Exception {
    Image image = Image.of(getContent("buildpack-image.json"));
    ImageReference imageReference = ImageReference.of("example/buildpack1:1.0.0");
    BuildpackResolverContext resolverContext = mock(BuildpackResolverContext.class);
    given(resolverContext.fetchImage(eq(imageReference), eq(ImageType.BUILDPACK))).willReturn(image);
    willAnswer(this::withMockLayers).given(resolverContext).exportImageLayers(eq(imageReference), any());
    BuildpackReference reference = BuildpackReference.of("docker://example/buildpack1:1.0.0");
    Buildpack buildpack = ImageBuildpack.resolve(resolverContext, reference);
    assertThat(buildpack.getCoordinates()).hasToString("example/hello-universe@0.0.1");
    assertHasExpectedLayers(buildpack);
}
Also used : ImageReference(org.springframework.boot.buildpack.platform.docker.type.ImageReference) Image(org.springframework.boot.buildpack.platform.docker.type.Image) Test(org.junit.jupiter.api.Test)

Example 14 with ImageReference

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

the class BuildImageRegistryIntegrationTests method whenBuildImageIsInvokedWithPublish.

@TestTemplate
void whenBuildImageIsInvokedWithPublish(MavenBuild mavenBuild) {
    String repoName = "test-image";
    String imageName = this.registryAddress + "/" + repoName;
    mavenBuild.project("build-image-publish").goals("package").systemProperty("spring-boot.build-image.imageName", imageName).execute((project) -> {
        assertThat(buildLog(project)).contains("Building image").contains("Successfully built image").contains("Pushing image '" + imageName + ":latest" + "'").contains("Pushed image '" + imageName + ":latest" + "'");
        ImageReference imageReference = ImageReference.of(imageName);
        DockerApi.ImageApi imageApi = new DockerApi().image();
        Image pulledImage = imageApi.pull(imageReference, UpdateListener.none());
        assertThat(pulledImage).isNotNull();
        imageApi.remove(imageReference, false);
    });
}
Also used : ImageReference(org.springframework.boot.buildpack.platform.docker.type.ImageReference) DockerApi(org.springframework.boot.buildpack.platform.docker.DockerApi) Image(org.springframework.boot.buildpack.platform.docker.type.Image) TestTemplate(org.junit.jupiter.api.TestTemplate)

Example 15 with ImageReference

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

the class Builder method tagImage.

private void tagImage(ImageReference sourceReference, List<ImageReference> tags) throws IOException {
    for (ImageReference tag : tags) {
        this.docker.image().tag(sourceReference, tag);
        this.log.taggedImage(tag);
    }
}
Also used : ImageReference(org.springframework.boot.buildpack.platform.docker.type.ImageReference)

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