Skip to content

Commit e71322b

Browse files
chhsia0tekton-robot
authored andcommitted
Made the image digest exporter report image digest if there is only one image.
Currently the image digest exporter does not implemented the behavior described in the resources doc, which says "if there are multiple versions of the image, the latest will be used." Instead, it reports the digest of `index.json`, which is an image index. This behavior introduces a usability issue: one of the major public container registry --- dockerhub --- does not support OCI image indices, and there are very few tools (if any) that support converting OCI image indices to docker manifest lists. Skopeo currently only support pushing an OCI image index that contain only one image. If the index has more than one images, it requires the user to specify one: containers/skopeo#107 containers/image#400 Essentially, these limitations make the image digest exporter useless. To make this feature useful, the exporter could instead implement the following behavior: 1. If there is only one image in `index.json`, report the image's digest. 2. If there are multiple images, report the digest of the full index. The advantage of this behavior is that, we can immediately use it (in conjunction of GoogleContainerTools/kaniko#744), yet if multi-image manifests are more widely supported, the image digest exporter can still support that without any modification.
1 parent 0d175f2 commit e71322b

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

cmd/imagedigestexporter/main.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"log"
2323
"os"
2424

25+
"github.com/google/go-containerregistry/pkg/v1"
2526
"github.com/google/go-containerregistry/pkg/v1/layout"
2627
v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
2728
)
@@ -55,9 +56,19 @@ func main() {
5556
log.Printf("ImageResource %s doesn't have an index.json file: %s", imageResource.Name, err)
5657
continue
5758
}
58-
digest, err := ii.Digest()
59+
// If there is only one image in the index, report the digest of the image; otherwise, report the digest of the whole index.
60+
digest, err := func() (v1.Hash, error) {
61+
im, err := ii.IndexManifest()
62+
if err != nil {
63+
return v1.Hash{}, err
64+
}
65+
if len(im.Manifests) == 1 {
66+
return im.Manifests[0].Digest, nil
67+
}
68+
return ii.Digest()
69+
}()
5970
if err != nil {
60-
log.Fatalf("Unexpected error getting image digest %v: %v", imageResource, err)
71+
log.Fatalf("Unexpected error getting image digest for %s: %v", imageResource.Name, err)
6172
}
6273
output = append(output, v1alpha1.PipelineResourceResult{Name: imageResource.Name, Digest: digest.String()})
6374
}

docs/resources.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,9 @@ To surface the image digest in the output of the `taskRun` the builder tool
445445
should produce this information in a
446446
[OCI Image Spec](https://github.com/opencontainers/image-spec/blob/master/image-layout.md)
447447
`index.json` file. This file should be placed on a location as specified in the
448-
task definition under the resource `outputImageDir`. Annotations in `index.json`
449-
will be ignored, and if there are multiple versions of the image, the latest
450-
will be used.
448+
task definition under the resource `outputImageDir`. If there is only one image
449+
in the `index.json` file, the digest of that image is exported; otherwise, the
450+
digest of the whole image index would be exported.
451451

452452
For example this build-push task defines the `outputImageDir` for the
453453
`builtImage` resource in `/workspace/buildImage`

0 commit comments

Comments
 (0)