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

Function Append

pkg/crane/append.go:44–82  ·  view source on GitHub ↗

Append reads a layer from path and appends it the the v1.Image base. If the base image is a Windows base image (i.e., its config.OS is "windows"), the contents of the tarballs will be modified to be suitable for a Windows container image.`,

(base v1.Image, paths ...string)

Source from the content-addressed store, hash-verified

42// "windows"), the contents of the tarballs will be modified to be suitable for
43// a Windows container image.`,
44func Append(base v1.Image, paths ...string) (v1.Image, error) {
45 if base == nil {
46 return nil, fmt.Errorf("invalid argument: base")
47 }
48
49 win, err := isWindows(base)
50 if err != nil {
51 return nil, fmt.Errorf("getting base image: %w", err)
52 }
53
54 baseMediaType, err := base.MediaType()
55 if err != nil {
56 return nil, fmt.Errorf("getting base image media type: %w", err)
57 }
58
59 layerType := types.DockerLayer
60 if baseMediaType == types.OCIManifestSchema1 {
61 layerType = types.OCILayer
62 }
63
64 layers := make([]v1.Layer, 0, len(paths))
65 for _, path := range paths {
66 layer, err := getLayer(path, layerType)
67 if err != nil {
68 return nil, fmt.Errorf("reading layer %q: %w", path, err)
69 }
70
71 if win {
72 layer, err = windows.Windows(layer)
73 if err != nil {
74 return nil, fmt.Errorf("converting %q for Windows: %w", path, err)
75 }
76 }
77
78 layers = append(layers, layer)
79 }
80
81 return mutate.AppendLayers(base, layers...)
82}
83
84func getLayer(path string, layerType types.MediaType) (v1.Layer, error) {
85 f, err := streamFile(path)

Callers 8

TestCraneFilesystemFunction · 0.92
TestStreamingAppendFunction · 0.92
TestBadInputsFunction · 0.92
TestAppendWithZstdFunction · 0.92
NewCmdMutateFunction · 0.92
NewCmdAppendFunction · 0.92

Calls 5

WindowsFunction · 0.92
AppendLayersFunction · 0.92
isWindowsFunction · 0.85
getLayerFunction · 0.85
MediaTypeMethod · 0.65

Tested by 6

TestCraneFilesystemFunction · 0.74
TestStreamingAppendFunction · 0.74
TestBadInputsFunction · 0.74
TestAppendWithZstdFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…