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();
}
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);
}
}
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();
}
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);
}
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();
}
Aggregations