Search in sources :

Example 6 with Image

use of com.spotify.docker.client.messages.Image in project linuxtools by eclipse.

the class VariablesTest method setUpForMockito.

private void setUpForMockito() throws DockerException, InterruptedException {
    // images to use
    final Image image = MockImageFactory.id("1a2b3c4d5e6f7g").name(IMAGE_UHTTPD + ":" + IMAGE_TAG_LATEST).build();
    final ImageInfo imageInfo = MockImageInfoFactory.volume("/foo/bar").command(Arrays.asList("the", "command")).entrypoint(Arrays.asList("the", "entrypoint")).env(Arrays.asList("FOO", "barbarbar")).build();
    // container to be created
    this.createdContainer = MockContainerFactory.id("1MockContainer").name(CONTAINER_NAME).imageName("1a2b3c4d5e6f7g").status("Started 1 second ago").build();
    this.containerInfo = MockContainerInfoFactory.privilegedMode(true).id("TestTestTestTestTest").ipAddress("127.0.0.1").build();
    this.client = MockDockerClientFactory.image(image, imageInfo).build();
    final DockerConnection dockerConnection = MockDockerConnectionFactory.from(DEFAULT_CONNECTION_NAME, client).withDefaultTCPConnectionSettings();
    // configure the Connection Manager
    MockDockerConnectionManager.configureConnectionManager(dockerConnection);
}
Also used : DockerConnection(org.eclipse.linuxtools.internal.docker.core.DockerConnection) Image(com.spotify.docker.client.messages.Image) ImageInfo(com.spotify.docker.client.messages.ImageInfo)

Example 7 with Image

use of com.spotify.docker.client.messages.Image in project linuxtools by eclipse.

the class HierarchyViewTest method buildImage.

public void buildImage() {
    final Image rootImage = MockImageFactory.id("sha256:alpine:3.3").name("alpine:3.3").build();
    final Image fooImage1 = MockImageFactory.id("sha256:" + IMAGE_TEST_BUILD + NAME_TAG_SEPARATOR + IMAGE_TAG_LATEST).name(IMAGE_TEST_BUILD + NAME_TAG_SEPARATOR + IMAGE_TAG_LATEST).parentId("sha256:alpine:3.3").build();
    final DockerClient client = MockDockerClientFactory.image(rootImage).image(fooImage1).build();
    this.connection = MockDockerConnectionFactory.from(DEFAULT_CONNECTION_NAME, client).withDefaultTCPConnectionSettings();
    this.connection.getImages(true);
    this.connection.getContainers(true);
    MockDockerConnectionManager.configureConnectionManager(connection);
}
Also used : DockerClient(com.spotify.docker.client.DockerClient) Image(com.spotify.docker.client.messages.Image)

Example 8 with Image

use of com.spotify.docker.client.messages.Image in project linuxtools by eclipse.

the class DockerConnection method listImages.

// TODO: remove this method from the API
@Override
public List<IDockerImage> listImages() throws DockerException {
    final List<IDockerImage> tempImages = new ArrayList<>();
    synchronized (imageLock) {
        try {
            final List<Image> nativeImages = new ArrayList<>();
            synchronized (clientLock) {
                // containers list left in the queue
                if (client == null) {
                    // there's no client.
                    return Collections.emptyList();
                }
                nativeImages.addAll(client.listImages(DockerClient.ListImagesParam.allImages()));
            }
            // images.
            for (Image nativeImage : nativeImages) {
                final DockerImageQualifier imageQualifier = resolveQualifier(nativeImage, nativeImages);
                // return one IDockerImage per raw image
                final List<String> repoTags = (nativeImage.repoTags() != null) ? new ArrayList<>(nativeImage.repoTags()) : new ArrayList<>();
                Collections.sort(repoTags);
                if (repoTags.isEmpty()) {
                    // $NON-NLS-1$
                    repoTags.add("<none>:<none>");
                }
                final String repo = DockerImage.extractRepo(repoTags.get(0));
                final List<String> tags = Arrays.asList(DockerImage.extractTag(repoTags.get(0)));
                tempImages.add(new DockerImage(this, repoTags, repo, tags, nativeImage.id(), nativeImage.parentId(), nativeImage.created(), nativeImage.size(), nativeImage.virtualSize(), imageQualifier));
            }
        } catch (com.spotify.docker.client.exceptions.DockerTimeoutException e) {
            if (isOpen()) {
                Activator.log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, Messages.Docker_Connection_Timeout, e));
                close();
            }
        } catch (com.spotify.docker.client.exceptions.DockerRequestException e) {
            throw new DockerException(e.message());
        } catch (com.spotify.docker.client.exceptions.DockerException | InterruptedException e) {
            if (isOpen() && e.getCause() != null && e.getCause().getCause() != null && e.getCause().getCause() instanceof ProcessingException) {
                close();
            } else {
                throw new DockerException(NLS.bind(Messages.List_Docker_Images_Failure, this.getName()), e);
            }
        } finally {
            this.images = tempImages;
        }
    }
    // Perform notification outside of lock so that listener doesn't cause a
    // deadlock to occur
    notifyImageListeners(tempImages);
    return tempImages;
}
Also used : Status(org.eclipse.core.runtime.Status) EnumDockerLoggingStatus(org.eclipse.linuxtools.docker.core.EnumDockerLoggingStatus) IStatus(org.eclipse.core.runtime.IStatus) DockerException(org.eclipse.linuxtools.docker.core.DockerException) DockerImageQualifier(org.eclipse.linuxtools.internal.docker.core.DockerImage.DockerImageQualifier) ArrayList(java.util.ArrayList) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) Image(com.spotify.docker.client.messages.Image) DockerTimeoutException(com.spotify.docker.client.exceptions.DockerTimeoutException) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) IDockerImage(org.eclipse.linuxtools.docker.core.IDockerImage) ProcessingException(javax.ws.rs.ProcessingException)

