Search in sources :

Example 6 with DockerApi

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

the class BuilderTests method buildWhenDetectedRunImageInDifferentAuthenticatedRegistryThrowsException.

@Test
void buildWhenDetectedRunImageInDifferentAuthenticatedRegistryThrowsException() throws Exception {
    TestPrintStream out = new TestPrintStream();
    DockerApi docker = mockDockerApi();
    Image builderImage = loadImage("image-with-run-image-different-registry.json");
    DockerConfiguration dockerConfiguration = new DockerConfiguration().withBuilderRegistryTokenAuthentication("builder token");
    given(docker.image().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()))).willAnswer(withPulledImage(builderImage));
    Builder builder = new Builder(BuildLog.to(out), docker, dockerConfiguration);
    BuildRequest request = getTestRequest();
    assertThatIllegalStateException().isThrownBy(() -> builder.build(request)).withMessage("Run image 'example.com/custom/run:latest' must be pulled from the 'docker.io' authenticated registry");
}
Also used : DockerConfiguration(org.springframework.boot.buildpack.platform.docker.configuration.DockerConfiguration) DockerApi(org.springframework.boot.buildpack.platform.docker.DockerApi) Image(org.springframework.boot.buildpack.platform.docker.type.Image) Test(org.junit.jupiter.api.Test)

Example 7 with DockerApi

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

the class BuilderTests method buildWhenBuilderReturnsErrorThrowsException.

@Test
void buildWhenBuilderReturnsErrorThrowsException() throws Exception {
    TestPrintStream out = new TestPrintStream();
    DockerApi docker = mockDockerApiLifecycleError();
    Image builderImage = loadImage("image.json");
    Image runImage = loadImage("run-image.json");
    given(docker.image().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), isNull())).willAnswer(withPulledImage(builderImage));
    given(docker.image().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(), isNull())).willAnswer(withPulledImage(runImage));
    Builder builder = new Builder(BuildLog.to(out), docker, null);
    BuildRequest request = getTestRequest();
    assertThatExceptionOfType(BuilderException.class).isThrownBy(() -> builder.build(request)).withMessage("Builder lifecycle 'creator' failed with status code 9");
}
Also used : DockerApi(org.springframework.boot.buildpack.platform.docker.DockerApi) Image(org.springframework.boot.buildpack.platform.docker.type.Image) Test(org.junit.jupiter.api.Test)

Example 8 with DockerApi

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

the class BuilderTests method buildWhenRequestedRunImageInDifferentAuthenticatedRegistryThrowsException.

@Test
void buildWhenRequestedRunImageInDifferentAuthenticatedRegistryThrowsException() throws Exception {
    TestPrintStream out = new TestPrintStream();
    DockerApi docker = mockDockerApi();
    Image builderImage = loadImage("image.json");
    DockerConfiguration dockerConfiguration = new DockerConfiguration().withBuilderRegistryTokenAuthentication("builder token");
    given(docker.image().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()))).willAnswer(withPulledImage(builderImage));
    Builder builder = new Builder(BuildLog.to(out), docker, dockerConfiguration);
    BuildRequest request = getTestRequest().withRunImage(ImageReference.of("example.com/custom/run:latest"));
    assertThatIllegalStateException().isThrownBy(() -> builder.build(request)).withMessage("Run image 'example.com/custom/run:latest' must be pulled from the 'docker.io' authenticated registry");
}
Also used : DockerConfiguration(org.springframework.boot.buildpack.platform.docker.configuration.DockerConfiguration) DockerApi(org.springframework.boot.buildpack.platform.docker.DockerApi) Image(org.springframework.boot.buildpack.platform.docker.type.Image) Test(org.junit.jupiter.api.Test)

Example 9 with DockerApi

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

the class BuilderTests method buildInvokesBuilderWithRunImageFromRequest.

