Search in sources :

Example 1 with LogUpdateEvent

use of org.springframework.boot.buildpack.platform.docker.LogUpdateEvent 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 2 with LogUpdateEvent

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

the class PrintStreamBuildLogTests method mockLogEvent.

private LogUpdateEvent mockLogEvent(String string) {
    LogUpdateEvent event = mock(LogUpdateEvent.class);
    given(event.toString()).willReturn(string);
    return event;
}
Also used : LogUpdateEvent(org.springframework.boot.buildpack.platform.docker.LogUpdateEvent)

Example 3 with LogUpdateEvent

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

the class Lifecycle method run.

private void run(Phase phase) throws IOException {
    Consumer<LogUpdateEvent> logConsumer = this.log.runningPhase(this.request, phase.getName());
    ContainerConfig containerConfig = ContainerConfig.of(this.builder.getName(), phase::apply);
    ContainerReference reference = createContainer(containerConfig);
    try {
        this.docker.container().start(reference);
        this.docker.container().logs(reference, logConsumer::accept);
        ContainerStatus status = this.docker.container().wait(reference);
        if (status.getStatusCode() != 0) {
            throw new BuilderException(phase.getName(), status.getStatusCode());
        }
    } finally {
        this.docker.container().remove(reference, true);
    }
}
Also used : ContainerConfig(org.springframework.boot.buildpack.platform.docker.type.ContainerConfig) LogUpdateEvent(org.springframework.boot.buildpack.platform.docker.LogUpdateEvent) ContainerStatus(org.springframework.boot.buildpack.platform.docker.type.ContainerStatus) ContainerReference(org.springframework.boot.buildpack.platform.docker.type.ContainerReference)

Aggregations

LogUpdateEvent (org.springframework.boot.buildpack.platform.docker.LogUpdateEvent)3 InputStreamReader (java.io.InputStreamReader)1 Test (org.junit.jupiter.api.Test)1 TotalProgressEvent (org.springframework.boot.buildpack.platform.docker.TotalProgressEvent)1 ContainerConfig (org.springframework.boot.buildpack.platform.docker.type.ContainerConfig)1 ContainerReference (org.springframework.boot.buildpack.platform.docker.type.ContainerReference)1 ContainerStatus (org.springframework.boot.buildpack.platform.docker.type.ContainerStatus)1 Image (org.springframework.boot.buildpack.platform.docker.type.Image)1 ImageReference (org.springframework.boot.buildpack.platform.docker.type.ImageReference)1