use of org.eclipse.che.plugin.docker.client.params.PullParams in project che by eclipse.
the class DockerConnectorTest method shouldBeAbleToPullImageFromRepository.
@Test
public void shouldBeAbleToPullImageFromRepository() throws IOException, InterruptedException {
PullParams pullParams = PullParams.create(IMAGE);
when(dockerResponse.getInputStream()).thenReturn(new ByteArrayInputStream(STREAM_DATA_BYTES));
dockerConnector.pull(pullParams, progressMonitor);
verify(dockerConnectionFactory).openConnection(any(URI.class));
verify(dockerConnection).method(REQUEST_METHOD_POST);
verify(dockerConnection).path("/images/create");
verify(dockerConnection).query("fromImage", pullParams.getImage());
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.PullParams in project che by eclipse.
the class MachineProviderImpl method pullImage.
/**
* Pulls docker image for container creation.
*
* @param service
* service that provides description of image that should be pulled
* @param machineImageName
* name of the image that should be assigned on pull
* @param progressMonitor
* consumer of output
* @throws SourceNotFoundException
* if image for pulling not found
* @throws MachineException
* if any other error occurs
*/
protected void pullImage(CheServiceImpl service, String machineImageName, ProgressMonitor progressMonitor) throws MachineException {
DockerMachineSource dockerMachineSource = new DockerMachineSource(new MachineSourceImpl("image").setLocation(service.getImage()));
if (dockerMachineSource.getRepository() == null) {
throw new MachineException(format("Machine creation failed. Machine source is invalid. No repository is defined. Found '%s'.", dockerMachineSource));
}
try {
boolean isSnapshot = SNAPSHOT_LOCATION_PATTERN.matcher(dockerMachineSource.getLocation()).matches();
if (!isSnapshot || snapshotUseRegistry) {
PullParams pullParams = PullParams.create(dockerMachineSource.getRepository()).withTag(MoreObjects.firstNonNull(dockerMachineSource.getTag(), LATEST_TAG)).withRegistry(dockerMachineSource.getRegistry()).withAuthConfigs(dockerCredentials.getCredentials());
docker.pull(pullParams, progressMonitor);
}
String fullNameOfPulledImage = dockerMachineSource.getLocation(false);
try {
// tag image with generated name to allow sysadmin recognize it
docker.tag(TagParams.create(fullNameOfPulledImage, machineImageName));
} catch (ImageNotFoundException nfEx) {
throw new SourceNotFoundException(nfEx.getLocalizedMessage(), nfEx);
}
// remove unneeded tag if restoring snapshot from registry
if (isSnapshot && snapshotUseRegistry) {
docker.removeImage(RemoveImageParams.create(fullNameOfPulledImage).withForce(false));
}
} catch (IOException e) {
throw new MachineException("Can't create machine from image. Cause: " + e.getLocalizedMessage(), e);
}
}
use of org.eclipse.che.plugin.docker.client.params.PullParams in project che by eclipse.
the class MachineProviderImplTest method shouldPullDockerImageOnInstanceCreationFromSnapshotFromRegistry.
@Test
public void shouldPullDockerImageOnInstanceCreationFromSnapshotFromRegistry() throws Exception {
String repo = MACHINE_SNAPSHOT_PREFIX + "repo";
String tag = "latest";
String registry = "localhost:1234";
createInstanceFromSnapshot(repo, tag, registry);
PullParams pullParams = PullParams.create(repo).withRegistry(registry).withTag(tag);
verify(dockerConnector).pull(eq(pullParams), any(ProgressMonitor.class));
}
use of org.eclipse.che.plugin.docker.client.params.PullParams in project che by eclipse.
the class DockerConnectorTest method shouldBeAbleToPullImageCreateRegistryRepository.
@Test
public void shouldBeAbleToPullImageCreateRegistryRepository() throws IOException, InterruptedException {
PullParams pullParams = PullParams.create(IMAGE).withRegistry(REGISTRY);
when(dockerResponse.getInputStream()).thenReturn(new ByteArrayInputStream(STREAM_DATA_BYTES));
dockerConnector.pull(pullParams, progressMonitor);
verify(dockerConnectionFactory).openConnection(any(URI.class));
verify(dockerConnection).method(REQUEST_METHOD_POST);
verify(dockerConnection).path("/images/create");
verify(dockerConnection).query("fromImage", pullParams.getRegistry() + '/' + pullParams.getImage());
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.PullParams in project che by eclipse.
the class DockerConnectorTest method shouldThrowDockerExceptionWhilePullingImageIfResponseCodeIsNotSuccess.
@Test(expectedExceptions = DockerException.class, expectedExceptionsMessageRegExp = EXCEPTION_ERROR_MESSAGE)
public void shouldThrowDockerExceptionWhilePullingImageIfResponseCodeIsNotSuccess() throws IOException, InterruptedException {
PullParams pullParams = PullParams.create(IMAGE);
when(dockerResponse.getStatus()).thenReturn(RESPONSE_ERROR_CODE);
dockerConnector.pull(pullParams, progressMonitor);
verify(dockerResponse).getStatus();
}
Aggregations