@Test
void buildInvokesBuilderWithRunImageFromRequest() throws Exception {
    TestPrintStream out = new TestPrintStream();
    DockerApi docker = mockDockerApi();
    Image builderImage = loadImage("image.json");
    Image runImage = loadImage("run-image.json");
    given(docker.image().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), isNull())).willAnswer(withPulledImage(builderImage));
    given(docker.image().pull(eq(ImageReference.of("example.com/custom/run:latest")), any(), isNull())).willAnswer(withPulledImage(runImage));
    Builder builder = new Builder(BuildLog.to(out), docker, null);
    BuildRequest request = getTestRequest().withRunImage(ImageReference.of("example.com/custom/run:latest"));
    builder.build(request);
    assertThat(out.toString()).contains("Running creator");
    assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'");
    ArgumentCaptor<ImageArchive> archive = ArgumentCaptor.forClass(ImageArchive.class);
    then(docker.image()).should().load(archive.capture(), any());
    then(docker.image()).should().remove(archive.getValue().getTag(), true);
}
Also used : DockerApi(org.springframework.boot.buildpack.platform.docker.DockerApi) ImageArchive(org.springframework.boot.buildpack.platform.docker.type.ImageArchive) Image(org.springframework.boot.buildpack.platform.docker.type.Image) Test(org.junit.jupiter.api.Test)

Example 10 with DockerApi

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

the class BuilderTests method buildInvokesBuilderWithRunImageInDigestForm.

@Test
void buildInvokesBuilderWithRunImageInDigestForm() throws Exception {
    TestPrintStream out = new TestPrintStream();
    DockerApi docker = mockDockerApi();
    Image builderImage = loadImage("image-with-run-image-digest.json");
    Image runImage = loadImage("run-image.json");
    given(docker.image().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), isNull())).willAnswer(withPulledImage(builderImage));
    given(docker.image().pull(eq(ImageReference.of("docker.io/cloudfoundry/run@sha256:6e9f67fa63b0323e9a1e587fd71c561ba48a034504fb804fd26fd8800039835d")), any(), isNull())).willAnswer(withPulledImage(runImage));
    Builder builder = new Builder(BuildLog.to(out), docker, null);
    BuildRequest request = getTestRequest();
    builder.build(request);
    assertThat(out.toString()).contains("Running creator");
    assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'");
    ArgumentCaptor<ImageArchive> archive = ArgumentCaptor.forClass(ImageArchive.class);
    then(docker.image()).should().load(archive.capture(), any());
    then(docker.image()).should().remove(archive.getValue().getTag(), true);
}
Also used : DockerApi(org.springframework.boot.buildpack.platform.docker.DockerApi) ImageArchive(org.springframework.boot.buildpack.platform.docker.type.ImageArchive) Image(org.springframework.boot.buildpack.platform.docker.type.Image) Test(org.junit.jupiter.api.Test)

Aggregations

DockerApi (org.springframework.boot.buildpack.platform.docker.DockerApi)21 Image (org.springframework.boot.buildpack.platform.docker.type.Image)17 Test (org.junit.jupiter.api.Test)15 ImageArchive (org.springframework.boot.buildpack.platform.docker.type.ImageArchive)10 DockerConfiguration (org.springframework.boot.buildpack.platform.docker.configuration.DockerConfiguration)4 ContainerApi (org.springframework.boot.buildpack.platform.docker.DockerApi.ContainerApi)3 ImageApi (org.springframework.boot.buildpack.platform.docker.DockerApi.ImageApi)3 VolumeApi (org.springframework.boot.buildpack.platform.docker.DockerApi.VolumeApi)3 TestTemplate (org.junit.jupiter.api.TestTemplate)2 ContainerReference (org.springframework.boot.buildpack.platform.docker.type.ContainerReference)2 ImageReference (org.springframework.boot.buildpack.platform.docker.type.ImageReference)2 URI (java.net.URI)1 BuildResult (org.gradle.testkit.runner.BuildResult)1 DockerEngineException (org.springframework.boot.buildpack.platform.docker.transport.DockerEngineException)1 Layer (org.springframework.boot.buildpack.platform.docker.type.Layer)1