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);
}
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);
}
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;
}
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());
}
}
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);
}
Aggregations