Search in sources :

Example 11 with DockerConfiguration

use of org.springframework.boot.buildpack.platform.docker.configuration.DockerConfiguration 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 12 with DockerConfiguration

use of org.springframework.boot.buildpack.platform.docker.configuration.DockerConfiguration 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)

Example 13 with DockerConfiguration

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

the class DockerSpec method asDockerConfiguration.

/**
 * Returns this configuration as a {@link DockerConfiguration} instance. This method
 * should only be called when the configuration is complete and will no longer be
 * changed.
 * @return the Docker configuration
 */
DockerConfiguration asDockerConfiguration() {
    DockerConfiguration dockerConfiguration = new DockerConfiguration();
    dockerConfiguration = customizeHost(dockerConfiguration);
    dockerConfiguration = customizeBuilderAuthentication(dockerConfiguration);
    dockerConfiguration = customizePublishAuthentication(dockerConfiguration);
    return dockerConfiguration;
}
Also used : DockerConfiguration(org.springframework.boot.buildpack.platform.docker.configuration.DockerConfiguration)

Example 14 with DockerConfiguration

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

the class DockerTests method asDockerConfigurationWithHostConfiguration.

@Test
void asDockerConfigurationWithHostConfiguration() {
    Docker docker = new Docker();
    docker.setHost("docker.example.com");
    docker.setTlsVerify(true);
    docker.setCertPath("/tmp/ca-cert");
    DockerConfiguration dockerConfiguration = docker.asDockerConfiguration();
    DockerHost host = dockerConfiguration.getHost();
    assertThat(host.getAddress()).isEqualTo("docker.example.com");
    assertThat(host.isSecure()).isEqualTo(true);
    assertThat(host.getCertificatePath()).isEqualTo("/tmp/ca-cert");
    assertThat(docker.asDockerConfiguration().getBuilderRegistryAuthentication()).isNull();
    assertThat(docker.asDockerConfiguration().getPublishRegistryAuthentication()).isNull();
}
Also used : DockerConfiguration(org.springframework.boot.buildpack.platform.docker.configuration.DockerConfiguration) DockerHost(org.springframework.boot.buildpack.platform.docker.configuration.DockerHost) Test(org.junit.jupiter.api.Test)

Aggregations

DockerConfiguration (org.springframework.boot.buildpack.platform.docker.configuration.DockerConfiguration)14 Test (org.junit.jupiter.api.Test)11 DockerApi (org.springframework.boot.buildpack.platform.docker.DockerApi)4 Image (org.springframework.boot.buildpack.platform.docker.type.Image)4 DockerHost (org.springframework.boot.buildpack.platform.docker.configuration.DockerHost)3 ImageArchive (org.springframework.boot.buildpack.platform.docker.type.ImageArchive)2 IOException (java.io.IOException)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 BuildRequest (org.springframework.boot.buildpack.platform.build.BuildRequest)1 Builder (org.springframework.boot.buildpack.platform.build.Builder)1 Libraries (org.springframework.boot.loader.tools.Libraries)1