Search in sources :

Example 1 with PushParams

use of org.eclipse.che.plugin.docker.client.params.PushParams in project che by eclipse.

the class DockerConnectorTest method shouldBeAbleToPushImageToRepository.

@Test
public void shouldBeAbleToPushImageToRepository() throws IOException, InterruptedException {
    PushParams pushParams = PushParams.create(REPOSITORY);
    when(dockerResponse.getInputStream()).thenReturn(new ByteArrayInputStream(("{\"status\":\"latest: digest: " + DIGEST + " size: 1234\"}").getBytes()));
    dockerConnector.push(pushParams, progressMonitor);
    verify(dockerConnectionFactory).openConnection(any(URI.class));
    verify(dockerConnection).method(REQUEST_METHOD_POST);
    verify(dockerConnection).path("/images/" + pushParams.getRepository() + "/push");
    verify(dockerConnection).header(eq("X-Registry-Auth"), any(AuthConfig.class));
    verify(dockerConnection).request();
    verify(dockerResponse).getStatus();
    verify(dockerResponse).getInputStream();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PushParams(org.eclipse.che.plugin.docker.client.params.PushParams) AuthConfig(org.eclipse.che.plugin.docker.client.dto.AuthConfig) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 2 with PushParams

use of org.eclipse.che.plugin.docker.client.params.PushParams in project che by eclipse.

the class DockerInstance method saveToSnapshot.

@Override
public MachineSource saveToSnapshot() throws MachineException {
    try {
        String image = generateRepository();
        if (!snapshotUseRegistry) {
            commitContainer(image, LATEST_TAG);
            return new DockerMachineSource(image).withTag(LATEST_TAG);
        }
        PushParams pushParams = PushParams.create(image).withRegistry(registry).withTag(LATEST_TAG);
        final String fullRepo = pushParams.getFullRepo();
        commitContainer(fullRepo, LATEST_TAG);
        //TODO fix this workaround. Docker image is not visible after commit when using swarm
        Thread.sleep(2000);
        final ProgressLineFormatterImpl lineFormatter = new ProgressLineFormatterImpl();
        final String digest = docker.push(pushParams, progressMonitor -> {
            try {
                outputConsumer.writeLine(lineFormatter.format(progressMonitor));
            } catch (IOException ignored) {
            }
        });
        docker.removeImage(RemoveImageParams.create(fullRepo).withForce(false));
        return new DockerMachineSource(image).withRegistry(registry).withDigest(digest).withTag(LATEST_TAG);
    } catch (IOException ioEx) {
        throw new MachineException(ioEx);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new MachineException(e.getLocalizedMessage(), e);
    }
}
Also used : ProgressLineFormatterImpl(org.eclipse.che.plugin.docker.client.ProgressLineFormatterImpl) MachineException(org.eclipse.che.api.machine.server.exception.MachineException) PushParams(org.eclipse.che.plugin.docker.client.params.PushParams) IOException(java.io.IOException)

Example 3 with PushParams

use of org.eclipse.che.plugin.docker.client.params.PushParams in project che by eclipse.

the class DockerConnectorTest method shouldBeAbleToPushImageToRegistryRepository.

@Test
public void shouldBeAbleToPushImageToRegistryRepository() throws IOException, InterruptedException {
    PushParams pushParams = PushParams.create(REPOSITORY).withRegistry(REGISTRY);
    when(dockerResponse.getInputStream()).thenReturn(new ByteArrayInputStream(("{\"status\":\"latest: digest: " + DIGEST + " size: 1234\"}").getBytes()));
    dockerConnector.push(pushParams, progressMonitor);
    verify(dockerConnectionFactory).openConnection(any(URI.class));
    verify(dockerConnection).method(REQUEST_METHOD_POST);
    verify(dockerConnection).path("/images/" + pushParams.getRegistry() + '/' + pushParams.getRepository() + "/push");
    verify(dockerConnection).header(eq("X-Registry-Auth"), any(AuthConfig.class));
    verify(dockerConnection).request();
    verify(dockerResponse).getStatus();
    verify(dockerResponse).getInputStream();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PushParams(org.eclipse.che.plugin.docker.client.params.PushParams) AuthConfig(org.eclipse.che.plugin.docker.client.dto.AuthConfig) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 4 with PushParams

use of org.eclipse.che.plugin.docker.client.params.PushParams in project che by eclipse.

the class DockerConnectorTest method shouldThrowDockerExceptionWhenPushFails.

@Test(expectedExceptions = DockerException.class, expectedExceptionsMessageRegExp = "Docker image pushing failed. Cause: test error")
public void shouldThrowDockerExceptionWhenPushFails() throws IOException, InterruptedException {
    String dockerPushOutput = "{\"progress\":\"[=====>              ] 25%\"}\n" + "{\"progress\":\"[===============>    ] 75%\"}\n" + "{\"error\":\"test error\"}\n";
    when(dockerResponse.getInputStream()).thenReturn(new ByteArrayInputStream(dockerPushOutput.getBytes()));
    PushParams pushParams = PushParams.create(REPOSITORY);
    dockerConnector.push(pushParams, progressMonitor);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) PushParams(org.eclipse.che.plugin.docker.client.params.PushParams) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 5 with PushParams

use of org.eclipse.che.plugin.docker.client.params.PushParams in project che by eclipse.

the class DockerConnectorTest method shouldThrowDockerExceptionWhilePushingImageIfResponseCodeIsNotSuccess.

@Test(expectedExceptions = DockerException.class, expectedExceptionsMessageRegExp = EXCEPTION_ERROR_MESSAGE)
public void shouldThrowDockerExceptionWhilePushingImageIfResponseCodeIsNotSuccess() throws IOException, InterruptedException {
    PushParams pushParams = PushParams.create(REPOSITORY);
    when(dockerResponse.getStatus()).thenReturn(RESPONSE_ERROR_CODE);
    dockerConnector.push(pushParams, progressMonitor);
    verify(dockerResponse).getStatus();
}
Also used : PushParams(org.eclipse.che.plugin.docker.client.params.PushParams) Test(org.testng.annotations.Test)

Aggregations

PushParams (org.eclipse.che.plugin.docker.client.params.PushParams)7 Test (org.testng.annotations.Test)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 URI (java.net.URI)2 AuthConfig (org.eclipse.che.plugin.docker.client.dto.AuthConfig)2 Matchers.anyString (org.mockito.Matchers.anyString)2 IOException (java.io.IOException)1 MachineException (org.eclipse.che.api.machine.server.exception.MachineException)1 ProgressLineFormatterImpl (org.eclipse.che.plugin.docker.client.ProgressLineFormatterImpl)1