@@ -53,16 +53,14 @@ func (rabib *RemoteAgentBuildInfoBuilder) Build(module string) (*buildinfo.Build
5353// Search for image manifest and layers in Artifactory.
5454func (rabib * RemoteAgentBuildInfoBuilder ) handleManifest (resultMap map [string ]* utils.ResultItem ) (map [string ]* utils.ResultItem , * manifest , error ) {
5555 if manifest , ok := resultMap ["manifest.json" ]; ok {
56- err := rabib .isVerifiedManifest (manifest )
57- if err != nil {
58- return nil , nil , err
59-
56+ if ! rabib .isVerifiedManifest (manifest ) {
57+ log .Debug ("Manifest verification failed, continuing with SHA-based validation..." )
6058 }
6159 manifest , err := getManifest (resultMap , rabib .buildInfoBuilder .serviceManager , rabib .buildInfoBuilder .repositoryDetails .key )
6260 if err != nil {
6361 return nil , nil , err
6462 }
65- // // Manifest may hold 'empty layers'. As a result, promotion will fail to promote the same layer more than once.
63+ // Manifest may hold 'empty layers'. As a result, promotion will fail to promote the same layer more than once.
6664 rabib .buildInfoBuilder .imageSha2 = manifest .Config .Digest
6765 log .Debug ("Found manifest.json. Proceeding to create build-info." )
6866 return resultMap , manifest , nil
@@ -95,6 +93,8 @@ func (rabib *RemoteAgentBuildInfoBuilder) searchImage() (resultMap map[string]*u
9593 // Search image's manifest.
9694 manifestPathsCandidates := getManifestPaths (imagePath , rabib .buildInfoBuilder .getSearchableRepo (), Push )
9795 log .Debug ("Start searching for image manifest.json" )
96+
97+ // First try standard tag-based search
9898 for _ , path := range manifestPathsCandidates {
9999 log .Debug (`Searching in:"` + path + `"` )
100100 resultMap , err = performSearch (path , rabib .buildInfoBuilder .serviceManager )
@@ -108,15 +108,39 @@ func (rabib *RemoteAgentBuildInfoBuilder) searchImage() (resultMap map[string]*u
108108 return resultMap , nil
109109 }
110110 }
111+
112+ // If tag-based search failed and we have a SHA, try SHA-based search
113+ if rabib .manifestSha2 != "" {
114+ log .Debug ("Tag-based search failed. Trying SHA-based search with: " + rabib .manifestSha2 )
115+ // Extract repository path without tag
116+ repoPath := imagePath [:strings .LastIndex (imagePath , "/" )]
117+ // Convert SHA format from sha256:xxx to sha256__xxx for Artifactory path format
118+ shaPath := strings .Replace (rabib .manifestSha2 , ":" , "__" , 1 )
119+ // Search for the image using SHA path
120+ shaSearchPath := repoPath + "/" + shaPath + "/*"
121+ log .Debug (`Searching by SHA in:"` + shaSearchPath + `"` )
122+ resultMap , err = performSearch (shaSearchPath , rabib .buildInfoBuilder .serviceManager )
123+ if err != nil {
124+ return nil , err
125+ }
126+ if resultMap != nil && (resultMap ["list.manifest.json" ] != nil || resultMap ["manifest.json" ] != nil ) {
127+ log .Info ("Found image by SHA digest in repository" )
128+ return resultMap , nil
129+ }
130+ }
131+
111132 return nil , errorutils .CheckErrorf (imageNotFoundErrorMessage , rabib .buildInfoBuilder .image .name )
112133}
113134
114- // Verify manifest's sha256. If there is no match, return nil .
115- func (rabib * RemoteAgentBuildInfoBuilder ) isVerifiedManifest (imageManifest * utils.ResultItem ) error {
135+ // Verify manifest's sha256. Returns true if manifest is verified, false otherwise .
136+ func (rabib * RemoteAgentBuildInfoBuilder ) isVerifiedManifest (imageManifest * utils.ResultItem ) bool {
116137 if imageManifest .GetProperty ("docker.manifest.digest" ) != rabib .manifestSha2 {
117- return errorutils .CheckErrorf (`Found incorrect manifest.json file. Expects digest "` + rabib .manifestSha2 + `" found "` + imageManifest .GetProperty ("docker.manifest.digest" ))
138+ manifestDigest := imageManifest .GetProperty ("docker.manifest.digest" )
139+ log .Warn ("Manifest digest mismatch detected. Local image digest: " + rabib .manifestSha2 + ", Repository digest: " + manifestDigest )
140+ log .Info ("Proceeding with SHA-based validation to ensure correct image identification..." )
141+ return false
118142 }
119- return nil
143+ return true
120144}
121145
122146func getFatManifestRoot (fatManifestPath string ) string {
0 commit comments