MCPcopy Create free account
hub / github.com/docker/buildx / addPinToImage

Function addPinToImage

policy/funcs.go:668–693  ·  view source on GitHub ↗
(src *pb.SourceOp, dgst digest.Digest)

Source from the content-addressed store, hash-verified

666}
667
668func addPinToImage(src *pb.SourceOp, dgst digest.Digest) (*pb.SourceOp, error) {
669 id, ok := strings.CutPrefix(src.Identifier, "docker-image://")
670 if !ok {
671 return nil, errors.Errorf("cannot pin non-image source: %q", src.Identifier)
672 }
673
674 ref, err := reference.ParseNormalizedNamed(id)
675 if err != nil {
676 return nil, errors.Wrapf(err, "failed parsing image reference %q", id)
677 }
678
679 newRef, err := reference.WithDigest(ref, dgst)
680 if err != nil {
681 return nil, errors.Wrapf(err, "failed adding digest to image reference %q", id)
682 }
683 attrs := maps.Clone(src.Attrs)
684 if attrs == nil {
685 attrs = make(map[string]string)
686 }
687 attrs["image.checksum"] = dgst.String()
688
689 return &pb.SourceOp{
690 Identifier: "docker-image://" + newRef.String(),
691 Attrs: attrs,
692 }, nil
693}

Callers 1

CheckPolicyMethod · 0.85

Calls 2

WithDigestMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…