Search in sources :

Example 1 with ImageTarWrapper

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

the class HttpClientInspector method getBdio.

public Result getBdio() throws IntegrationException, InterruptedException {
    ImageInspectorClient imageInspectorClient = chooseImageInspectorClient();
    try {
        output.ensureWorkingOutputDirIsWriteable();
        ImageTarWrapper finalDockerTarfile = prepareDockerTarfile(imageInspectorClient);
        String containerFileSystemFilename = containerFilesystemFilename.deriveContainerFilesystemFilename(finalDockerTarfile.getImageRepo(), finalDockerTarfile.getImageTag());
        String dockerTarFilePathInContainer = containerPaths.getContainerPathToTargetFile(finalDockerTarfile.getFile().getCanonicalPath());
        String containerFileSystemPathInContainer = null;
        if (config.isOutputIncludeContainerfilesystem() || config.isOutputIncludeSquashedImage()) {
            containerFileSystemPathInContainer = containerPaths.getContainerPathToOutputFile(containerFileSystemFilename);
        }
        String bdioString = imageInspectorClient.getBdio(finalDockerTarfile.getFile().getCanonicalPath(), dockerTarFilePathInContainer, config.getDockerImageRepo(), config.getDockerImageTag(), containerFileSystemPathInContainer, config.getContainerFileSystemExcludedPaths(), config.isOrganizeComponentsByLayer(), config.isIncludeRemovedComponents(), config.isCleanupWorkingDir(), config.getDockerPlatformTopLayerId(), config.getTargetImageLinuxDistroOverride());
        logger.trace(String.format("bdioString: %s", bdioString));
        SimpleBdioDocument bdioDocument = toBdioDocument(bdioString);
        adjustBdio(bdioDocument);
        OutputFiles outputFiles = output.addOutputToFinalOutputDir(bdioDocument, finalDockerTarfile.getImageRepo(), finalDockerTarfile.getImageTag());
        if (config.isUploadBdio()) {
            NameVersion projectAndVersion = new NameVersion(bdioDocument.getProject().name, bdioDocument.getProject().version);
            blackDuckClient.uploadBdio(outputFiles.getBdioFile(), bdioDocument.getBillOfMaterials().spdxName, projectAndVersion);
        }
        cleanup();
        Result result = Result.createResultSuccess(finalDockerTarfile.getImageRepo(), finalDockerTarfile.getImageTag(), finalDockerTarfile.getFile().getName(), outputFiles.getBdioFile(), outputFiles.getContainerFileSystemFile(), outputFiles.getSquashedImageFile());
        return result;
    } catch (IOException e) {
        throw new IntegrationException(e.getMessage(), e);
    }
}
Also used : ImageTarWrapper(com.synopsys.integration.blackduck.dockerinspector.output.ImageTarWrapper) NameVersion(com.synopsys.integration.util.NameVersion) IntegrationException(com.synopsys.integration.exception.IntegrationException) OutputFiles(com.synopsys.integration.blackduck.dockerinspector.output.OutputFiles) IOException(java.io.IOException) SimpleBdioDocument(com.synopsys.integration.bdio.model.SimpleBdioDocument) Result(com.synopsys.integration.blackduck.dockerinspector.output.Result)

Example 2 with ImageTarWrapper

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

the class ImageInspectorClient method copyTarfileToSharedDir.

public ImageTarWrapper copyTarfileToSharedDir(FileOperations fileOperations, Config config, ProgramPaths programPaths, ImageTarWrapper givenDockerTarfile) throws IOException {
    if (fileIsInsideDir(new File(config.getSharedDirPathLocal()), givenDockerTarfile.getFile())) {
        logger.debug(String.format("File %s is already inside shared dir %s; leaving it there", givenDockerTarfile.getFile().getCanonicalPath(), config.getSharedDirPathLocal()));
        return givenDockerTarfile;
    }
    // Copy the tarfile to the shared/target dir
    logger.debug(String.format("File %s is not inside shared dir %s; copying it there", givenDockerTarfile.getFile().getCanonicalPath(), config.getSharedDirPathLocal()));
    File finalDockerTarfile = new File(programPaths.getDockerInspectorTargetDirPath(), givenDockerTarfile.getFile().getName());
    logger.debug(String.format("Required docker tarfile location: %s", finalDockerTarfile.getCanonicalPath()));
    if (!finalDockerTarfile.getCanonicalPath().equals(givenDockerTarfile.getFile().getCanonicalPath())) {
        logger.debug(String.format("Copying %s to %s", givenDockerTarfile.getFile().getCanonicalPath(), finalDockerTarfile.getCanonicalPath()));
        FileUtils.copyFile(givenDockerTarfile.getFile(), finalDockerTarfile);
        fileOperations.logFileOwnerGroupPerms(finalDockerTarfile);
    }
    logger.debug(String.format("Final docker tar file path: %s", finalDockerTarfile.getCanonicalPath()));
    return new ImageTarWrapper(finalDockerTarfile, givenDockerTarfile.getImageRepo(), givenDockerTarfile.getImageTag());
}
Also used : ImageTarWrapper(com.synopsys.integration.blackduck.dockerinspector.output.ImageTarWrapper) File(java.io.File)

