/** * Check whether the image is available locally and pull it otherwise */ public void checkAndPullImage(DockerClient client, String image) { List<Image> images = client.listImagesCmd().withImageNameFilter(image).exec(); if (images.isEmpty()) { client.pullImageCmd(image).exec(new PullImageResultCallback()).awaitSuccess(); } }
.pullImageCmd(imageName.getUnversionedPart()) .withTag(imageName.getVersionPart()) .exec(callback); callback.awaitCompletion(); AVAILABLE_IMAGE_NAME_CACHE.add(imageName);
private void tagImage(String sourceImage, String targetImage, String targetTag) throws InterruptedException { DockerClient client = DockerClientFactory.instance().client(); client.pullImageCmd(sourceImage).exec(new PullImageResultCallback()).awaitCompletion(); client.tagImageCmd(sourceImage, targetImage, targetTag).exec(); } }
public void pull(String image) { log.info("Pull Image " + image + " Start"); try { docker .pullImageCmd(image) .exec(new PullImageProcess()) .awaitCompletion(); } catch (InterruptedException e) { log.error("Pull Image Error", e); throw new PluginException("Pull Image Error"); } log.info("Pull Image " + image + " Success"); }
private void putImageInRegistry() throws InterruptedException { // It doesn't matter which image we use for this test, but use one that's likely to have been pulled already final String dummySourceImage = TestcontainersConfiguration.getInstance().getRyukImage(); client.pullImageCmd(dummySourceImage) .exec(new PullImageResultCallback()) .awaitCompletion(1, TimeUnit.MINUTES); final String id = client.inspectImageCmd(dummySourceImage) .exec() .getId(); // push the image to the registry client.tagImageCmd(id, testImageName, "latest").exec(); client.pushImageCmd(testImageNameWithTag) .exec(new PushImageResultCallback()) .awaitCompletion(1, TimeUnit.MINUTES); // remove the image tag from local docker so that it must be pulled before use client.removeImageCmd(testImageNameWithTag).withForce(true).exec(); } }
public void pullImage(String image){ dockerClient.pullImageCmd(image).exec(); }
public void pullImageIfNecessary(String imageId, boolean force) { if (imageId.isEmpty()) { return; } if (force || !existsImage(imageId)) { log.debug("Pulling Docker image {} ... please be patient until the process finishes", imageId); try { getClient().pullImageCmd(imageId).exec(new PullImageResultCallback()).awaitCompletion(); } catch (Exception e) { log.warn("Exception pulling image {}", imageId, e); } log.debug("Image {} downloaded", imageId); } else { log.debug("Image {} already exists", imageId); } }
public void pullImageIfNecessary(String imageId, boolean force) { if (imageId.isEmpty()) { return; } if (force || !existsImage(imageId)) { log.debug("Pulling Docker image {} ... please be patient until the process finishes", imageId); try { getClient().pullImageCmd(imageId).exec(new PullImageResultCallback()).awaitCompletion(); } catch (Exception e) { log.warn("Exception pulling image {}", imageId, e); } log.debug("Image {} downloaded", imageId); } else { log.debug("Image {} already exists", imageId); } }
private void pullImageIfNeeded() { final List<Image> images = client.listImagesCmd().withImageNameFilter(image).exec(); if (images.isEmpty()) { log.info("Pulling " + image); final String[] parts = image.split(":"); client.pullImageCmd(parts[0]).withTag(parts[1]).exec(new PullImageResultCallback()).awaitSuccess(); log.info(image + " pulled"); } }
public void pullImage(String imageName) { this.readWriteLock.readLock().lock(); try { final Image image = Image.valueOf(imageName); PullImageCmd pullImageCmd = this.dockerClient.pullImageCmd(image.getName()); String tag = image.getTag(); if (tag != null && !"".equals(tag)) { pullImageCmd.withTag(tag); } else { pullImageCmd.withTag("latest"); } pullImageCmd.exec(new PullImageResultCallback()).awaitSuccess(); } finally { this.readWriteLock.readLock().unlock(); } }
public void pullImage(String imageName) { this.readWriteLock.readLock().lock(); try { final Image image = Image.valueOf(imageName); PullImageCmd pullImageCmd = this.dockerClient.pullImageCmd(image.getName()); String tag = image.getTag(); if (tag != null && !"".equals(tag)) { pullImageCmd.withTag(tag); } else { pullImageCmd.withTag("latest"); } pullImageCmd.exec(new PullImageResultCallback()).awaitSuccess(); } finally { this.readWriteLock.readLock().unlock(); } }
@Override public boolean pullImageAsyncIfNeeded(DockerImage image) { try { synchronized (monitor) { if (scheduledPulls.contains(image)) return true; if (imageIsDownloaded(image)) return false; scheduledPulls.add(image); logger.log(LogLevel.INFO, "Starting download of " + image.asString()); dockerClient.pullImageCmd(image.asString()).exec(new ImagePullCallback(image)); return true; } } catch (RuntimeException e) { numberOfDockerDaemonFails.add(); throw new DockerException("Failed to pull image '" + image.asString() + "'", e); } }
/** * Pulls a Docker image with given name and version. Throws exception when it times out after given timeout. * * @param imageName image to pull * @param imageVersion image version to pull * @param timeoutSecs pulling timeout in seconds */ public static void pullImage(String imageName, String imageVersion, long timeoutSecs) { try { final CompletableFuture<Void> result = new CompletableFuture<>(); DockerClientFactory.build().pullImageCmd(imageName).withTag(imageVersion).exec(new PullImageResultCallback()).awaitCompletion(); } catch (InterruptedException | RuntimeException e) { throw new MinimesosException("Error pulling image or image not found in registry: " + imageName + ":" + imageVersion, e); } }
public Void call() throws Exception { final ConsoleLogger console = new ConsoleLogger(listener); DockerClient client = DockerCommand.getClient(descriptor, cfgData.dockerUrlRes, cfgData.dockerVersionRes, cfgData.dockerCertPathRes, authConfig); PullImageCmd pullImageCmd = client.pullImageCmd(fromImageRes); PullImageResultCallback callback = new PullImageResultCallback() { @Override public void onNext(PullResponseItem item) { console.logInfo(item.toString()); super.onNext(item); } @Override public void onError(Throwable throwable) { console.logError("Failed to exec start:" + throwable.getMessage()); super.onError(throwable); } }; pullImageCmd.exec(callback).awaitSuccess(); return null; }
private void ensureImageExists(String wantedImage) { try { dockerClient.inspectImageCmd(wantedImage).exec(); } catch (NotFoundException e) { dockerClient.pullImageCmd(wantedImage).exec(new PullImageResultCallback()).awaitSuccess(); } } }
protected void pullImage(DockerClient dockerClient) throws InterruptedException { try { // Pulling from remote is always slower than pulling from local try { dockerClient.inspectImageCmd(properties.getDockerImage()).exec(); } catch (NotFoundException e) { dockerClient.pullImageCmd(properties.getDockerImage()).exec(new PullImageResultCallback()).awaitCompletion(); } } // Ignore registry-problems and try to proceed with local image catch (InternalServerErrorException e) { log.warn("Failed to pull image from registry. Try to proceed with local image..", e); } }
final DockerRegistryEndpoint registry = getRegistry(); DockerCloud.setRegistryAuthentication(cmd, registry, Jenkins.getInstance()); cmd.exec(new PullImageResultCallback() { @Override public void onNext(PullResponseItem item) {
private void executePullOnDocker(Run<?, ?> build, PrintStream llog, String xImage, DockerClient client) throws DockerException { PullImageResultCallback resultCallback = new PullImageResultCallback() { @Override public void onNext(PullResponseItem item) { if (item.getStatus() != null && item.getProgress() == null) { llog.print(item.getId() + ":" + item.getStatus()); LOG.info("{} : {}", item.getId(), item.getStatus()); } super.onNext(item); } }; PullImageCmd cmd = client.pullImageCmd(xImage); DockerCloud.setRegistryAuthentication(cmd, getRegistry(), build.getParent().getParent()); try { cmd.exec(resultCallback).awaitCompletion(); } catch (InterruptedException e) { throw new DockerClientException("Interrupted while pulling image", e); } }
private void ensureImageExists(String wantedImage) { try { dockerClient.inspectImageCmd(wantedImage).exec(); } catch (NotFoundException e) { dockerClient.pullImageCmd(wantedImage).exec(new PullImageResultCallback()).awaitSuccess(); } }
/** * Pull docker image using the docker java client. * * @param imageTag * @param username * @param password * @param host */ public static void pullImage(String imageTag, String username, String password, String host) throws IOException { final AuthConfig authConfig = new AuthConfig(); authConfig.withUsername(username); authConfig.withPassword(password); DockerClient dockerClient = null; try { dockerClient = getDockerClient(host); dockerClient.pullImageCmd(imageTag).withAuthConfig(authConfig).exec(new PullImageResultCallback()).awaitSuccess(); } finally { closeQuietly(dockerClient); } }