Search in sources :

Example 1 with PullImageResultCallback

use of com.github.dockerjava.api.command.PullImageResultCallback in project appstore-be by EdgeGallery.

the class AppService method downloadAppImage.

/**
 * Downloads app image from repo.
 *
 * @param imageInfoList list of images
 */
public void downloadAppImage(List<SwImgDesc> imageInfoList) {
    String[] sourceRepoHost;
    for (SwImgDesc imageInfo : imageInfoList) {
        LOGGER.info("Download docker image {} ", imageInfo.getSwImage());
        sourceRepoHost = imageInfo.getSwImage().split("/");
        DockerClient dockerClient = getDockerClient(sourceRepoHost[0], devRepoUsername, devRepoPassword);
        try {
            dockerClient.pullImageCmd(imageInfo.getSwImage()).exec(new PullImageResultCallback()).awaitCompletion();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            LOGGER.error("Failed to pull image {}, errorMsg: {}", imageInfo.getSwImage(), e.getMessage());
            throw new AppException(PULL_IMAGE_ERR_MESSAGES, ResponseConst.RET_PULL_IMAGE_FAILED, imageInfo.getSwImage());
        } catch (Exception e) {
            LOGGER.error("failed to download image {}, image not found in repository, {}", imageInfo.getSwImage(), e.getMessage());
            throw new AppException(PULL_IMAGE_ERR_MESSAGES, ResponseConst.RET_PULL_IMAGE_FAILED, imageInfo.getSwImage());
        }
    }
    LOGGER.info("images to edge repo downloaded successfully");
}
Also used : AppException(org.edgegallery.appstore.domain.shared.exceptions.AppException) DockerClient(com.github.dockerjava.api.DockerClient) PullImageResultCallback(com.github.dockerjava.api.command.PullImageResultCallback) SwImgDesc(org.edgegallery.appstore.domain.model.app.SwImgDesc) AppException(org.edgegallery.appstore.domain.shared.exceptions.AppException) IOException(java.io.IOException) EntityNotFoundException(org.edgegallery.appstore.domain.shared.exceptions.EntityNotFoundException)

Example 2 with PullImageResultCallback

use of com.github.dockerjava.api.command.PullImageResultCallback in project blackduck-docker-inspector by blackducksoftware.

the class DockerClientManager method pullImage.

private String pullImage(String imageName, String tagName, PullImageCmd pull) throws IntegrationException, InterruptedException {
    try {
        pull.exec(new PullImageResultCallback()).awaitCompletion();
    } catch (NotFoundException e) {
        throw new BlackDuckIntegrationException(String.format("Pull failed: Image %s:%s not found. Please check the image name/tag. Error: %s", imageName, tagName, e.getMessage()), e);
    }
    Optional<Image> justPulledImage = getLocalImage(dockerClient, imageName, tagName);
    if (!justPulledImage.isPresent()) {
        String msg = String.format("Pulled image %s:%s not found in image list.", imageName, tagName);
        logger.error(msg);
        throw new BlackDuckIntegrationException(msg);
    }
    return justPulledImage.get().getId();
}
Also used : BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) PullImageResultCallback(com.github.dockerjava.api.command.PullImageResultCallback) NotFoundException(com.github.dockerjava.api.exception.NotFoundException) Image(com.github.dockerjava.api.model.Image)

Example 3 with PullImageResultCallback

use of com.github.dockerjava.api.command.PullImageResultCallback in project testcontainers-java by testcontainers.

the class ImagePullPolicyTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    String testRegistryAddress = registry.getEndpoint();
    String testImageName = testRegistryAddress + "/image-pull-policy-test";
    String tag = UUID.randomUUID().toString();
    imageName = DockerImageName.parse(testImageName).withTag(tag);
    DockerClient client = DockerClientFactory.instance().client();
    String dummySourceImage = "hello-world:latest";
    client.pullImageCmd(dummySourceImage).exec(new PullImageResultCallback()).awaitCompletion();
    String dummyImageId = client.inspectImageCmd(dummySourceImage).exec().getId();
    // push the image to the registry
    client.tagImageCmd(dummyImageId, testImageName, tag).exec();
    client.pushImageCmd(imageName.asCanonicalNameString()).exec(new ResultCallback.Adapter<>()).awaitCompletion(1, TimeUnit.MINUTES);
}
Also used : DockerClient(com.github.dockerjava.api.DockerClient) PullImageResultCallback(com.github.dockerjava.api.command.PullImageResultCallback) BeforeClass(org.junit.BeforeClass)

