Search in sources :

Example 1 with DockerInspectorResults

use of com.synopsys.integration.detectable.detectables.docker.model.DockerInspectorResults in project synopsys-detect by blackducksoftware.

the class DockerExtractor method executeDocker.

private Extraction executeDocker(File outputDirectory, ImageIdentifierType imageIdentifierType, String imageArgument, String suppliedImagePiece, String dockerTarFilePath, File directory, ExecutableTarget javaExe, ExecutableTarget dockerExe, DockerInspectorInfo dockerInspectorInfo, DockerProperties dockerProperties) throws IOException, ExecutableRunnerException {
    File dockerPropertiesFile = new File(outputDirectory, "application.properties");
    dockerProperties.populatePropertiesFile(dockerPropertiesFile, outputDirectory);
    Map<String, String> environmentVariables = new HashMap<>(0);
    List<String> dockerArguments = new ArrayList<>();
    dockerArguments.add("-jar");
    dockerArguments.add(dockerInspectorInfo.getDockerInspectorJar().getAbsolutePath());
    dockerArguments.add("--spring.config.location=file:" + dockerPropertiesFile.getCanonicalPath());
    dockerArguments.add(imageArgument);
    if (dockerInspectorInfo.hasAirGapImageFiles()) {
        importTars(dockerInspectorInfo.getAirGapInspectorImageTarFiles(), outputDirectory, environmentVariables, dockerExe);
    }
    Executable dockerExecutable = ExecutableUtils.createFromTarget(outputDirectory, environmentVariables, javaExe, dockerArguments);
    executableRunner.execute(dockerExecutable);
    Optional<DockerInspectorResults> dockerResults = Optional.empty();
    File producedResultFile = fileFinder.findFile(outputDirectory, RESULTS_FILENAME_PATTERN);
    if (producedResultFile != null) {
        String resultsFileContents = FileUtils.readFileToString(producedResultFile, StandardCharsets.UTF_8);
        dockerResults = dockerInspectorResultsFileParser.parse(resultsFileContents);
    }
    File producedSquashedImageFile = fileFinder.findFile(outputDirectory, SQUASHED_IMAGE_FILENAME_PATTERN);
    if (producedSquashedImageFile != null) {
        logger.debug("Returning squashed image: {}", producedSquashedImageFile.getAbsolutePath());
    }
    File producedContainerFileSystemFile = fileFinder.findFile(outputDirectory, CONTAINER_FILESYSTEM_FILENAME_PATTERN);
    if (producedContainerFileSystemFile != null) {
        logger.debug("Returning container filesystem: {}", producedContainerFileSystemFile.getAbsolutePath());
    }
    Extraction.Builder extractionBuilder = findCodeLocations(outputDirectory, directory, dockerResults.map(DockerInspectorResults::getMessage).orElse(null));
    String imageIdentifier = imageIdentifierGenerator.generate(imageIdentifierType, suppliedImagePiece, dockerResults.orElse(null));
    // The value of DOCKER_IMAGE_NAME_META_DATA is built into the codelocation name, so changing how its value is derived is likely to
    // change how codelocation names are generated. Currently either an image repo, repo:tag, or tarfile path gets written there.
    // It's tempting to always store the image repo:tag in that field, but that would change code location naming with consequences for users.
    extractionBuilder.metaData(SQUASHED_IMAGE_META_DATA, producedSquashedImageFile).metaData(CONTAINER_FILESYSTEM_META_DATA, producedContainerFileSystemFile).metaData(DOCKER_IMAGE_NAME_META_DATA, imageIdentifier);
    if (StringUtils.isNotBlank(dockerTarFilePath)) {
        File givenDockerTarfile = new File(dockerTarFilePath);
        logger.debug("Returning given docker tarfile: {}", givenDockerTarfile.getAbsolutePath());
        extractionBuilder.metaData(DOCKER_TAR_META_DATA, givenDockerTarfile);
    }
    return extractionBuilder.build();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Extraction(com.synopsys.integration.detectable.extraction.Extraction) Executable(com.synopsys.integration.executable.Executable) File(java.io.File) DockerInspectorResults(com.synopsys.integration.detectable.detectables.docker.model.DockerInspectorResults)

Example 2 with DockerInspectorResults

use of com.synopsys.integration.detectable.detectables.docker.model.DockerInspectorResults in project synopsys-detect by blackducksoftware.

the class DockerExtractorTest method getMockDockerExtractor.

private DockerExtractor getMockDockerExtractor(DetectableExecutableRunner executableRunner, FileFinder fileFinder) {
    BdioTransformer bdioTransformer = Mockito.mock(BdioTransformer.class);
    ExternalIdFactory externalIdFactory = Mockito.mock(ExternalIdFactory.class);
    Gson gson = new Gson();
    DockerInspectorResultsFileParser dockerInspectorResultsFileParser = Mockito.mock(DockerInspectorResultsFileParser.class);
    DockerInspectorResults dockerInspectorResults = new DockerInspectorResults("returnedimage", "returnedtag", "returned message");
    Mockito.when(dockerInspectorResultsFileParser.parse(Mockito.anyString())).thenReturn(Optional.of(dockerInspectorResults));
    ImageIdentifierGenerator imageIdentifierGenerator = new ImageIdentifierGenerator();
    return new DockerExtractor(fileFinder, executableRunner, bdioTransformer, externalIdFactory, gson, dockerInspectorResultsFileParser, imageIdentifierGenerator);
}
Also used : BdioTransformer(com.synopsys.integration.bdio.BdioTransformer) ExternalIdFactory(com.synopsys.integration.bdio.model.externalid.ExternalIdFactory) DockerInspectorResultsFileParser(com.synopsys.integration.detectable.detectables.docker.parser.DockerInspectorResultsFileParser) Gson(com.google.gson.Gson) DockerExtractor(com.synopsys.integration.detectable.detectables.docker.DockerExtractor) ImageIdentifierGenerator(com.synopsys.integration.detectable.detectables.docker.ImageIdentifierGenerator) DockerInspectorResults(com.synopsys.integration.detectable.detectables.docker.model.DockerInspectorResults)

Example 3 with DockerInspectorResults

use of com.synopsys.integration.detectable.detectables.docker.model.DockerInspectorResults in project synopsys-detect by blackducksoftware.

the class ImageIdentifierGeneratorTest method testImageId.

@Test
void testImageId() {
    DockerInspectorResults dockerInspectorResults = new DockerInspectorResults("returnedrepo", "returnedtag", "success");
    assertEquals("returnedrepo:returnedtag", generator.generate(ImageIdentifierType.IMAGE_ID, "suppliedrepo:suppliedtag", dockerInspectorResults));
}
Also used : DockerInspectorResults(com.synopsys.integration.detectable.detectables.docker.model.DockerInspectorResults) Test(org.junit.jupiter.api.Test)

Example 4 with DockerInspectorResults

use of com.synopsys.integration.detectable.detectables.docker.model.DockerInspectorResults in project synopsys-detect by blackducksoftware.

the class ImageIdentifierGeneratorTest method testImageName.

@Test
void testImageName() {
    DockerInspectorResults dockerInspectorResults = new DockerInspectorResults("returnedrepo", "returnedtag", "success");
    assertEquals("suppliedrepo:suppliedtag", generator.generate(ImageIdentifierType.IMAGE_NAME, "suppliedrepo:suppliedtag", dockerInspectorResults));
}
Also used : DockerInspectorResults(com.synopsys.integration.detectable.detectables.docker.model.DockerInspectorResults) Test(org.junit.jupiter.api.Test)

Example 5 with DockerInspectorResults

use of com.synopsys.integration.detectable.detectables.docker.model.DockerInspectorResults in project synopsys-detect by blackducksoftware.

the class ImageIdentifierGeneratorTest method testMissingReturnedRepo.

@Test
void testMissingReturnedRepo() {
    DockerInspectorResults dockerInspectorResults = new DockerInspectorResults(null, "returnedtag", "success");
    assertEquals("suppliedrepo:suppliedtag", generator.generate(ImageIdentifierType.IMAGE_ID, "suppliedrepo:suppliedtag", dockerInspectorResults));
}
Also used : DockerInspectorResults(com.synopsys.integration.detectable.detectables.docker.model.DockerInspectorResults) Test(org.junit.jupiter.api.Test)

Aggregations

DockerInspectorResults (com.synopsys.integration.detectable.detectables.docker.model.DockerInspectorResults)6 Test (org.junit.jupiter.api.Test)4 Gson (com.google.gson.Gson)1 BdioTransformer (com.synopsys.integration.bdio.BdioTransformer)1 ExternalIdFactory (com.synopsys.integration.bdio.model.externalid.ExternalIdFactory)1 DockerExtractor (com.synopsys.integration.detectable.detectables.docker.DockerExtractor)1 ImageIdentifierGenerator (com.synopsys.integration.detectable.detectables.docker.ImageIdentifierGenerator)1 DockerInspectorResultsFileParser (com.synopsys.integration.detectable.detectables.docker.parser.DockerInspectorResultsFileParser)1 Extraction (com.synopsys.integration.detectable.extraction.Extraction)1 Executable (com.synopsys.integration.executable.Executable)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1