Search in sources :

Example 1 with ContainerReference

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

the class BuilderTests method mockDockerApi.

private DockerApi mockDockerApi() throws IOException {
    ContainerApi containerApi = mock(ContainerApi.class);
    ContainerReference reference = ContainerReference.of("container-ref");
    given(containerApi.create(any(), any())).willReturn(reference);
    given(containerApi.wait(eq(reference))).willReturn(ContainerStatus.of(0, null));
    ImageApi imageApi = mock(ImageApi.class);
    VolumeApi volumeApi = mock(VolumeApi.class);
    DockerApi docker = mock(DockerApi.class);
    given(docker.image()).willReturn(imageApi);
    given(docker.container()).willReturn(containerApi);
    given(docker.volume()).willReturn(volumeApi);
    return docker;
}
Also used : ImageApi(org.springframework.boot.buildpack.platform.docker.DockerApi.ImageApi) VolumeApi(org.springframework.boot.buildpack.platform.docker.DockerApi.VolumeApi) DockerApi(org.springframework.boot.buildpack.platform.docker.DockerApi) ContainerApi(org.springframework.boot.buildpack.platform.docker.DockerApi.ContainerApi) ContainerReference(org.springframework.boot.buildpack.platform.docker.type.ContainerReference)

Example 2 with ContainerReference

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

the class BuilderTests method mockDockerApiLifecycleError.

private DockerApi mockDockerApiLifecycleError() throws IOException {
    ContainerApi containerApi = mock(ContainerApi.class);
    ContainerReference reference = ContainerReference.of("container-ref");
    given(containerApi.create(any(), any())).willReturn(reference);
    given(containerApi.wait(eq(reference))).willReturn(ContainerStatus.of(9, null));
    ImageApi imageApi = mock(ImageApi.class);
    VolumeApi volumeApi = mock(VolumeApi.class);
    DockerApi docker = mock(DockerApi.class);
    given(docker.image()).willReturn(imageApi);
    given(docker.container()).willReturn(containerApi);
    given(docker.volume()).willReturn(volumeApi);
    return docker;
}
Also used : ImageApi(org.springframework.boot.buildpack.platform.docker.DockerApi.ImageApi) VolumeApi(org.springframework.boot.buildpack.platform.docker.DockerApi.VolumeApi) DockerApi(org.springframework.boot.buildpack.platform.docker.DockerApi) ContainerApi(org.springframework.boot.buildpack.platform.docker.DockerApi.ContainerApi) ContainerReference(org.springframework.boot.buildpack.platform.docker.type.ContainerReference)

Example 3 with ContainerReference

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

the class LifecycleTests method assertPhaseWasRun.

private void assertPhaseWasRun(String name, IOConsumer<ContainerConfig> configConsumer) throws IOException {
    ContainerReference containerReference = ContainerReference.of("cnb-lifecycle-" + name);
    then(this.docker.container()).should().start(containerReference);
    then(this.docker.container()).should().logs(eq(containerReference), any());
    then(this.docker.container()).should().remove(containerReference, true);
    configConsumer.accept(this.configs.get(containerReference.toString()));
}
Also used : ContainerReference(org.springframework.boot.buildpack.platform.docker.type.ContainerReference)

Example 4 with ContainerReference

use of org.springframework.boot.buildpack.platform.docker.type.ContainerReference 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

ContainerReference (org.springframework.boot.buildpack.platform.docker.type.ContainerReference)4 DockerApi (org.springframework.boot.buildpack.platform.docker.DockerApi)2 ContainerApi (org.springframework.boot.buildpack.platform.docker.DockerApi.ContainerApi)2 ImageApi (org.springframework.boot.buildpack.platform.docker.DockerApi.ImageApi)2 VolumeApi (org.springframework.boot.buildpack.platform.docker.DockerApi.VolumeApi)2 LogUpdateEvent (org.springframework.boot.buildpack.platform.docker.LogUpdateEvent)1 ContainerConfig (org.springframework.boot.buildpack.platform.docker.type.ContainerConfig)1 ContainerStatus (org.springframework.boot.buildpack.platform.docker.type.ContainerStatus)1