MCPcopy
hub / github.com/google/go-containerregistry / appendLocal

Function appendLocal

cmd/crane/cmd/index.go:224–269  ·  view source on GitHub ↗
(baseRef string, adds []mutate.IndexAddendum)

Source from the content-addressed store, hash-verified

222}
223
224func appendLocal(baseRef string, adds []mutate.IndexAddendum) error {
225 var p layout.Path
226 if _, err := os.Stat(baseRef); err == nil {
227 // If the path exists, try to open it as an OCI layout.
228 var err error
229 p, err = layout.FromPath(baseRef)
230 if err != nil {
231 return err
232 }
233 } else {
234 // If the path does not exist, initialize a new OCI layout.
235 var err error
236 p, err = layout.Write(baseRef, empty.Index)
237 if err != nil {
238 return err
239 }
240 }
241
242 for _, add := range adds {
243 opts := []layout.Option{}
244 if add.Platform != nil {
245 opts = append(opts, layout.WithPlatform(*add.Platform))
246 }
247
248 if add.MediaType.IsImage() {
249 img, ok := add.Add.(v1.Image)
250 if !ok {
251 return fmt.Errorf("internal error: add.Add is not v1.Image: %T", add.Add)
252 }
253 if err := p.AppendImage(img, opts...); err != nil {
254 return err
255 }
256 } else if add.MediaType.IsIndex() {
257 idx, ok := add.Add.(v1.ImageIndex)
258 if !ok {
259 return fmt.Errorf("internal error: add.Add is not v1.ImageIndex: %T", add.Add)
260 }
261 if err := p.AppendIndex(idx, opts...); err != nil {
262 return err
263 }
264 } else {
265 return fmt.Errorf("unexpected media type for local append: %s", add.MediaType)
266 }
267 }
268 return nil
269}
270
271func appendRemote(cmd *cobra.Command, baseRef, newTag string, adds []mutate.IndexAddendum, o crane.Options, dockerEmptyBase bool) error {
272 var base v1.ImageIndex

Callers 1

NewCmdIndexAppendFunction · 0.85

Calls 8

AppendImageMethod · 0.95
AppendIndexMethod · 0.95
FromPathFunction · 0.92
WriteFunction · 0.92
WithPlatformFunction · 0.92
IsImageMethod · 0.80
IsIndexMethod · 0.80
StatMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…