Search in sources :

Example 6 with DockerConfiguration

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

the class DockerSpecTests method asDockerConfigurationWithHostConfigurationNoTlsVerify.

@Test
void asDockerConfigurationWithHostConfigurationNoTlsVerify() {
    DockerSpec dockerSpec = new DockerSpec();
    dockerSpec.setHost("docker.example.com");
    DockerConfiguration dockerConfiguration = dockerSpec.asDockerConfiguration();
    DockerHost host = dockerConfiguration.getHost();
    assertThat(host.getAddress()).isEqualTo("docker.example.com");
    assertThat(host.isSecure()).isEqualTo(false);
    assertThat(host.getCertificatePath()).isNull();
    assertThat(dockerSpec.asDockerConfiguration().getBuilderRegistryAuthentication()).isNull();
    assertThat(dockerSpec.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)

Example 7 with DockerConfiguration

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

the class DockerTests method asDockerConfigurationWithTokenAuth.

@Test
void asDockerConfigurationWithTokenAuth() {
    Docker docker = new Docker();
    docker.setBuilderRegistry(new Docker.DockerRegistry("token1"));
    docker.setPublishRegistry(new Docker.DockerRegistry("token2"));
    DockerConfiguration dockerConfiguration = docker.asDockerConfiguration();
    assertThat(decoded(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader())).contains("\"identitytoken\" : \"token1\"");
    assertThat(decoded(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader())).contains("\"identitytoken\" : \"token2\"");
}
Also used : DockerConfiguration(org.springframework.boot.buildpack.platform.docker.configuration.DockerConfiguration) Test(org.junit.jupiter.api.Test)

Example 8 with DockerConfiguration

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

the class DockerTests method asDockerConfigurationWithUserAuth.

@Test
void asDockerConfigurationWithUserAuth() {
    Docker docker = new Docker();
    docker.setBuilderRegistry(new Docker.DockerRegistry("user1", "secret1", "https://docker1.example.com", "docker1@example.com"));
    docker.setPublishRegistry(new Docker.DockerRegistry("user2", "secret2", "https://docker2.example.com", "docker2@example.com"));
    DockerConfiguration dockerConfiguration = docker.asDockerConfiguration();
    assertThat(decoded(dockerConfiguration.getBuilderRegistryAuthentication().getAuthHeader())).contains("\"username\" : \"user1\"").contains("\"password\" : \"secret1\"").contains("\"email\" : \"docker1@example.com\"").contains("\"serveraddress\" : \"https://docker1.example.com\"");
    assertThat(decoded(dockerConfiguration.getPublishRegistryAuthentication().getAuthHeader())).contains("\"username\" : \"user2\"").contains("\"password\" : \"secret2\"").contains("\"email\" : \"docker2@example.com\"").contains("\"serveraddress\" : \"https://docker2.example.com\"");
}
Also used : DockerConfiguration(org.springframework.boot.buildpack.platform.docker.configuration.DockerConfiguration) Test(org.junit.jupiter.api.Test)

Example 9 with DockerConfiguration

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

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

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