Skip to content

Commit

Permalink
Auto detect osVersion/osFeature/variant
Browse files Browse the repository at this point in the history
  • Loading branch information
STARRY-S committed Aug 14, 2024
1 parent 1b0d73e commit fe6e67b
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions pkg/image/source/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,21 @@ func (s *Source) copyDockerV2ListMediaType(
errs = append(errs, fmt.Errorf("inspector.Raw failed: %w", err))
continue
}
if needInspectConfig(osInfo, arch, variant, osVersion, osFeatures) {
c, err := inspector.Config(ctx)
if err != nil {
errs = append(errs, fmt.Errorf("inspector.Config failed: %w", err))
continue
}
ociConfig := &imgspecv1.Image{}
err = json.Unmarshal(c, ociConfig)
if err != nil {
errs = append(errs, fmt.Errorf("failed to unmarshal OCI config: %w", err))
continue
}
osVersion = ociConfig.OSVersion
variant = ociConfig.Variant
}
manifestDigest, err := manifestv5.Digest(b)
if err != nil {
errs = append(errs, fmt.Errorf("failed to get digest: %w", err))
Expand Down Expand Up @@ -294,6 +309,21 @@ func (s *Source) copyMediaTypeImageIndex(
errs = append(errs, fmt.Errorf("inspector.Raw failed: %w", err))
continue
}
if needInspectConfig(osInfo, arch, variant, osVersion, osFeatures) {
c, err := inspector.Config(ctx)
if err != nil {
errs = append(errs, fmt.Errorf("inspector.Config failed: %w", err))
continue
}
ociConfig := &imgspecv1.Image{}
err = json.Unmarshal(c, ociConfig)
if err != nil {
errs = append(errs, fmt.Errorf("failed to unmarshal OCI config: %w", err))
continue
}
osVersion = ociConfig.OSVersion
variant = ociConfig.Variant
}
manifestDigest, err := manifestv5.Digest(b)
if err != nil {
errs = append(errs, fmt.Errorf("imagemanifest.Digest failed: %w", err))
Expand Down Expand Up @@ -680,3 +710,18 @@ func updateSpecImageManifest(
spec.Layers = append(spec.Layers, layer.Digest)
}
}

func needInspectConfig(
osInfo, arch, variant, osVersion string, osFeatures []string,
) bool {
switch osInfo {
case "windows":
return osVersion == "" || len(osFeatures) == 0
case "linux":
if arch == "arm" {
return variant == ""
}
}

return false
}

0 comments on commit fe6e67b

Please sign in to comment.