Example 9 with Image

use of com.spotify.docker.client.messages.Image in project docker-client by spotify.

the class DefaultDockerClientTest method testCreate.

@Test
public void testCreate() throws Exception {
    // Ensure the local Docker instance has the busybox image so that save() will work
    sut.pull(BUSYBOX_LATEST);
    final File imageFile = save(BUSYBOX);
    final String image = BUSYBOX + "test" + System.nanoTime();
    try (InputStream imagePayload = new BufferedInputStream(new FileInputStream(imageFile))) {
        sut.create(image, imagePayload);
    }
    final Collection<Image> images = Collections2.filter(sut.listImages(), new Predicate<Image>() {

        @Override
        public boolean apply(final Image img) {
            return img.repoTags() != null && img.repoTags().contains(image + ":latest");
        }
    });
    assertThat(images.size(), greaterThan(0));
    for (final Image img : images) {
        sut.removeImage(img.id());
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) TarArchiveInputStream(org.apache.commons.compress.archivers.tar.TarArchiveInputStream) InputStream(java.io.InputStream) Long.toHexString(java.lang.Long.toHexString) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.containsString(org.hamcrest.Matchers.containsString) Image(com.spotify.docker.client.messages.Image) RemovedImage(com.spotify.docker.client.messages.RemovedImage) SecretFile(com.spotify.docker.client.messages.swarm.SecretFile) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 10 with Image

use of com.spotify.docker.client.messages.Image in project docker-client by spotify.

the class DefaultDockerClientTest method testImageLabels.

@Test
public void testImageLabels() throws Exception {
    requireDockerApiVersionAtLeast("1.17", "image labels");
    final Path dockerDirectory = getResource("dockerDirectoryWithImageLabels");
    // Create test images
    final String barName = randomName();
    final String barId = sut.build(dockerDirectory.resolve("barDir"), barName);
    final String bazName = randomName();
    final String bazId = sut.build(dockerDirectory.resolve("bazDir"), bazName);
    // Check that both test images are listed when we filter with a "name" label
    final List<Image> nameImages = sut.listImages(ListImagesParam.withLabel("name"));
    final List<String> nameIds = dockerApiVersionLessThan("1.22") ? imagesToShortIds(nameImages) : imagesToShortIdsAndRemoveSha256(nameImages);
    assertThat(barId, isIn(nameIds));
    assertThat(bazId, isIn(nameIds));
    // Check that the first image is listed when we filter with a "foo=bar" label
    final List<Image> barImages = sut.listImages(ListImagesParam.withLabel("foo", "bar"));
    final List<String> barIds = dockerApiVersionLessThan("1.22") ? imagesToShortIds(barImages) : imagesToShortIdsAndRemoveSha256(barImages);
    assertThat(barId, isIn(barIds));
    // Check that we find the first image again when searching with the full
    // set of labels in a Map
    final List<Image> barImages2 = sut.listImages(ListImagesParam.withLabel("foo", "bar"), ListImagesParam.withLabel("name", "testtesttest"));
    final List<String> barIds2 = dockerApiVersionLessThan("1.22") ? imagesToShortIds(barImages2) : imagesToShortIdsAndRemoveSha256(barImages2);
    assertThat(barId, isIn(barIds2));
    // Check that the second image is listed when we filter with a "foo=baz" label
    final List<Image> bazImages = sut.listImages(ListImagesParam.withLabel("foo", "baz"));
    final List<String> bazIds = dockerApiVersionLessThan("1.22") ? imagesToShortIds(bazImages) : imagesToShortIdsAndRemoveSha256(bazImages);
    assertThat(bazId, isIn(bazIds));
    // Check that no containers are listed when we filter with a "foo=qux" label
    final List<Image> quxImages = sut.listImages(ListImagesParam.withLabel("foo", "qux"));
    assertThat(quxImages, hasSize(0));
    // Clean up test images
    sut.removeImage(barName, true, true);
    sut.removeImage(bazName, true, true);
}
Also used : Path(java.nio.file.Path) Long.toHexString(java.lang.Long.toHexString) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.containsString(org.hamcrest.Matchers.containsString) Image(com.spotify.docker.client.messages.Image) RemovedImage(com.spotify.docker.client.messages.RemovedImage) Test(org.junit.Test)

Aggregations

Image (com.spotify.docker.client.messages.Image)14 DockerClient (com.spotify.docker.client.DockerClient)7 Test (org.junit.Test)7 IDockerImage (org.eclipse.linuxtools.docker.core.IDockerImage)6 Container (com.spotify.docker.client.messages.Container)4 DockerException (com.spotify.docker.client.exceptions.DockerException)3 RemovedImage (com.spotify.docker.client.messages.RemovedImage)3 Long.toHexString (java.lang.Long.toHexString)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)3 ContainerCreation (com.spotify.docker.client.messages.ContainerCreation)2 ContainerInfo (com.spotify.docker.client.messages.ContainerInfo)2 ImageInfo (com.spotify.docker.client.messages.ImageInfo)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 IDockerContainer (org.eclipse.linuxtools.docker.core.IDockerContainer)2 DockerConnection (org.eclipse.linuxtools.internal.docker.core.DockerConnection)2 Before (org.junit.Before)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1