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