Example 4 with PullImageResultCallback

use of com.github.dockerjava.api.command.PullImageResultCallback in project testcontainers-java by testcontainers.

the class DockerRegistryContainer method createImage.

@SneakyThrows(InterruptedException.class)
public DockerImageName createImage(String originalImage, String tag) {
    DockerClient client = getDockerClient();
    client.pullImageCmd(originalImage).exec(new PullImageResultCallback()).awaitCompletion();
    String dummyImageId = client.inspectImageCmd(originalImage).exec().getId();
    DockerImageName imageName = DockerImageName.parse(getEndpoint() + "/" + Base58.randomString(6).toLowerCase()).withTag(tag);
    // push the image to the registry
    client.tagImageCmd(dummyImageId, imageName.asCanonicalNameString(), tag).exec();
    client.pushImageCmd(imageName.asCanonicalNameString()).exec(new ResultCallback.Adapter<>()).awaitCompletion(1, TimeUnit.MINUTES);
    // Remove from local cache, tests should pull the image themselves
    client.removeImageCmd(imageName.asCanonicalNameString()).exec();
    return imageName;
}
Also used : DockerImageName(org.testcontainers.utility.DockerImageName) DockerClient(com.github.dockerjava.api.DockerClient) PullImageResultCallback(com.github.dockerjava.api.command.PullImageResultCallback) SneakyThrows(lombok.SneakyThrows)

Example 5 with PullImageResultCallback

use of com.github.dockerjava.api.command.PullImageResultCallback in project synopsys-detect by blackducksoftware.

the class PullDockerImageProvider method installImage.

@Override
public void installImage(String imageName, DockerClient dockerClient) throws InterruptedException {
    PullImageResultCallback callback = new PullImageResultCallback();
    // I am not sure this is right, it says 'repository' in the args.
    dockerClient.pullImageCmd(imageName).exec(callback);
    callback.awaitCompletion();
}
Also used : PullImageResultCallback(com.github.dockerjava.api.command.PullImageResultCallback)

Aggregations

PullImageResultCallback (com.github.dockerjava.api.command.PullImageResultCallback)10 DockerClient (com.github.dockerjava.api.DockerClient)5 IOException (java.io.IOException)3 PullResponseItem (com.github.dockerjava.api.model.PullResponseItem)2 ProgressDetail (com.github.dockerjava.api.model.ResponseItem.ProgressDetail)2 ResultCallback (com.github.dockerjava.api.async.ResultCallback)1 CreateContainerResponse (com.github.dockerjava.api.command.CreateContainerResponse)1 LogContainerCmd (com.github.dockerjava.api.command.LogContainerCmd)1 PullImageCmd (com.github.dockerjava.api.command.PullImageCmd)1 SaveImageCmd (com.github.dockerjava.api.command.SaveImageCmd)1 WaitContainerResultCallback (com.github.dockerjava.api.command.WaitContainerResultCallback)1 NotFoundException (com.github.dockerjava.api.exception.NotFoundException)1 AuthConfig (com.github.dockerjava.api.model.AuthConfig)1 Bind (com.github.dockerjava.api.model.Bind)1 Frame (com.github.dockerjava.api.model.Frame)1 Image (com.github.dockerjava.api.model.Image)1 StreamType (com.github.dockerjava.api.model.StreamType)1 DefaultDockerClientConfig (com.github.dockerjava.core.DefaultDockerClientConfig)1 DockerClientBuilder (com.github.dockerjava.core.DockerClientBuilder)1 LogContainerResultCallback (com.github.dockerjava.core.command.LogContainerResultCallback)1