Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have describe command display digests of image layers #461

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion pkg/imgpkg/cmd/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/spf13/cobra"
"github.com/vmware-tanzu/carvel-imgpkg/pkg/imgpkg/bundle"
"github.com/vmware-tanzu/carvel-imgpkg/pkg/imgpkg/internal/util"
"github.com/vmware-tanzu/carvel-imgpkg/pkg/imgpkg/v1"
v1 "github.com/vmware-tanzu/carvel-imgpkg/pkg/imgpkg/v1"
"sigs.k8s.io/yaml"
)

Expand Down Expand Up @@ -161,6 +161,8 @@ func (p bundleTextPrinter) printerRec(description v1.Description, originalLogger
}
annotations := image.Annotations
p.printAnnotations(annotations, util.NewIndentedLogger(indentLogger))
layers := image.Layers
p.printLayers(layers, util.NewIndentedLogger(indentLogger))
}
}

Expand All @@ -180,6 +182,17 @@ func (p bundleTextPrinter) printAnnotations(annotations map[string]string, inden
}
}

func (p bundleTextPrinter) printLayers(layers []map[string]string, indentLogger Logger) {
if len(layers) > 0 {
indentLogger.Logf("Layers:\n")
layerIndentLogger := util.NewIndentedLogger(indentLogger)

for i := range layers {
layerIndentLogger.Logf(" - Digest: %s\n", layers[i]["digest"])
}
}
}

type bundleYAMLPrinter struct {
logger Logger
}
Expand Down
26 changes: 21 additions & 5 deletions pkg/imgpkg/v1/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import (
"fmt"
"sort"

"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/name"
regname "github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/vmware-tanzu/carvel-imgpkg/pkg/imgpkg/bundle"
"github.com/vmware-tanzu/carvel-imgpkg/pkg/imgpkg/lockconfig"
"github.com/vmware-tanzu/carvel-imgpkg/pkg/imgpkg/registry"
Expand All @@ -34,11 +37,12 @@ type Metadata struct {

// ImageInfo URLs where the image can be found as well as annotations provided in the Images Lock
type ImageInfo struct {
Image string `json:"image,omitempty"`
Origin string `json:"origin,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
ImageType bundle.ImageType `json:"imageType"`
Error string `json:"error,omitempty"`
Image string `json:"image,omitempty"`
Origin string `json:"origin,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
ImageType bundle.ImageType `json:"imageType"`
Error string `json:"error,omitempty"`
Layers []map[string]string `json:"layers,omitempty"`
}

// Content Contents present in a Bundle
Expand Down Expand Up @@ -170,11 +174,23 @@ func (r *refWithDescription) describeBundleRec(visitedImgs map[string]refWithDes
if err != nil {
panic(fmt.Sprintf("Internal inconsistency: image %s should be fully resolved", ref.Image))
}

layers := []map[string]string{}

parsedImgRef, _ := regname.ParseReference(ref.Image, regname.WeakValidation)
v1Img, _ := remote.Image(parsedImgRef, remote.WithAuthFromKeychain(authn.DefaultKeychain))
imgLayers, _ := v1Img.Layers()
for _, imgLayer := range imgLayers {
digHash, _ := imgLayer.Digest()
layers = append(layers, map[string]string{"digest": fmt.Sprintf("%s:%s", digHash.Algorithm, digHash.Hex)})
}

desc.bundle.Content.Images[digest.DigestStr()] = ImageInfo{
Image: ref.PrimaryLocation(),
Origin: ref.Image,
Annotations: ref.Annotations,
ImageType: ref.ImageType,
Layers: layers,
}
} else {
desc.bundle.Content.Images[ref.Image] = ImageInfo{
Expand Down