@Test(dependsOnMethods = "testCreateImage") public void testInspectImage() { image = api.getImageApi().inspectImage(String.format("%s:%s", DEFAULT_IMAGE, DEFAULT_TAG)); assertNotNull(image); }
@Test(dependsOnMethods = "testListImages", alwaysRun = true) public void testDeleteImage() { consumeStream(api().deleteImage(String.format("%s:%s", DEFAULT_IMAGE, DEFAULT_TAG))); assertNull(api().inspectImage(String.format("%s:%s", DEFAULT_IMAGE, DEFAULT_TAG))); assertNotNull(api().inspectImage(image.id()), "Image should should still exist after removing original tag. There is a newly added tag referencing it."); consumeStream(api().deleteImage("jclouds:testTag")); assertNull(api().inspectImage("jclouds:testTag")); }
public void testGetImageNotHiddenByCache() { // Ensure image to be tested is unknown to jclouds and docker and that // cache is warm assertNull(findImageFromListImages(CHUANWEN_COWSAY)); assertNull(api.getImageApi().inspectImage(CHUANWEN_COWSAY)); // Get new image adapter.getImage(CHUANWEN_COWSAY); assertNotNull(findImageFromListImages(CHUANWEN_COWSAY), "New image is not available from listImages presumably due to caching"); }
@BeforeClass protected void init() { if (api.getImageApi().inspectImage(ALPINE_IMAGE_TAG) == null) { CreateImageOptions options = CreateImageOptions.Builder.fromImage(ALPINE_IMAGE_TAG); InputStream createImageStream = api.getImageApi().createImage(options); consumeStream(createImageStream); } image = api.getImageApi().inspectImage(ALPINE_IMAGE_TAG); assertNotNull(image); }
/** * Removes Docker image if it's present on the Docker host. Docker Image API * is used to inspect and remove image (({@link ImageApi#deleteImage(String)} * method). * * @param dockerApi * DockerApi instance (must be not-<code>null</code>) * @param imageName * image to be deleted (must be not-<code>null</code>) */ public static void removeImageIfExists(DockerApi dockerApi, String imageName) { Preconditions.checkNotNull(dockerApi, "DockerApi instance has to be provided"); Preconditions.checkNotNull(imageName, "Docker image name has to be provided"); final ImageApi imageApi = dockerApi.getImageApi(); if (null != imageApi.inspectImage(imageName)) { consumeStreamSilently(imageApi.deleteImage(imageName, DeleteImageOptions.Builder.force(true))); } } }
@Test(dependsOnMethods = "testInspectImage") public void testTagImage() { api.getImageApi().tagImage(image.id(), "jclouds", "testTag", true); Image taggedImage = api.getImageApi().inspectImage("jclouds:testTag"); assertEquals(taggedImage.id(), image.id(), "Newly added image tag should point to the same image ID."); }
/** * Method based on {@link org.jclouds.docker.features.ImageApi#listImages()}. It retrieves additional * information by inspecting each image. * * @see org.jclouds.compute.ComputeServiceAdapter#listImages() */ @Override public Set<Image> listImages() { Set<Image> images = Sets.newHashSet(); for (ImageSummary imageSummary : api.getImageApi().listImages()) { // less efficient than just listImages but returns richer json that needs repoTags coming from listImages Image inspected = api.getImageApi().inspectImage(imageSummary.id()); inspected = Image.create(inspected.id(), inspected.author(), inspected.comment(), inspected.config(), inspected.containerConfig(), inspected.parent(), inspected.created(), inspected.container(), inspected.dockerVersion(), inspected.architecture(), inspected.os(), inspected.size(), inspected.virtualSize(), imageSummary.repoTags()); images.add(inspected); } return images; }
/** * Method based on {@link org.jclouds.docker.features.ImageApi#listImages()}. It retrieves additional * information by inspecting each image. * * @see org.jclouds.compute.ComputeServiceAdapter#listImages() */ @Override public Set<Image> listImages() { Set<Image> images = Sets.newHashSet(); for (ImageSummary imageSummary : api.getImageApi().listImages()) { // less efficient than just listImages but returns richer json that needs repoTags coming from listImages Image inspected = api.getImageApi().inspectImage(imageSummary.id()); inspected = Image.create(inspected.id(), inspected.author(), inspected.comment(), inspected.config(), inspected.containerConfig(), inspected.parent(), inspected.created(), inspected.container(), inspected.dockerVersion(), inspected.architecture(), inspected.os(), inspected.size(), inspected.virtualSize(), imageSummary.repoTags()); images.add(inspected); } return images; }
/** * Method based on {@link org.jclouds.docker.features.ImageApi#listImages()}. It retrieves additional * information by inspecting each image. * * @see org.jclouds.compute.ComputeServiceAdapter#listImages() */ @Override public Set<Image> listImages() { Set<Image> images = Sets.newHashSet(); for (ImageSummary imageSummary : api.getImageApi().listImages()) { // less efficient than just listImages but returns richer json that needs repoTags coming from listImages Image inspected = api.getImageApi().inspectImage(imageSummary.id()); inspected = Image.create(inspected.id(), inspected.author(), inspected.comment(), inspected.config(), inspected.containerConfig(), inspected.parent(), inspected.created(), inspected.container(), inspected.dockerVersion(), inspected.architecture(), inspected.os(), inspected.size(), inspected.virtualSize(), imageSummary.repoTags()); images.add(inspected); } return images; }
/** * Method based on {@link org.jclouds.docker.features.ImageApi#listImages()}. It retrieves additional * information by inspecting each image. * * @see org.jclouds.compute.ComputeServiceAdapter#listImages() */ @Override public Set<Image> listImages() { Set<Image> images = Sets.newHashSet(); for (ImageSummary imageSummary : api.getImageApi().listImages()) { // less efficient than just listImages but returns richer json that needs repoTags coming from listImages Image inspected = api.getImageApi().inspectImage(imageSummary.id()); inspected = Image.create(inspected.id(), inspected.author(), inspected.comment(), inspected.config(), inspected.containerConfig(), inspected.parent(), inspected.created(), inspected.container(), inspected.dockerVersion(), inspected.architecture(), inspected.os(), inspected.size(), inspected.virtualSize(), imageSummary.repoTags()); images.add(inspected); } return images; }
@BeforeClass protected void init() { if (api.getImageApi().inspectImage(ALPINE_IMAGE_TAG) == null) { CreateImageOptions options = CreateImageOptions.Builder.fromImage(ALPINE_IMAGE_TAG); InputStream createImageStream = api.getImageApi().createImage(options); consumeStream(createImageStream); } image = api.getImageApi().inspectImage(ALPINE_IMAGE_TAG); assertNotNull(image); Config containerConfig = Config.builder().image(image.id()) .cmd(ImmutableList.of("/bin/sh", "-c", "touch hello; while true; do echo hello world; sleep 1; done")) .build(); container = api.getContainerApi().createContainer("miscApiTest", containerConfig); assertNotNull(container); api.getContainerApi().startContainer(container.id()); assertTrue(api.getContainerApi().inspectContainer(container.id()).state().running()); }
public void testGetImage() throws Exception { MockWebServer server = mockWebServer(new MockResponse().setBody(payloadFromResource("/image.json"))); ImageApi api = api(DockerApi.class, server.getUrl("/").toString(), new DockerParserModule()).getImageApi(); try { String imageId = "cbba6639a342646deed70d7ea6162fa2a0acea9300f911f4e014555fe37d3456"; assertEquals(api.inspectImage(imageId), new ImageParseTest().expected()); assertSent(server, "GET", "/images/" + imageId + "/json"); } finally { server.shutdown(); } }
@BeforeClass protected void init() { if (api.getImageApi().inspectImage(ALPINE_IMAGE_TAG) == null) { CreateImageOptions options = CreateImageOptions.Builder.fromImage(ALPINE_IMAGE_TAG); InputStream createImageStream = api.getImageApi().createImage(options); consumeStream(createImageStream); } image = api.getImageApi().inspectImage(ALPINE_IMAGE_TAG); assertNotNull(image); Config containerConfig = Config.builder().image(image.id()) .cmd(ImmutableList.of("sh", "-c", "touch hello; while true; do echo hello world; sleep 1; done")) .build(); container = api.getContainerApi().createContainer("jclouds-test-network", containerConfig); api.getContainerApi().startContainer(container.id()); container = api.getContainerApi().inspectContainer(container.id()); }
protected Template buildTemplate(TemplateBuilder templateBuilder) { String imageName = SSHABLE_IMAGE + ":" + SSHABLE_IMAGE_TAG; org.jclouds.docker.domain.Image image = imageApi().inspectImage(imageName); if (image == null) { CreateImageOptions options = CreateImageOptions.Builder.fromImage(SSHABLE_IMAGE).tag(SSHABLE_IMAGE_TAG); imageApi().createImage(options); } image = imageApi().inspectImage(imageName); defaultImage = client.getImage(image.id()); DockerTemplateOptions options = new DockerTemplateOptions(); options.env(ImmutableList.of("ROOT_PASS=password")); options.overrideLoginCredentials(LoginCredentials.builder().identity("root").credential("password").build()); template = templateBuilder.imageId(defaultImage.getId()).options(options).build(); return template; }
@AfterClass(alwaysRun = true) protected void tearDown() { if (guest != null) { adapter.destroyNode(guest.getNode().id() + ""); } if (api.getImageApi().inspectImage(CHUANWEN_COWSAY) != null) { api.getImageApi().deleteImage(CHUANWEN_COWSAY); } if (api.getNetworkApi().inspectNetwork("network1") != null) { api.getNetworkApi().removeNetwork("network1"); } if (api.getNetworkApi().inspectNetwork("network2") != null) { api.getNetworkApi().removeNetwork("network2"); } super.tearDown(); }
/** * Build a new image with 2 tags on it in the test preparation phase. * * @see org.jclouds.apis.BaseContextLiveTest#setupContext() */ @Override @BeforeClass(groups = { "integration", "live" }) public void setupContext() { super.setupContext(); final String tag = toTag(IMAGE_REPOSITORY, IMAGE_TAG_1); removeImageIfExists(api(), tag); removeImageIfExists(api(), toTag(IMAGE_REPOSITORY, IMAGE_TAG_2)); BuildOptions options = BuildOptions.Builder.tag(tag).verbose(false).nocache(false); InputStream buildImageStream; try { buildImageStream = api().getMiscApi().build(BaseDockerApiLiveTest.tarredDockerfile(), options); consumeStreamSilently(buildImageStream); } catch (IOException e) { throw new RuntimeException("Error occured during building Docker image.", e); } image = api().getImageApi().inspectImage(tag); api().getImageApi().tagImage(image.id(), IMAGE_REPOSITORY, IMAGE_TAG_2, true); }