File tree Expand file tree Collapse file tree 5 files changed +33
-31
lines changed
Expand file tree Collapse file tree 5 files changed +33
-31
lines changed Original file line number Diff line number Diff line change @@ -268,14 +268,11 @@ async function getImageArchive(
268268
269269function extractImageDetails ( targetImage : string ) : ImageDetails {
270270 const parsed = parseImageReference ( targetImage ) ;
271- const hostname = parsed . registryForPull ;
272- const isDockerHub = hostname === "registry-1.docker.io" ;
273- const imageName =
274- isDockerHub && ! parsed . repository . includes ( "/" )
275- ? "library/" + parsed . repository
276- : parsed . repository ;
277- const tag = parsed . tailReferenceForPull ;
278- return { hostname, imageName, tag } ;
271+ return {
272+ hostname : parsed . registryForPull ,
273+ imageName : parsed . normalizedRepository ,
274+ tag : parsed . tailReferenceForPull ,
275+ } ;
279276}
280277
281278function isLocalImageSameArchitecture (
Original file line number Diff line number Diff line change 1- import { parseAll } from "@swimlane/docker -reference" ;
1+ import { parseImageReference } from "../image -reference" ;
22
33export interface OCIDistributionMetadata {
44 // Must be a valid host, including port if one was used to pull the image.
@@ -32,17 +32,15 @@ export function constructOCIDisributionMetadata({
3232 | OCIDistributionMetadata
3333 | undefined {
3434 try {
35- const ref = parseAll ( imageName ) ;
36- if ( ! ref . domain || ! ref . repository ) {
37- return ;
38- }
39-
35+ const parsed = parseImageReference ( imageName ) ;
36+ // Normalize the hostname. Note this function uses slightly different logic from the one in the image-reference.ts file.
37+ const hostname = parsed . registry ? parsed . registry : "docker.io" ;
4038 const metadata : OCIDistributionMetadata = {
41- registryHost : ref . domain ,
42- repository : ref . repository ,
39+ registryHost : hostname ,
40+ repository : parsed . normalizedRepository ,
4341 manifestDigest,
4442 indexDigest,
45- imageTag : ref . tag ,
43+ imageTag : parsed . tag ,
4644 } ;
4745
4846 if ( ! ociDistributionMetadataIsValid ( metadata ) ) {
Original file line number Diff line number Diff line change @@ -54,12 +54,20 @@ export class ParsedImageReference {
5454 return ref ;
5555 }
5656
57+ /**
58+ * Whether the image is from Docker Hub.
59+ * This is true if the registry is "registry-1.docker.io" or "docker.io" or undefined.
60+ */
61+ get isDockerHub ( ) : boolean {
62+ return this . registry === "registry-1.docker.io" || this . registry === "docker.io" || this . registry === undefined ;
63+ }
64+
5765 /**
5866 * The registry to use for pulling the image.
5967 * If the registry is not set, use Docker Hub.
6068 */
6169 get registryForPull ( ) : string {
62- if ( this . registry === "docker.io" || this . registry === undefined ) {
70+ if ( this . isDockerHub || this . registry === undefined ) {
6371 return "registry-1.docker.io" ;
6472 }
6573 return this . registry ;
@@ -74,6 +82,17 @@ export class ParsedImageReference {
7482 get tailReferenceForPull ( ) : string {
7583 return this . digest ?? this . tag ?? "latest" ;
7684 }
85+
86+ /**
87+ * The normalized repository name.
88+ * If the image is from Docker Hub and the repository does not have a namespace, add the default namespace "library".
89+ */
90+ get normalizedRepository ( ) : string {
91+ if ( this . isDockerHub && ! this . repository . includes ( "/" ) ) {
92+ return "library/" + this . repository ;
93+ }
94+ return this . repository ;
95+ }
7796}
7897
7998/**
Original file line number Diff line number Diff line change 3333 "@snyk/docker-registry-v2-client" : " ^2.24.0" ,
3434 "@snyk/rpm-parser" : " ^3.4.1" ,
3535 "@snyk/snyk-docker-pull" : " ^3.15.0" ,
36- "@swimlane/docker-reference" : " ^2.0.1" ,
3736 "adm-zip" : " ^0.5.16" ,
3837 "chalk" : " ^2.4.2" ,
3938 "debug" : " ^4.4.3" ,
6261 "@commitlint/config-conventional" : " ^17.0.2" ,
6362 "@mongodb-js/zstd" : " ^2.0.1" ,
6463 "@semantic-release/exec" : " ^6.0.3" ,
65- "semantic-release" : " ^19.0.5" ,
6664 "@types/adm-zip" : " ^0.4.34" ,
6765 "@types/debug" : " ^4.1.5" ,
6866 "@types/jest" : " ^29.5.5" ,
7371 "jest" : " ^29.7.0" ,
7472 "npm-run-all" : " ^4.1.5" ,
7573 "prettier" : " ^2.7.1" ,
74+ "semantic-release" : " ^19.0.5" ,
7675 "ts-jest" : " ^29.1.1" ,
7776 "ts-node" : " ^10.2.1" ,
7877 "tsc-watch" : " ^4.2.8" ,
You can’t perform that action at this time.
0 commit comments