Search in sources :

Example 6 with ImageTarWrapper

use of com.synopsys.integration.blackduck.dockerinspector.output.ImageTarWrapper in project blackduck-docker-inspector by blackducksoftware.

the class DockerClientManager method getTarFileFromDockerImageById.

public ImageTarWrapper getTarFileFromDockerImageById(String imageId, File imageTarDirectory) throws IntegrationException, IOException {
    InspectImageCmd inspectImageCmd = dockerClient.inspectImageCmd(imageId);
    InspectImageResponse imageDetails = inspectImageCmd.exec();
    List<String> repoTags = imageDetails.getRepoTags();
    if (repoTags == null || repoTags.isEmpty()) {
        throw new IntegrationException(String.format("Unable to get image name:tag for image ID %s", imageId));
    }
    RepoTag resolvedRepoTag = imageNameResolver.resolve(repoTags.get(0), null, null);
    String imageName = resolvedRepoTag.getRepo().orElse("");
    String tagName = resolvedRepoTag.getTag().orElse("");
    logger.debug(String.format("Converted image ID %s to image name:tag %s:%s", imageId, imageName, tagName));
    File imageTarFile = saveImageToDir(imageTarDirectory, imageTarFilename.deriveImageTarFilenameFromImageTag(imageName, tagName), imageName, tagName);
    return new ImageTarWrapper(imageTarFile, imageName, tagName);
}
Also used : InspectImageCmd(com.github.dockerjava.api.command.InspectImageCmd) ImageTarWrapper(com.synopsys.integration.blackduck.dockerinspector.output.ImageTarWrapper) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) InspectImageResponse(com.github.dockerjava.api.command.InspectImageResponse) File(java.io.File) RepoTag(com.synopsys.integration.blackduck.imageinspector.image.common.RepoTag)

Example 7 with ImageTarWrapper

use of com.synopsys.integration.blackduck.dockerinspector.output.ImageTarWrapper in project blackduck-docker-inspector by blackducksoftware.

the class DockerClientManagerTest method testDeriveDockerTarfileFromConfiguredTar.

@Test
public void testDeriveDockerTarfileFromConfiguredTar() throws IOException, IntegrationException {
    Mockito.when(programPaths.getDockerInspectorTargetDirPath()).thenReturn("test/containerShared/target");
    Mockito.when(config.getDockerTar()).thenReturn("build/images/test/alpine.tar");
    ImageTarWrapper imageTarWrapper = dockerClientManager.deriveDockerTarFileFromConfig();
    assertEquals("alpine.tar", imageTarWrapper.getFile().getName());
}
Also used : ImageTarWrapper(com.synopsys.integration.blackduck.dockerinspector.output.ImageTarWrapper) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with ImageTarWrapper

use of com.synopsys.integration.blackduck.dockerinspector.output.ImageTarWrapper in project blackduck-docker-inspector by blackducksoftware.

the class DockerClientManagerTest method testDeriveDockerTarfileFromConfiguredImage.

@Test
public void testDeriveDockerTarfileFromConfiguredImage() throws IOException, IntegrationException {
    Mockito.when(programPaths.getDockerInspectorTargetDirPath()).thenReturn("test/containerShared/target");
    Mockito.when(config.getDockerImageRepo()).thenReturn("alpine");
    Mockito.when(config.getDockerImageTag()).thenReturn("latest");
    ImageTarWrapper imageTarWrapper = dockerClientManager.deriveDockerTarFileFromConfig();
    assertEquals("alpine_latest.tar", imageTarWrapper.getFile().getName());
}
Also used : ImageTarWrapper(com.synopsys.integration.blackduck.dockerinspector.output.ImageTarWrapper) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with ImageTarWrapper

use of com.synopsys.integration.blackduck.dockerinspector.output.ImageTarWrapper in project blackduck-docker-inspector by blackducksoftware.

the class HttpClientInspector method prepareDockerTarfile.

private ImageTarWrapper prepareDockerTarfile(ImageInspectorClient imageInspectorClient) throws IOException, IntegrationException {
    ImageTarWrapper givenDockerTarfile = dockerClientManager.deriveDockerTarFileFromConfig();
    ImageTarWrapper finalDockerTarfile = imageInspectorClient.copyTarfileToSharedDir(fileOperations, config, programPaths, givenDockerTarfile);
    return finalDockerTarfile;
}
Also used : ImageTarWrapper(com.synopsys.integration.blackduck.dockerinspector.output.ImageTarWrapper)

Aggregations

ImageTarWrapper (com.synopsys.integration.blackduck.dockerinspector.output.ImageTarWrapper)9 File (java.io.File)5 BlackDuckIntegrationException (com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)3 IntegrationException (com.synopsys.integration.exception.IntegrationException)3 IOException (java.io.IOException)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 InspectImageCmd (com.github.dockerjava.api.command.InspectImageCmd)1 InspectImageResponse (com.github.dockerjava.api.command.InspectImageResponse)1 NotFoundException (com.github.dockerjava.api.exception.NotFoundException)1 SimpleBdioDocument (com.synopsys.integration.bdio.model.SimpleBdioDocument)1 DisabledException (com.synopsys.integration.blackduck.dockerinspector.exception.DisabledException)1 OutputFiles (com.synopsys.integration.blackduck.dockerinspector.output.OutputFiles)1 Result (com.synopsys.integration.blackduck.dockerinspector.output.Result)1 RepoTag (com.synopsys.integration.blackduck.imageinspector.image.common.RepoTag)1 NameVersion (com.synopsys.integration.util.NameVersion)1