Search in sources :

Example 6 with ImageReference

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

the class LifecycleTests method getTestRequest.

private BuildRequest getTestRequest() {
    TarArchive content = mock(TarArchive.class);
    ImageReference name = ImageReference.of("my-application");
    return BuildRequest.of(name, (owner) -> content).withRunImage(ImageReference.of("cloudfoundry/run"));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) VolumeApi(org.springframework.boot.buildpack.platform.docker.DockerApi.VolumeApi) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ContainerConfig(org.springframework.boot.buildpack.platform.docker.type.ContainerConfig) ImageReference(org.springframework.boot.buildpack.platform.docker.type.ImageReference) LinkedHashMap(java.util.LinkedHashMap) Answer(org.mockito.stubbing.Answer) ImageApi(org.springframework.boot.buildpack.platform.docker.DockerApi.ImageApi) BDDMockito.given(org.mockito.BDDMockito.given) ContainerReference(org.springframework.boot.buildpack.platform.docker.type.ContainerReference) TarArchive(org.springframework.boot.buildpack.platform.io.TarArchive) Map(java.util.Map) SharedObjectMapper(org.springframework.boot.buildpack.platform.json.SharedObjectMapper) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) JsonNode(com.fasterxml.jackson.databind.JsonNode) ContainerContent(org.springframework.boot.buildpack.platform.docker.type.ContainerContent) PrintStream(java.io.PrintStream) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) BDDMockito.then(org.mockito.BDDMockito.then) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ContainerStatus(org.springframework.boot.buildpack.platform.docker.type.ContainerStatus) InputStreamReader(java.io.InputStreamReader) StandardCharsets(java.nio.charset.StandardCharsets) DockerApi(org.springframework.boot.buildpack.platform.docker.DockerApi) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Test(org.junit.jupiter.api.Test) IOConsumer(org.springframework.boot.buildpack.platform.io.IOConsumer) ContainerApi(org.springframework.boot.buildpack.platform.docker.DockerApi.ContainerApi) Binding(org.springframework.boot.buildpack.platform.docker.type.Binding) VolumeName(org.springframework.boot.buildpack.platform.docker.type.VolumeName) FileCopyUtils(org.springframework.util.FileCopyUtils) InputStream(java.io.InputStream) Mockito.mock(org.mockito.Mockito.mock) ImageReference(org.springframework.boot.buildpack.platform.docker.type.ImageReference) TarArchive(org.springframework.boot.buildpack.platform.io.TarArchive)

Example 7 with ImageReference

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

the class ImageBuildpackTests method resolveWhenUnqualifiedReferenceReturnsBuilder.

@Test
void resolveWhenUnqualifiedReferenceReturnsBuilder() 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("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 8 with ImageReference

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

the class ImageBuildpackTests method resolveReferenceWithoutTagUsesLatestTag.

@Test
void resolveReferenceWithoutTagUsesLatestTag() throws Exception {
    Image image = Image.of(getContent("buildpack-image.json"));
    ImageReference imageReference = ImageReference.of("example/buildpack1:latest");
    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");
    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 9 with ImageReference

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

the class PrintStreamBuildLogTests method printsExpectedOutput.

@Test
void printsExpectedOutput() throws Exception {
    TestPrintStream out = new TestPrintStream();
    PrintStreamBuildLog log = new PrintStreamBuildLog(out);
    BuildRequest request = mock(BuildRequest.class);
    ImageReference name = ImageReference.of("my-app:latest");
    ImageReference builderImageReference = ImageReference.of("cnb/builder");
    Image builderImage = mock(Image.class);
    given(builderImage.getDigests()).willReturn(Collections.singletonList("00000001"));
    ImageReference runImageReference = ImageReference.of("cnb/runner");
    Image runImage = mock(Image.class);
    given(runImage.getDigests()).willReturn(Collections.singletonList("00000002"));
    given(request.getName()).willReturn(name);
    ImageReference tag = ImageReference.of("my-app:1.0");
    given(request.getTags()).willReturn(Collections.singletonList(tag));
    log.start(request);
    Consumer<TotalProgressEvent> pullBuildImageConsumer = log.pullingImage(builderImageReference, ImageType.BUILDER);
    pullBuildImageConsumer.accept(new TotalProgressEvent(100));
    log.pulledImage(builderImage, ImageType.BUILDER);
    Consumer<TotalProgressEvent> pullRunImageConsumer = log.pullingImage(runImageReference, ImageType.RUNNER);
    pullRunImageConsumer.accept(new TotalProgressEvent(100));
    log.pulledImage(runImage, ImageType.RUNNER);
    log.executingLifecycle(request, LifecycleVersion.parse("0.5"), VolumeName.of("pack-abc.cache"));
    Consumer<LogUpdateEvent> phase1Consumer = log.runningPhase(request, "alphabet");
    phase1Consumer.accept(mockLogEvent("one"));
    phase1Consumer.accept(mockLogEvent("two"));
    phase1Consumer.accept(mockLogEvent("three"));
    Consumer<LogUpdateEvent> phase2Consumer = log.runningPhase(request, "basket");
    phase2Consumer.accept(mockLogEvent("spring"));
    phase2Consumer.accept(mockLogEvent("boot"));
    log.executedLifecycle(request);
    log.taggedImage(tag);
    String expected = FileCopyUtils.copyToString(new InputStreamReader(getClass().getResourceAsStream("print-stream-build-log.txt"), StandardCharsets.UTF_8));
    assertThat(out.toString()).isEqualToIgnoringNewLines(expected);
}
Also used : ImageReference(org.springframework.boot.buildpack.platform.docker.type.ImageReference) LogUpdateEvent(org.springframework.boot.buildpack.platform.docker.LogUpdateEvent) InputStreamReader(java.io.InputStreamReader) TotalProgressEvent(org.springframework.boot.buildpack.platform.docker.TotalProgressEvent) Image(org.springframework.boot.buildpack.platform.docker.type.Image) Test(org.junit.jupiter.api.Test)

Example 10 with ImageReference

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

the class BuilderTests method getTestRequest.

private BuildRequest getTestRequest() {
    TarArchive content = mock(TarArchive.class);
    ImageReference name = ImageReference.of("my-application");
    return BuildRequest.of(name, (owner) -> content);
}
Also used : ImageReference(org.springframework.boot.buildpack.platform.docker.type.ImageReference) TarArchive(org.springframework.boot.buildpack.platform.io.TarArchive)

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