com.github.dockerjava.api.command.InspectImageResponse Java Examples
The following examples show how to use
com.github.dockerjava.api.command.InspectImageResponse.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BuildImageCmdIT.java From docker-java with Apache License 2.0 | 6 votes |
@Test public void multipleTags() throws Exception { assumeThat("API version should be >= 1.23", dockerRule, isGreaterOrEqual(VERSION_1_21)); File baseDir = fileFromBuildTestResource("labels"); String imageId = dockerRule.getClient().buildImageCmd(baseDir).withNoCache(true) .withTag("fallback-when-withTags-not-called") .withTags(new HashSet<>(Arrays.asList("docker-java-test:tag1", "docker-java-test:tag2"))) .start() .awaitImageId(); InspectImageResponse inspectImageResponse = dockerRule.getClient().inspectImageCmd(imageId).exec(); assertThat(inspectImageResponse, not(nullValue())); LOG.info("Image Inspect: {}", inspectImageResponse.toString()); assertThat(inspectImageResponse.getRepoTags().size(), equalTo(2)); assertThat(inspectImageResponse.getRepoTags(), containsInAnyOrder("docker-java-test:tag1", "docker-java-test:tag2")); }
Example #2
Source File: ApplicationContainer.java From microshed-testing with Apache License 2.0 | 6 votes |
public DefaultServerAdapter() { if (isHollow) { defaultHttpPort = -1; } else { InspectImageResponse imageData = DockerClientFactory.instance().client().inspectImageCmd(getDockerImageName()).exec(); LOG.info("Found exposed ports: " + Arrays.toString(imageData.getContainerConfig().getExposedPorts())); int bestChoice = -1; for (ExposedPort exposedPort : imageData.getContainerConfig().getExposedPorts()) { int port = exposedPort.getPort(); // If any ports end with 80, assume they are HTTP ports if (Integer.toString(port).endsWith("80")) { bestChoice = port; break; } else if (bestChoice == -1) { // if no ports match *80, then pick the first port bestChoice = port; } } defaultHttpPort = bestChoice; LOG.info("Automatically selecting default HTTP port: " + defaultHttpPort); } }
Example #3
Source File: JobTest.java From module-ballerina-kubernetes with Apache License 2.0 | 6 votes |
@Test public void testKubernetesJobNodeSelector() throws IOException, InterruptedException { Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "node_selector.bal"), 0); File dockerFile = DOCKER_TARGET_PATH.resolve("Dockerfile").toFile(); Assert.assertTrue(dockerFile.exists()); InspectImageResponse imageInspect = getDockerImage(DOCKER_IMAGE_NODE); Assert.assertNotNull(imageInspect.getConfig()); File jobYAML = KUBERNETES_TARGET_PATH.resolve("node_selector_job.yaml").toFile(); Job job = KubernetesTestUtils.loadYaml(jobYAML); Assert.assertEquals(job.getMetadata().getName(), "node-selector-job"); Assert.assertEquals(job.getSpec().getTemplate().getSpec().getContainers().size(), 1); Container container = job.getSpec().getTemplate().getSpec().getContainers().get(0); Assert.assertEquals(container.getImage(), DOCKER_IMAGE_NODE); Assert.assertEquals(container.getImagePullPolicy(), KubernetesConstants.ImagePullPolicy.IfNotPresent.name()); Assert.assertEquals(job.getSpec().getTemplate().getSpec() .getRestartPolicy(), KubernetesConstants.RestartPolicy.Never.name()); //Validate node selector Map<String, String> nodeSelectors = job.getSpec().getTemplate().getSpec().getNodeSelector(); Assert.assertEquals(nodeSelectors.size(), 1); Assert.assertEquals(nodeSelectors.get("disktype"), "ssd"); }
Example #4
Source File: JobTest.java From module-ballerina-kubernetes with Apache License 2.0 | 6 votes |
@Test public void testKubernetesJobGeneration() throws IOException, InterruptedException { Assert.assertEquals(KubernetesTestUtils.compileBallerinaFile(SOURCE_DIR_PATH, "ballerina_job.bal"), 0); File dockerFile = DOCKER_TARGET_PATH.resolve("Dockerfile").toFile(); Assert.assertTrue(dockerFile.exists()); InspectImageResponse imageInspect = getDockerImage(DOCKER_IMAGE_JOB); Assert.assertNotNull(imageInspect.getConfig()); File jobYAML = KUBERNETES_TARGET_PATH.resolve("ballerina_job_job.yaml").toFile(); Job job = KubernetesTestUtils.loadYaml(jobYAML); Assert.assertEquals(job.getMetadata().getName(), "ballerina-job-job"); Assert.assertEquals(job.getSpec().getTemplate().getSpec().getContainers().size(), 1); Container container = job.getSpec().getTemplate().getSpec().getContainers().get(0); Assert.assertEquals(container.getImage(), DOCKER_IMAGE_JOB); Assert.assertEquals(container.getImagePullPolicy(), KubernetesConstants.ImagePullPolicy.IfNotPresent.name()); Assert.assertEquals(job.getSpec().getTemplate().getSpec() .getRestartPolicy(), KubernetesConstants.RestartPolicy.Never.name()); }
Example #5
Source File: BuildImageCmdIT.java From docker-java with Apache License 2.0 | 6 votes |
@Test public void labels() throws Exception { assumeThat("API version should be >= 1.23", dockerRule, isGreaterOrEqual(VERSION_1_23)); File baseDir = fileFromBuildTestResource("labels"); String imageId = dockerRule.getClient().buildImageCmd(baseDir).withNoCache(true) .withLabels(Collections.singletonMap("test", "abc")) .start() .awaitImageId(); InspectImageResponse inspectImageResponse = dockerRule.getClient().inspectImageCmd(imageId).exec(); assertThat(inspectImageResponse, not(nullValue())); LOG.info("Image Inspect: {}", inspectImageResponse.toString()); assertThat(inspectImageResponse.getConfig().getLabels().get("test"), equalTo("abc")); }
Example #6
Source File: BuildImageCmdIT.java From docker-java with Apache License 2.0 | 6 votes |
@Test public void cacheFrom() throws Exception { assumeThat(dockerRule, isGreaterOrEqual(VERSION_1_27)); File baseDir1 = fileFromBuildTestResource("CacheFrom/test1"); String imageId1 = dockerRule.getClient().buildImageCmd(baseDir1) .start() .awaitImageId(); InspectImageResponse inspectImageResponse1 = dockerRule.getClient().inspectImageCmd(imageId1).exec(); assertThat(inspectImageResponse1, not(nullValue())); File baseDir2 = fileFromBuildTestResource("CacheFrom/test2"); String imageId2 = dockerRule.getClient().buildImageCmd(baseDir2).withCacheFrom(new HashSet<>(Arrays.asList(imageId1))) .start() .awaitImageId(); InspectImageResponse inspectImageResponse2 = dockerRule.getClient().inspectImageCmd(imageId2).exec(); assertThat(inspectImageResponse2, not(nullValue())); // Compare whether the image2's parent layer is from image1 so that cache is used assertThat(inspectImageResponse2.getParent(), equalTo(inspectImageResponse1.getId())); }
Example #7
Source File: BuildImageCmdIT.java From docker-java with Apache License 2.0 | 6 votes |
@Test public void extraHosts() { assumeThat(dockerRule, isGreaterOrEqual(VERSION_1_28)); File baseDir = fileFromBuildTestResource("labels"); String imageId = dockerRule.getClient() .buildImageCmd(baseDir) .withExtraHosts(new HashSet<>(Arrays.asList("host1"))) .start() .awaitImageId(); InspectImageResponse inspectImageResponse = dockerRule.getClient().inspectImageCmd(imageId).exec(); assertThat(inspectImageResponse, not(nullValue())); LOG.info("Image Inspect: {}", inspectImageResponse.toString()); }
Example #8
Source File: DockerTemplate.java From docker-plugin with MIT License | 6 votes |
@Restricted(NoExternalUse.class) public DockerTransientNode provisionNode(DockerAPI api, TaskListener listener) throws IOException, Descriptor.FormException, InterruptedException { try { final InspectImageResponse image = pullImage(api, listener); final String effectiveRemoteFsDir = getEffectiveRemoteFs(image); try(final DockerClient client = api.getClient()) { return doProvisionNode(api, client, effectiveRemoteFsDir, listener); } } catch (IOException | Descriptor.FormException | InterruptedException | RuntimeException ex) { final DockerCloud ourCloud = DockerCloud.findCloudForTemplate(this); final long milliseconds = ourCloud == null ? 0L : ourCloud.getEffectiveErrorDurationInMilliseconds(); if (milliseconds > 0L) { // if anything went wrong, disable ourselves for a while final String reason = "Template provisioning failed."; final DockerDisabled reasonForDisablement = getDisabled(); reasonForDisablement.disableBySystem(reason, milliseconds, ex); setDisabled(reasonForDisablement); } throw ex; } }
Example #9
Source File: InspectImageCmdExec.java From docker-java with Apache License 2.0 | 5 votes |
@Override protected InspectImageResponse execute(InspectImageCmd command) { WebTarget webResource = getBaseResource().path("/images/{id}/json").resolveTemplate("id", command.getImageId()); LOGGER.trace("GET: {}", webResource); return webResource.request().accept(MediaType.APPLICATION_JSON).get(new TypeReference<InspectImageResponse>() { }); }
Example #10
Source File: BuildImageCmdIT.java From docker-java with Apache License 2.0 | 5 votes |
@Test public void quiet() { File baseDir = fileFromBuildTestResource("labels"); String imageId = dockerRule.getClient() .buildImageCmd(baseDir) .withQuiet(true) .start() .awaitImageId(); InspectImageResponse inspectImageResponse = dockerRule.getClient().inspectImageCmd(imageId).exec(); assertThat(inspectImageResponse, not(nullValue())); assertThat(inspectImageResponse.getId(), endsWith(imageId)); LOG.info("Image Inspect: {}", inspectImageResponse.toString()); }
Example #11
Source File: DockerTemplate.java From docker-plugin with MIT License | 5 votes |
@Nonnull InspectImageResponse pullImage(DockerAPI api, TaskListener listener) throws IOException, InterruptedException { final String image = getFullImageId(); final boolean shouldPullImage; try(final DockerClient client = api.getClient()) { shouldPullImage = getPullStrategy().shouldPullImage(client, image); } if (shouldPullImage) { // TODO create a FlyWeightTask so end-user get visibility on pull operation progress LOGGER.info("Pulling image '{}'. This may take awhile...", image); long startTime = System.currentTimeMillis(); try(final DockerClient client = api.getClient(pullTimeout)) { final PullImageCmd cmd = client.pullImageCmd(image); final DockerRegistryEndpoint registry = getRegistry(); DockerCloud.setRegistryAuthentication(cmd, registry, Jenkins.getInstance()); cmd.exec(new PullImageResultCallback() { @Override public void onNext(PullResponseItem item) { super.onNext(item); listener.getLogger().println(item.getStatus()); } }).awaitCompletion(); } long pullTime = System.currentTimeMillis() - startTime; LOGGER.info("Finished pulling image '{}', took {} ms", image, pullTime); } final InspectImageResponse result; try(final DockerClient client = api.getClient()) { result = client.inspectImageCmd(image).exec(); } catch (NotFoundException e) { throw new DockerClientException("Could not pull image: " + image, e); } return result; }
Example #12
Source File: ImageFromDockerfileTest.java From testcontainers-java with MIT License | 5 votes |
@Test public void shouldAddDefaultLabels() { ImageFromDockerfile image = new ImageFromDockerfile() .withDockerfileFromBuilder(it -> it.from("scratch")); String imageId = image.resolve(); DockerClient dockerClient = DockerClientFactory.instance().client(); InspectImageResponse inspectImageResponse = dockerClient.inspectImageCmd(imageId).exec(); assertThat(inspectImageResponse.getConfig().getLabels()) .containsAllEntriesOf(DockerClientFactory.DEFAULT_LABELS); }
Example #13
Source File: BuildImageCmdIT.java From docker-java with Apache License 2.0 | 5 votes |
@Test public void buildArgs() throws Exception { File baseDir = fileFromBuildTestResource("buildArgs"); String imageId = dockerRule.getClient().buildImageCmd(baseDir).withNoCache(true).withBuildArg("testArg", "abc !@#$%^&*()_+") .start() .awaitImageId(); InspectImageResponse inspectImageResponse = dockerRule.getClient().inspectImageCmd(imageId).exec(); assertThat(inspectImageResponse, not(nullValue())); LOG.info("Image Inspect: {}", inspectImageResponse.toString()); assertThat(inspectImageResponse.getConfig().getLabels().get("test"), equalTo("abc !@#$%^&*()_+")); }
Example #14
Source File: BuildImageCmdIT.java From docker-java with Apache License 2.0 | 5 votes |
@Test public void author() throws Exception { String imageId = dockerRule.buildImage(fileFromBuildTestResource("AUTHOR")); InspectImageResponse inspectImageResponse = dockerRule.getClient().inspectImageCmd(imageId).exec(); assertThat(inspectImageResponse, not(nullValue())); LOG.info("Image Inspect: {}", inspectImageResponse.toString()); assertThat(inspectImageResponse.getAuthor(), equalTo("Guillaume J. Charmes \"[email protected]\"")); }
Example #15
Source File: CommitCmdIT.java From docker-java with Apache License 2.0 | 5 votes |
@Test public void commitWithLabels() throws DockerException { CreateContainerResponse container = dockerRule.getClient().createContainerCmd("busybox") .withCmd("touch", "/test") .exec(); LOG.info("Created container: {}", container.toString()); assertThat(container.getId(), not(is(emptyString()))); dockerRule.getClient().startContainerCmd(container.getId()).exec(); Integer status = dockerRule.getClient().waitContainerCmd(container.getId()) .start() .awaitStatusCode(); assertThat(status, is(0)); LOG.info("Committing container: {}", container.toString()); Map<String, String> labels = ImmutableMap.of("label1", "abc", "label2", "123"); String imageId = dockerRule.getClient().commitCmd(container.getId()) .withLabels(labels) .exec(); InspectImageResponse inspectImageResponse = dockerRule.getClient().inspectImageCmd(imageId).exec(); LOG.info("Image Inspect: {}", inspectImageResponse.toString()); //use config here since containerConfig contains the configuration of the container which was //committed to the container //https://stackoverflow.com/questions/36216220/what-is-different-of-config-and-containerconfig-of-docker-inspect Map<String, String> responseLabels = inspectImageResponse.getConfig().getLabels(); //swarm will attach additional labels here assertThat(responseLabels.size(), greaterThanOrEqualTo(2)); assertThat(responseLabels.get("label1"), equalTo("abc")); assertThat(responseLabels.get("label2"), equalTo("123")); }
Example #16
Source File: DockerTemplate.java From docker-plugin with MIT License | 5 votes |
@Nonnull private String getEffectiveRemoteFs(final InspectImageResponse image) { final String remoteFsOrNull = getRemoteFs(); if (remoteFsOrNull != null) { return remoteFsOrNull; } final ContainerConfig containerConfig = image.getContainerConfig(); final String containerWorkingDir = containerConfig == null ? null : containerConfig.getWorkingDir(); if (!StringUtils.isBlank(containerWorkingDir)) { return containerWorkingDir; } return "/"; }
Example #17
Source File: DockerImagePullStrategyTest.java From docker-plugin with MIT License | 5 votes |
private DockerClient mockDockerClient() { InspectImageCmd cmd = mock(InspectImageCmd.class); if (existedImage) when(cmd.exec()).thenReturn(mock(InspectImageResponse.class)); else when(cmd.exec()).thenThrow(new NotFoundException("not found")); DockerClient dockerClient = mock(DockerClient.class); when(dockerClient.inspectImageCmd(imageName)).thenReturn(cmd); return dockerClient; }
Example #18
Source File: CommitCmdIT.java From docker-java with Apache License 2.0 | 5 votes |
@Test public void commit() throws DockerException, InterruptedException { CreateContainerResponse container = dockerRule.getClient().createContainerCmd(DEFAULT_IMAGE) .withCmd("touch", "/test") .exec(); LOG.info("Created container: {}", container.toString()); assertThat(container.getId(), not(is(emptyString()))); dockerRule.getClient().startContainerCmd(container.getId()).exec(); LOG.info("Committing container: {}", container.toString()); String imageId = dockerRule.getClient().commitCmd(container.getId()).exec(); //swarm needs some time to reflect new images synchronized (this) { wait(5000); } InspectImageResponse inspectImageResponse = dockerRule.getClient().inspectImageCmd(imageId).exec(); LOG.info("Image Inspect: {}", inspectImageResponse.toString()); assertThat(inspectImageResponse, hasField("container", startsWith(container.getId()))); assertThat(inspectImageResponse.getContainerConfig().getImage(), equalTo(DEFAULT_IMAGE)); InspectImageResponse busyboxImg = dockerRule.getClient().inspectImageCmd("busybox").exec(); assertThat(inspectImageResponse.getParent(), equalTo(busyboxImg.getId())); }
Example #19
Source File: DockerTraceabilityReport.java From docker-traceability-plugin with MIT License | 5 votes |
public DockerTraceabilityReport(@Nonnull Event event, @Nonnull Info hostInfo, @CheckForNull InspectContainerResponse container, @CheckForNull String imageId, @CheckForNull String imageName, @CheckForNull InspectImageResponse image, @Nonnull List<String> parents, @CheckForNull String environment) { this.event = event; this.hostInfo = hostInfo; this.container = container; this.imageId = imageId; this.image = image; this.parents = new ArrayList<String>(parents); this.imageName = imageName; this.environment = environment; }
Example #20
Source File: ImageLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void givenListOfImages_whenInspectImage_thenMustReturnObject() { // given List<Image> images = dockerClient.listImagesCmd().exec(); Image image = images.get(0); // when InspectImageResponse imageResponse = dockerClient.inspectImageCmd(image.getId()).exec(); // then MatcherAssert.assertThat(imageResponse.getId(), Is.is(image.getId())); }
Example #21
Source File: DockerTestUtils.java From module-ballerina-docker with Apache License 2.0 | 5 votes |
/** * Get the list of commands of the docker image. * * @param imageName The docker image name. * @return The list of commands. */ public static List<String> getCommand(String imageName) { InspectImageResponse dockerImage = getDockerImage(imageName); if (null == dockerImage.getConfig() || null == dockerImage.getConfig().getCmd()) { return new ArrayList<>(); } return Arrays.asList(dockerImage.getConfig().getCmd()); }
Example #22
Source File: DockerTestUtils.java From module-ballerina-docker with Apache License 2.0 | 5 votes |
/** * Get the list of exposed ports of the docker image. * * @param imageName The docker image name. * @return Exposed ports. */ public static List<String> getExposedPorts(String imageName) { InspectImageResponse dockerImage = getDockerImage(imageName); if (null == dockerImage.getConfig() || null == dockerImage.getConfig().getExposedPorts()) { return new ArrayList<>(); } ExposedPort[] exposedPorts = dockerImage.getConfig().getExposedPorts(); return Arrays.stream(exposedPorts).map(ExposedPort::toString).collect(Collectors.toList()); }
Example #23
Source File: KubernetesTestUtils.java From module-ballerina-kubernetes with Apache License 2.0 | 5 votes |
/** * Get the list of exposed ports of the docker image. * * @param imageName The docker image name. * @return Exposed ports. */ public static List<String> getExposedPorts(String imageName) { InspectImageResponse dockerImage = getDockerImage(imageName); if (null == dockerImage.getConfig()) { return new ArrayList<>(); } ExposedPort[] exposedPorts = dockerImage.getConfig().getExposedPorts(); return Arrays.stream(exposedPorts).map(ExposedPort::toString).collect(Collectors.toList()); }
Example #24
Source File: KubernetesTestUtils.java From module-ballerina-kubernetes with Apache License 2.0 | 5 votes |
/** * Get the list of commands of the docker image. * * @param imageName The docker image name. * @return The list of commands. */ public static List<String> getCommand(String imageName) { InspectImageResponse dockerImage = getDockerImage(imageName); if (null == dockerImage.getConfig() || null == dockerImage.getConfig().getCmd()) { return new ArrayList<>(); } return Arrays.asList(dockerImage.getConfig().getCmd()); }
Example #25
Source File: KnativeTestUtils.java From module-ballerina-kubernetes with Apache License 2.0 | 5 votes |
/** * Get the list of exposed ports of the docker image. * * @param imageName The docker image name. * @return Exposed ports. */ public static List<String> getExposedPorts(String imageName) { InspectImageResponse dockerImage = getDockerImage(imageName); if (null == dockerImage.getConfig()) { return new ArrayList<>(); } ExposedPort[] exposedPorts = dockerImage.getConfig().getExposedPorts(); return Arrays.stream(exposedPorts).map(ExposedPort::toString).collect(Collectors.toList()); }
Example #26
Source File: KnativeTestUtils.java From module-ballerina-kubernetes with Apache License 2.0 | 5 votes |
/** * Get the list of commands of the docker image. * * @param imageName The docker image name. * @return The list of commands. */ public static List<String> getCommand(String imageName) { InspectImageResponse dockerImage = getDockerImage(imageName); if (null == dockerImage.getConfig() || null == dockerImage.getConfig().getCmd()) { return new ArrayList<>(); } return Arrays.asList(dockerImage.getConfig().getCmd()); }
Example #27
Source File: PrometheusTest.java From module-ballerina-kubernetes with Apache License 2.0 | 5 votes |
/** * Validate contents of the Dockerfile. */ public void validateDockerImage() throws DockerTestException, InterruptedException { InspectImageResponse imageInspect = getDockerImage(DOCKER_IMAGE); Assert.assertTrue(Arrays.toString(Objects.requireNonNull(imageInspect.getConfig()) .getCmd()).contains("--b7a.observability.enabled=true")); Assert.assertNotNull(imageInspect.getConfig(), "Image not found"); }
Example #28
Source File: DockerImplTest.java From vespa with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings({"unchecked", "rawtypes"}) public void pullImageAsyncIfNeededSuccessfully() { final DockerImage image = DockerImage.fromString("test:1.2.3"); InspectImageResponse inspectImageResponse = mock(InspectImageResponse.class); when(inspectImageResponse.getId()).thenReturn(image.asString()); InspectImageCmd imageInspectCmd = mock(InspectImageCmd.class); when(imageInspectCmd.exec()) .thenThrow(new NotFoundException("Image not found")) .thenReturn(inspectImageResponse); // Array to make it final ArgumentCaptor<ResultCallback> resultCallback = ArgumentCaptor.forClass(ResultCallback.class); PullImageCmd pullImageCmd = mock(PullImageCmd.class); when(pullImageCmd.exec(resultCallback.capture())).thenReturn(null); when(dockerClient.inspectImageCmd(image.asString())).thenReturn(imageInspectCmd); when(dockerClient.pullImageCmd(eq(image.asString()))).thenReturn(pullImageCmd); assertTrue("Should return true, we just scheduled the pull", docker.pullImageAsyncIfNeeded(image)); assertTrue("Should return true, the pull i still ongoing", docker.pullImageAsyncIfNeeded(image)); assertTrue(docker.imageIsDownloaded(image)); resultCallback.getValue().onComplete(); assertFalse(docker.pullImageAsyncIfNeeded(image)); }
Example #29
Source File: DefaultModeTest.java From module-ballerina-kubernetes with Apache License 2.0 | 4 votes |
/** * Validate contents of the Dockerfile. */ public void validateDockerImage(String image) throws DockerTestException, InterruptedException { InspectImageResponse imageInspect = getDockerImage(image); Assert.assertNotNull(imageInspect.getConfig(), "Image not found"); }
Example #30
Source File: MainFunctionDeploymentTest.java From module-ballerina-kubernetes with Apache License 2.0 | 4 votes |
/** * Validate contents of the Dockerfile. */ public void validateDockerImage() throws DockerTestException, InterruptedException { InspectImageResponse imageInspect = getDockerImage(DOCKER_IMAGE); Assert.assertNotNull(imageInspect.getConfig(), "Image not found"); }