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)
| 42 | // "windows"), the contents of the tarballs will be modified to be suitable for |
| 43 | // a Windows container image.`, |
| 44 | func 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 | |
| 84 | func getLayer(path string, layerType types.MediaType) (v1.Layer, error) { |
| 85 | f, err := streamFile(path) |
searching dependent graphs…