Skip to content

Commit b71e35d

Browse files
committed
fix: fixes for multi-image oci archives (with and without given repo:tag values)
1 parent 70c4864 commit b71e35d

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/main/java/com/synopsys/integration/blackduck/imageinspector/image/docker/manifest/DockerManifest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ private String deriveSpecifiedRepoTag(final String dockerImageName, final String
9999

100100
private void validateImageSpecificity(final List<DockerImageInfo> images, final String targetImageName, final String targetTagName) throws IntegrationException {
101101
if (images.size() > 1 && (StringUtils.isBlank(targetImageName) || StringUtils.isBlank(targetTagName))) {
102-
final String msg = "When the manifest contains multiple images or tags, the target image and tag to inspect must be specified";
103-
logger.debug(msg);
104-
throw new IntegrationException(msg);
102+
throw new IntegrationException("When the manifest contains multiple images or tags, the target image and tag to inspect must be specified");
105103
}
106104
}
107105

src/main/java/com/synopsys/integration/blackduck/imageinspector/image/oci/OciManifestDescriptorParser.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
1313
import com.synopsys.integration.exception.IntegrationException;
1414
import org.apache.commons.lang3.StringUtils;
1515
import org.jetbrains.annotations.Nullable;
16+
import org.slf4j.Logger;
17+
import org.slf4j.LoggerFactory;
1618

1719
import java.util.List;
1820
import java.util.Optional;
1921
import java.util.stream.Collectors;
2022

2123
public class OciManifestDescriptorParser {
2224
private static final String MANIFEST_FILE_MEDIA_TYPE = "application/vnd.oci.image.manifest.v1+json";
25+
private final Logger logger = LoggerFactory.getLogger(this.getClass());
2326
private final ManifestRepoTagMatcher manifestRepoTagMatcher;
2427

2528
public OciManifestDescriptorParser(ManifestRepoTagMatcher manifestRepoTagMatcher) {
@@ -37,9 +40,13 @@ public OciDescriptor getManifestDescriptor(OciImageIndex ociImageIndex,
3740
throw new IntegrationException(String.format("No manifest descriptor with media type %s was found in OCI image index", MANIFEST_FILE_MEDIA_TYPE));
3841
}
3942
if ((trueManifests.size() == 1) && StringUtils.isBlank(givenRepo)) {
43+
logger.debug(String.format("User did not specify a repo:tag, and there's only one manifest; inspecting that one; digest=%s", trueManifests.get(0).getDigest()));
4044
return trueManifests.get(0);
4145
}
42-
if (StringUtils.isBlank(givenTag)) {
46+
if ((trueManifests.size() > 1) && StringUtils.isBlank(givenRepo)) {
47+
throw new IntegrationException("When the image contains multiple manifests, the target image and tag to inspect must be specified");
48+
}
49+
if (StringUtils.isNotBlank(givenRepo) && StringUtils.isBlank(givenTag)) {
4350
givenTag = "latest";
4451
}
4552
// Safe to assume both repo and tag have values

src/test/java/com/synopsys/integration/blackduck/imageinspector/api/ImageInspectorApiIntTest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public class ImageInspectorApiIntTest {
5353
private static final String MULTILAYER_IMAGE_TARFILE = "build/images/test/centos_minus_vim_plus_bacula.tar";
5454
private static final String NOPKGMGR_IMAGE_TARFILE = "build/images/test/nopkgmgr.tar";
5555
// TODO need to build this:
56-
private static final String OCI_IMAGE_TARFILE = "/tmp/ccc/centos_minus_vim_plus_bacula-oci.tar";
56+
//private static final String OCI_IMAGE_TARFILE = "/tmp/ccc/centos_minus_vim_plus_bacula-oci.tar";
57+
private static final String OCI_IMAGE_TARFILE = "/tmp/ggg/u_multi_tagged.tar";
5758

5859
private static Os os;
5960
private static ImageInspectorApi imageInspectorApi;
@@ -231,12 +232,12 @@ public void testAppOnlyFileSystem() throws IntegrationException, IOException, In
231232
assertTrue(containerFileSystemFile.length() < 80000000);
232233
}
233234

234-
@Disabled
235+
/////@Disabled
235236
@Test
236237
public void testOciImage() throws IntegrationException, IOException, InterruptedException {
237238
ComponentHierarchyBuilder componentHierarchyBuilder = new ComponentHierarchyBuilder(packageGetter);
238-
Mockito.when(os.getLinuxDistroNameFromEtcDir(Mockito.any(File.class))).thenReturn(Optional.of("centos"));
239-
Mockito.when(os.deriveOs(Mockito.any(String.class))).thenReturn(ImageInspectorOsEnum.CENTOS);
239+
Mockito.when(os.getLinuxDistroNameFromEtcDir(Mockito.any(File.class))).thenReturn(Optional.of("ubuntu"));
240+
Mockito.when(os.deriveOs(Mockito.any(String.class))).thenReturn(ImageInspectorOsEnum.UBUNTU);
240241
Mockito.when(rpmPkgMgr.isApplicable(Mockito.any(File.class))).thenReturn(true);
241242
Mockito.when(rpmPkgMgr.getType()).thenReturn(PackageManagerEnum.RPM);
242243
Mockito.when(rpmPkgMgr.getImagePackageManagerDirectory(Mockito.any(File.class))).thenReturn(new File("."));
@@ -247,8 +248,10 @@ public void testOciImage() throws IntegrationException, IOException, Interrupted
247248
.setDockerTarfilePath(OCI_IMAGE_TARFILE)
248249
//.setBlackDuckProjectName(PROJECT)
249250
//.setBlackDuckProjectVersion(PROJECT_VERSION)
251+
.setGivenImageRepo("testrepo")
252+
.setGivenImageTag("testtag")
250253
.setContainerFileSystemOutputPath(containerFileSystemOutputFilePath)
251-
.setCurrentLinuxDistro("CENTOS")
254+
.setCurrentLinuxDistro("UBUNTU")
252255
.setCleanupWorkingDir(true)
253256
.build();
254257
SimpleBdioDocument bdioDocument = imageInspectorApi.getBdio(componentHierarchyBuilder, imageInspectionRequest);

0 commit comments

Comments
 (0)