Example 3 with ImageTarWrapper

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

the class DockerClientManager method deriveDockerTarFileFromConfig.

public ImageTarWrapper deriveDockerTarFileFromConfig() throws IOException, IntegrationException {
    logger.debug(String.format("programPaths.getDockerInspectorTargetDirPath(): %s", programPaths.getDockerInspectorTargetDirPath()));
    ImageTarWrapper tarWrapper;
    if (StringUtils.isNotBlank(config.getDockerTar())) {
        File dockerTarFile = new File(config.getDockerTar());
        fileOperations.logFileOwnerGroupPerms(dockerTarFile);
        tarWrapper = new ImageTarWrapper(dockerTarFile);
    } else {
        tarWrapper = deriveDockerTarFileGivenImageSpec();
    }
    fileOperations.logFileOwnerGroupPerms(tarWrapper.getFile());
    return tarWrapper;
}
Also used : ImageTarWrapper(com.synopsys.integration.blackduck.dockerinspector.output.ImageTarWrapper) File(java.io.File)

Example 4 with ImageTarWrapper

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

the class DockerClientManager method deriveDockerTarFileGivenImageSpec.

private ImageTarWrapper deriveDockerTarFileGivenImageSpec() throws IntegrationException, IOException {
    ImageTarWrapper finalDockerTarfile;
    File imageTarDirectory = new File(programPaths.getDockerInspectorTargetDirPath());
    if (StringUtils.isNotBlank(config.getDockerImageId())) {
        finalDockerTarfile = getTarFileFromDockerImageById(config.getDockerImageId(), imageTarDirectory);
    } else if (StringUtils.isNotBlank(config.getDockerImageRepo())) {
        finalDockerTarfile = getTarFileFromDockerImage(config.getDockerImageRepo(), config.getDockerImageTag(), imageTarDirectory);
    } else {
        throw new BlackDuckIntegrationException("You must specify a docker image");
    }
    return finalDockerTarfile;
}
Also used : ImageTarWrapper(com.synopsys.integration.blackduck.dockerinspector.output.ImageTarWrapper) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) File(java.io.File)

Example 5 with ImageTarWrapper

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

the class DockerClientManager method getTarFileFromDockerImage.

private ImageTarWrapper getTarFileFromDockerImage(String imageName, String tagName, File imageTarDirectory) throws IntegrationException, IOException {
    Optional<String> targetImageId = Optional.empty();
    try {
        targetImageId = getImageId(imageName, tagName);
    } catch (DisabledException disabledException) {
        logger.info("Image pulling is disabled in offline mode");
    } catch (Exception e) {
        throwIfPlatformSpecified(imageName, tagName, e);
        logger.warn(String.format("Unable to pull %s:%s; Proceeding anyway since the image might be in local docker image cache. Error on pull: %s", imageName, tagName, e.getMessage()));
    }
    File imageTarFile = saveImageToDir(imageTarDirectory, imageTarFilename.deriveImageTarFilenameFromImageTag(imageName, tagName), imageName, tagName);
    ImageTarWrapper imageTarWrapper = new ImageTarWrapper(imageTarFile, imageName, tagName);
    if (config.isCleanupTargetImage() && targetImageId.isPresent()) {
        removeImage(targetImageId.get());
    }
    return imageTarWrapper;
}
Also used : ImageTarWrapper(com.synopsys.integration.blackduck.dockerinspector.output.ImageTarWrapper) DisabledException(com.synopsys.integration.blackduck.dockerinspector.exception.DisabledException) File(java.io.File) IntegrationException(com.synopsys.integration.exception.IntegrationException) DisabledException(com.synopsys.integration.blackduck.dockerinspector.exception.DisabledException) NotFoundException(com.github.dockerjava.api.exception.NotFoundException) IOException(java.io.IOException) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)

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