MCPcopy Index your code
hub / github.com/containerd/containerd / createImages

Function createImages

integration/client/import_test.go:751–834  ·  view source on GitHub ↗
(tc tartest.TarContext, imageNames ...string)

Source from the content-addressed store, hash-verified

749}
750
751func createImages(tc tartest.TarContext, imageNames ...string) (descs map[string]ocispec.Descriptor, tw []tartest.WriterToTar) {
752 descs = map[string]ocispec.Descriptor{}
753 idx := ocispec.Index{
754 Versioned: specs.Versioned{
755 SchemaVersion: 2,
756 },
757 }
758
759 // indexDigestRefs collects @<index> entries to be resolved with the
760 // index digest after the index is built.
761 var indexDigestRefs []string
762
763 if len(imageNames) > 1 {
764 var lastManifest ocispec.Descriptor
765
766 for _, image := range imageNames[1:] {
767 if name, ok := strings.CutSuffix(image, "@<index>"); ok {
768 indexDigestRefs = append(indexDigestRefs, name)
769 continue
770 }
771 if name, ok := strings.CutSuffix(image, "@<manifest>"); ok {
772 descs[fmt.Sprintf("%s@%s", name, lastManifest.Digest)] = lastManifest
773 continue
774 }
775 seed := hash64(image)
776 bb, b := createContent(128, seed)
777 tw = append(tw, tc.File(ocispec.ImageBlobsDir+"/sha256/"+b.Encoded(), bb, 0644))
778
779 cb, c := createConfig("linux", "amd64", image)
780 tw = append(tw, tc.File(ocispec.ImageBlobsDir+"/sha256/"+c.Encoded(), cb, 0644))
781
782 mb, m, _ := createManifest(cb, [][]byte{bb})
783 tw = append(tw, tc.File(ocispec.ImageBlobsDir+"/sha256/"+m.Encoded(), mb, 0644))
784
785 annotations := map[string]string{}
786 if image != "" {
787 if parts := strings.SplitN(image, " ", 2); len(parts) == 2 {
788 annotations[ocispec.AnnotationRefName] = parts[1]
789 image = strings.Join(parts, ":")
790 } else {
791 annotations[images.AnnotationImageName] = image
792 }
793 }
794
795 md := ocispec.Descriptor{
796 Digest: m,
797 Size: int64(len(mb)),
798 MediaType: ocispec.MediaTypeImageManifest,
799 Annotations: annotations,
800 }
801
802 // If image is empty, but has base and digest, still use digest
803 // If image is not a full reference, then add base if provided?
804 if image != "" {
805 descs[image] = md
806 }
807
808 idx.Manifests = append(idx.Manifests, md)

Callers 1

TestTransferImportFunction · 0.85

Calls 6

hash64Function · 0.85
createConfigFunction · 0.85
createManifestFunction · 0.85
createContentFunction · 0.70
FileMethod · 0.65
MarshalMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…