Search in sources :

Example 6 with ImageArchive

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

the class BuilderTests method buildInvokesBuilderWithIfNotPresentPullPolicy.

@Test
void buildInvokesBuilderWithIfNotPresentPullPolicy() 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("docker.io/cloudfoundry/run:base-cnb")), any(), isNull())).willAnswer(withPulledImage(runImage));
    given(docker.image().inspect(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)))).willThrow(new DockerEngineException("docker://localhost/", new URI("example"), 404, "NOT FOUND", null, null)).willReturn(builderImage);
    given(docker.image().inspect(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")))).willThrow(new DockerEngineException("docker://localhost/", new URI("example"), 404, "NOT FOUND", null, null)).willReturn(runImage);
    Builder builder = new Builder(BuildLog.to(out), docker, null);
    BuildRequest request = getTestRequest().withPullPolicy(PullPolicy.IF_NOT_PRESENT);
    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);
    then(docker.image()).should(times(2)).inspect(any());
    then(docker.image()).should(times(2)).pull(any(), any(), isNull());
}
Also used : DockerEngineException(org.springframework.boot.buildpack.platform.docker.transport.DockerEngineException) 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) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 7 with ImageArchive

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

the class BuilderTests method buildInvokesBuilderAndPublishesImage.

@Test
void buildInvokesBuilderAndPublishesImage() throws Exception {
    TestPrintStream out = new TestPrintStream();
    DockerApi docker = mockDockerApi();
    Image builderImage = loadImage("image.json");
    Image runImage = loadImage("run-image.json");
    DockerConfiguration dockerConfiguration = new DockerConfiguration().withBuilderRegistryTokenAuthentication("builder token").withPublishRegistryTokenAuthentication("publish token");
    given(docker.image().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()))).willAnswer(withPulledImage(builderImage));
    given(docker.image().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(), eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()))).willAnswer(withPulledImage(runImage));
    Builder builder = new Builder(BuildLog.to(out), docker, dockerConfiguration);
    BuildRequest request = getTestRequest().withPublish(true);
    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().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()));
    then(docker.image()).should().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(), eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()));
    then(docker.image()).should().push(eq(request.getName()), any(), eq(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader()));
    then(docker.image()).should().load(archive.capture(), any());
    then(docker.image()).should().remove(archive.getValue().getTag(), true);
    then(docker.image()).shouldHaveNoMoreInteractions();
}
Also used : DockerConfiguration(org.springframework.boot.buildpack.platform.docker.configuration.DockerConfiguration) 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 8 with ImageArchive

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

the class BuilderTests method buildInvokesBuilderWithNeverPullPolicy.

@Test
void buildInvokesBuilderWithNeverPullPolicy() 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("docker.io/cloudfoundry/run:base-cnb")), any(), isNull())).willAnswer(withPulledImage(runImage));
    given(docker.image().inspect(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)))).willReturn(builderImage);
    given(docker.image().inspect(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")))).willReturn(runImage);
    Builder builder = new Builder(BuildLog.to(out), docker, null);
    BuildRequest request = getTestRequest().withPullPolicy(PullPolicy.NEVER);
    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);
    then(docker.image()).should(never()).pull(any(), any());
    then(docker.image()).should(times(2)).inspect(any());
}
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 9 with ImageArchive

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

the class BuilderTests method buildInvokesBuilder.

@Test
void buildInvokesBuilder() 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("docker.io/cloudfoundry/run:base-cnb")), 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().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), isNull());
    then(docker.image()).should().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(), isNull());
    then(docker.image()).should().load(archive.capture(), any());
    then(docker.image()).should().remove(archive.getValue().getTag(), true);
    then(docker.image()).shouldHaveNoMoreInteractions();
}
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 ImageArchive

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

the class BuilderTests method buildInvokesBuilderWithTagsAndPublishesImageAndTags.

@Test
void buildInvokesBuilderWithTagsAndPublishesImageAndTags() throws Exception {
    TestPrintStream out = new TestPrintStream();
    DockerApi docker = mockDockerApi();
    Image builderImage = loadImage("image.json");
    Image runImage = loadImage("run-image.json");
    DockerConfiguration dockerConfiguration = new DockerConfiguration().withBuilderRegistryTokenAuthentication("builder token").withPublishRegistryTokenAuthentication("publish token");
    given(docker.image().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()))).willAnswer(withPulledImage(builderImage));
    given(docker.image().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(), eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()))).willAnswer(withPulledImage(runImage));
    Builder builder = new Builder(BuildLog.to(out), docker, dockerConfiguration);
    BuildRequest request = getTestRequest().withPublish(true).withTags(ImageReference.of("my-application:1.2.3"));
    builder.build(request);
    assertThat(out.toString()).contains("Running creator");
    assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'");
    assertThat(out.toString()).contains("Successfully created image tag 'docker.io/library/my-application:1.2.3'");
    then(docker.image()).should().pull(eq(ImageReference.of(BuildRequest.DEFAULT_BUILDER_IMAGE_NAME)), any(), eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()));
    then(docker.image()).should().pull(eq(ImageReference.of("docker.io/cloudfoundry/run:base-cnb")), any(), eq(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader()));
    then(docker.image()).should().push(eq(request.getName()), any(), eq(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader()));
    then(docker.image()).should().tag(eq(request.getName()), eq(ImageReference.of("my-application:1.2.3")));
    then(docker.image()).should().push(eq(ImageReference.of("my-application:1.2.3")), any(), eq(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader()));
    ArgumentCaptor<ImageArchive> archive = ArgumentCaptor.forClass(ImageArchive.class);
    then(docker.image()).should().load(archive.capture(), any());
    then(docker.image()).should().remove(archive.getValue().getTag(), true);
    then(docker.image()).shouldHaveNoMoreInteractions();
}
Also used : DockerConfiguration(org.springframework.boot.buildpack.platform.docker.configuration.DockerConfiguration) 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

Test (org.junit.jupiter.api.Test)10 DockerApi (org.springframework.boot.buildpack.platform.docker.DockerApi)10 Image (org.springframework.boot.buildpack.platform.docker.type.Image)10 ImageArchive (org.springframework.boot.buildpack.platform.docker.type.ImageArchive)10 DockerConfiguration (org.springframework.boot.buildpack.platform.docker.configuration.DockerConfiguration)2 URI (java.net.URI)1 DockerEngineException (org.springframework.boot.buildpack.platform.docker.transport.DockerEngineException)1