newImageSource returns an ImageSource for reading from an existing directory. newImageSource extracts SIF objects and saves them in a temp directory.
(ctx context.Context, sys *types.SystemContext, ref sifReference)
| 65 | // newImageSource returns an ImageSource for reading from an existing directory. |
| 66 | // newImageSource extracts SIF objects and saves them in a temp directory. |
| 67 | func newImageSource(ctx context.Context, sys *types.SystemContext, ref sifReference) (private.ImageSource, error) { |
| 68 | sifImg, err := sif.LoadContainerFromPath(ref.file, sif.OptLoadWithFlag(os.O_RDONLY)) |
| 69 | if err != nil { |
| 70 | return nil, fmt.Errorf("loading SIF file: %w", err) |
| 71 | } |
| 72 | defer func() { |
| 73 | _ = sifImg.UnloadContainer() |
| 74 | }() |
| 75 | |
| 76 | workDir, err := tmpdir.MkDirBigFileTemp(sys, "sif") |
| 77 | if err != nil { |
| 78 | return nil, fmt.Errorf("creating temp directory: %w", err) |
| 79 | } |
| 80 | succeeded := false |
| 81 | defer func() { |
| 82 | if !succeeded { |
| 83 | os.RemoveAll(workDir) |
| 84 | } |
| 85 | }() |
| 86 | |
| 87 | layerPath, commandLine, err := convertSIFToElements(ctx, sifImg, workDir) |
| 88 | if err != nil { |
| 89 | return nil, fmt.Errorf("converting rootfs from SquashFS to Tarball: %w", err) |
| 90 | } |
| 91 | |
| 92 | layerDigest, layerSize, err := getBlobInfo(layerPath) |
| 93 | if err != nil { |
| 94 | return nil, fmt.Errorf("gathering blob information: %w", err) |
| 95 | } |
| 96 | |
| 97 | created := sifImg.ModifiedAt() |
| 98 | config := imgspecv1.Image{ |
| 99 | Created: &created, |
| 100 | Platform: imgspecv1.Platform{ |
| 101 | Architecture: sifImg.PrimaryArch(), |
| 102 | OS: "linux", |
| 103 | }, |
| 104 | Config: imgspecv1.ImageConfig{ |
| 105 | Cmd: commandLine, |
| 106 | }, |
| 107 | RootFS: imgspecv1.RootFS{ |
| 108 | Type: "layers", |
| 109 | DiffIDs: []digest.Digest{layerDigest}, |
| 110 | }, |
| 111 | History: []imgspecv1.History{ |
| 112 | { |
| 113 | Created: &created, |
| 114 | CreatedBy: fmt.Sprintf("/bin/sh -c #(nop) ADD file:%s in %c", layerDigest.Encoded(), os.PathSeparator), |
| 115 | Comment: "imported from SIF, uuid: " + sifImg.ID(), |
| 116 | }, |
| 117 | { |
| 118 | Created: &created, |
| 119 | CreatedBy: "/bin/sh -c #(nop) CMD [\"bash\"]", |
| 120 | EmptyLayer: true, |
| 121 | }, |
| 122 | }, |
| 123 | } |
| 124 | configBytes, err := json.Marshal(&config) |
no test coverage detected
searching dependent graphs…