Pull pull a reference, whether it points to an arch-specific image or to an index. If an index, optionally, try to pull its individual named references as well.
(name string, withArchReferences bool)
| 160 | // Pull pull a reference, whether it points to an arch-specific image or to an index. |
| 161 | // If an index, optionally, try to pull its individual named references as well. |
| 162 | func (p *Provider) Pull(name string, withArchReferences bool) error { |
| 163 | var ( |
| 164 | err error |
| 165 | ) |
| 166 | fullname := util.ReferenceExpand(name, util.ReferenceWithTag()) |
| 167 | ref, err := namepkg.ParseReference(fullname) |
| 168 | if err != nil { |
| 169 | return err |
| 170 | } |
| 171 | v1ref, err := reference.Parse(ref.String()) |
| 172 | if err != nil { |
| 173 | return err |
| 174 | } |
| 175 | |
| 176 | // before we even try to push, let us see if it exists remotely |
| 177 | remoteOptions := []remote.Option{remote.WithAuthFromKeychain(authn.DefaultKeychain)} |
| 178 | |
| 179 | desc, err := registry.GetRemote().Get(ref, remoteOptions...) |
| 180 | if err != nil { |
| 181 | return fmt.Errorf("error getting manifest for trusted image %s: %v", name, err) |
| 182 | } |
| 183 | |
| 184 | // lock the cache so we can write to it |
| 185 | if err := p.Lock(); err != nil { |
| 186 | return fmt.Errorf("unable to lock cache for writing: %v", err) |
| 187 | } |
| 188 | defer p.Unlock() |
| 189 | |
| 190 | // first attempt as an index |
| 191 | ii, err := desc.ImageIndex() |
| 192 | if err == nil { |
| 193 | log.Debugf("ImageWrite retrieved %s is index, saving", fullname) |
| 194 | |
| 195 | if err := p.cache.WriteIndex(ii); err != nil { |
| 196 | return fmt.Errorf("unable to write index: %v", err) |
| 197 | } |
| 198 | if err := p.DescriptorWrite(v1ref.String(), desc.Descriptor); err != nil { |
| 199 | return fmt.Errorf("unable to write index descriptor to cache: %v", err) |
| 200 | } |
| 201 | if withArchReferences { |
| 202 | im, err := ii.IndexManifest() |
| 203 | if err != nil { |
| 204 | return fmt.Errorf("unable to get IndexManifest: %v", err) |
| 205 | } |
| 206 | for _, m := range im.Manifests { |
| 207 | if m.MediaType.IsImage() && m.Platform != nil && m.Platform.Architecture != unknown && m.Platform.OS != unknown { |
| 208 | archSpecific := fmt.Sprintf("%s-%s", ref.String(), m.Platform.Architecture) |
| 209 | if _, err := reference.Parse(archSpecific); err != nil { |
| 210 | return fmt.Errorf("unable to parse arch-specific reference %s: %v", archSpecific, err) |
| 211 | } |
| 212 | if err := p.DescriptorWrite(archSpecific, m); err != nil { |
| 213 | return fmt.Errorf("unable to write index descriptor to cache: %v", err) |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | } else { |
| 219 | var im v1.Image |
no test coverage detected