Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
fix: use RawConfigFile() instead of ConfigFile() to get docker image …
Browse files Browse the repository at this point in the history
…config file (#499)

* ignore mismatch between fs commands and layers count

* use RawConfigFile() instead of ConfigFile()

* ignore mismatch between fs commands and layers count

* add missing error check
  • Loading branch information
FrimIdan authored Sep 11, 2023
1 parent 89b14c1 commit e52ab26
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions shared/pkg/utils/image_helper/image_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,14 @@ func GetHashFromRepoDigest(repoDigests []string, imageName string) string {

// fetchFsCommands retrieves information about image layers commands.
func fetchFsCommands(img containerregistry_v1.Image) ([]*FsLayerCommand, error) {
conf, err := img.ConfigFile()
configFile, err := img.RawConfigFile()
if err != nil {
return nil, fmt.Errorf("failed to get config file: %v", err)
return nil, fmt.Errorf("failed to get raw config file: %v", err)
}

var conf containerregistry_v1.ConfigFile
if err = json.Unmarshal(configFile, &conf); err != nil {
return nil, fmt.Errorf("failed to unmarshal config file: %v", err)
}

if log.IsLevelEnabled(log.DebugLevel) {
Expand All @@ -84,15 +89,16 @@ func fetchFsCommands(img containerregistry_v1.Image) ([]*FsLayerCommand, error)
log.Debugf("Image config: %s", confB)
}

commands := getCommands(conf)
commands := getCommands(&conf)

layers, err := img.Layers()
if err != nil {
return nil, fmt.Errorf("failed to get layers: %v", err)
}

if len(layers) != len(commands) {
return nil, fmt.Errorf("number of fs layers (%v) doesn't match the number of fs history entries (%v)", len(layers), len(commands))
log.Infof("Number of fs layers (%v) doesn't match the number of fs history entries (%v) - setting empty commands", len(layers), len(commands))
commands = make([]string, len(layers))
}

fsLayerCommands, err := createFsLayerCommands(layers, commands)
Expand Down

0 comments on commit e52ab26

Please sign in to comment.