use of com.github.dockerjava.api.command.PullImageCmd in project camel by apache.
the class AsyncDockerProducer method executePullImageRequest.
/**
* Produces a pull image request
*
* @param client
* @param message
* @return
*/
private PullImageCmd executePullImageRequest(DockerClient client, Message message) {
LOGGER.debug("Executing Docker Pull Image Request");
String repository = DockerHelper.getProperty(DockerConstants.DOCKER_REPOSITORY, configuration, message, String.class);
ObjectHelper.notNull(repository, "Repository must be specified");
PullImageCmd pullImageCmd = client.pullImageCmd(repository);
String registry = DockerHelper.getProperty(DockerConstants.DOCKER_REGISTRY, configuration, message, String.class);
if (registry != null) {
pullImageCmd.withRegistry(registry);
}
String tag = DockerHelper.getProperty(DockerConstants.DOCKER_TAG, configuration, message, String.class);
if (tag != null) {
pullImageCmd.withTag(tag);
}
AuthConfig authConfig = client.authConfig();
if (authConfig != null) {
pullImageCmd.withAuthConfig(authConfig);
}
return pullImageCmd;
}
use of com.github.dockerjava.api.command.PullImageCmd in project dockerunit by qzagarese.
the class DefaultServiceBuilder method pullImage.
private CompletableFuture<Void> pullImage(CreateContainerCmd cmd, DockerClient client) {
PullImageCmd pullImageCmd = client.pullImageCmd(cmd.getImage());
CompletableFuture<Void> pullFut = new CompletableFuture<Void>();
ResultCallback<PullResponseItem> resultCallback = new ResultCallback<PullResponseItem>() {
private Closeable closeable;
@Override
public void close() throws IOException {
try {
closeable.close();
} catch (IOException e) {
throw new RuntimeException("Cannot close closeable " + closeable, e);
}
}
@Override
public void onStart(Closeable closeable) {
this.closeable = closeable;
}
@Override
public void onNext(PullResponseItem object) {
if (object.getId() != null) {
logger.info("Pulling image " + object.getId() + "...");
}
}
@Override
public void onError(Throwable throwable) {
pullFut.completeExceptionally(new RuntimeException("Failed pulling image " + cmd.getImage(), throwable));
}
@Override
public void onComplete() {
pullFut.complete(null);
}
};
pullImageCmd.exec(resultCallback);
return pullFut;
}
use of com.github.dockerjava.api.command.PullImageCmd in project hub-docker-inspector by blackducksoftware.
the class DockerClientManager method pullImage.
public String pullImage(final String imageName, final String tagName) throws HubIntegrationException {
logger.info(String.format("Pulling image %s:%s", imageName, tagName));
final DockerClient dockerClient = hubDockerClient.getDockerClient();
final Image alreadyPulledImage = getLocalImage(dockerClient, imageName, tagName);
if (alreadyPulledImage == null) {
// Only pull if we dont already have it
final PullImageCmd pull = dockerClient.pullImageCmd(imageName).withTag(tagName);
try {
pull.exec(new PullImageResultCallback()).awaitSuccess();
} catch (final NotFoundException e) {
final String msg = String.format("Pull failed: Image %s:%s not found. Please check the image name/tag", imageName, tagName);
logger.error(msg);
throw new HubIntegrationException(msg, e);
}
final Image justPulledImage = getLocalImage(dockerClient, imageName, tagName);
if (justPulledImage == null) {
final String msg = String.format("Pulled image %s:%s not found in image list.", imageName, tagName);
logger.error(msg);
throw new HubIntegrationException(msg);
}
return justPulledImage.getId();
} else {
logger.info("Image already pulled");
return alreadyPulledImage.getId();
}
}
use of com.github.dockerjava.api.command.PullImageCmd in project vespa by vespa-engine.
the class DockerImplTest method pullImageAsyncIfNeededSuccessfully.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void pullImageAsyncIfNeededSuccessfully() {
final DockerImage image = new DockerImage("test:1.2.3");
InspectImageResponse inspectImageResponse = mock(InspectImageResponse.class);
when(inspectImageResponse.getId()).thenReturn(image.asString());
InspectImageCmd imageInspectCmd = mock(InspectImageCmd.class);
when(imageInspectCmd.exec()).thenThrow(new NotFoundException("Image not found")).thenReturn(inspectImageResponse);
// Array to make it final
ArgumentCaptor<ResultCallback> resultCallback = ArgumentCaptor.forClass(ResultCallback.class);
PullImageCmd pullImageCmd = mock(PullImageCmd.class);
when(pullImageCmd.exec(resultCallback.capture())).thenReturn(null);
final DockerClient dockerClient = mock(DockerClient.class);
when(dockerClient.inspectImageCmd(image.asString())).thenReturn(imageInspectCmd);
when(dockerClient.pullImageCmd(eq(image.asString()))).thenReturn(pullImageCmd);
final DockerImpl docker = new DockerImpl(dockerClient);
docker.setMetrics(new MetricReceiverWrapper(MetricReceiver.nullImplementation));
assertTrue("Should return true, we just scheduled the pull", docker.pullImageAsyncIfNeeded(image));
assertTrue("Should return true, the pull i still ongoing", docker.pullImageAsyncIfNeeded(image));
assertTrue(docker.imageIsDownloaded(image));
resultCallback.getValue().onComplete();
assertFalse(docker.pullImageAsyncIfNeeded(image));
}
use of com.github.dockerjava.api.command.PullImageCmd in project vespa by vespa-engine.
the class DockerImpl method pullImageAsyncIfNeeded.
@Override
public boolean pullImageAsyncIfNeeded(final DockerImage image) {
try {
synchronized (monitor) {
if (scheduledPulls.contains(image))
return true;
if (imageIsDownloaded(image))
return false;
scheduledPulls.add(image);
PullImageCmd pullImageCmd = dockerClient.pullImageCmd(image.asString());
dockerRegistryCredentialsSupplier.flatMap(credentialsSupplier -> credentialsSupplier.getCredentials(image)).map(credentials -> new AuthConfig().withRegistryAddress(credentials.registry.toString()).withUsername(credentials.username).withPassword(credentials.password)).ifPresent(pullImageCmd::withAuthConfig);
logger.log(LogLevel.INFO, "Starting download of " + image.asString());
pullImageCmd.exec(new ImagePullCallback(image));
return true;
}
} catch (RuntimeException e) {
numberOfDockerDaemonFails.add();
throw new DockerException("Failed to pull image '" + image.asString() + "'", e);
}
}
Aggregations