Install a binary image into the opt service. More info: https://github.com/containerd/containerd/blob/main/docs/managed-opt.md.
(ctx context.Context, image Image, opts ...InstallOpts)
| 35 | // Install a binary image into the opt service. |
| 36 | // More info: https://github.com/containerd/containerd/blob/main/docs/managed-opt.md. |
| 37 | func (c *Client) Install(ctx context.Context, image Image, opts ...InstallOpts) error { |
| 38 | var config InstallConfig |
| 39 | for _, o := range opts { |
| 40 | o(&config) |
| 41 | } |
| 42 | path, err := c.getInstallPath(ctx, config) |
| 43 | if err != nil { |
| 44 | return err |
| 45 | } |
| 46 | var ( |
| 47 | cs = image.ContentStore() |
| 48 | platform = c.platform |
| 49 | ) |
| 50 | manifest, err := images.Manifest(ctx, cs, image.Target(), platform) |
| 51 | if err != nil { |
| 52 | return err |
| 53 | } |
| 54 | |
| 55 | var binDir, libDir string |
| 56 | if runtime.GOOS == "windows" { |
| 57 | binDir = "Files\\bin" |
| 58 | libDir = "Files\\lib" |
| 59 | } else { |
| 60 | binDir = "bin" |
| 61 | libDir = "lib" |
| 62 | } |
| 63 | for _, layer := range manifest.Layers { |
| 64 | ra, err := cs.ReaderAt(ctx, layer) |
| 65 | if err != nil { |
| 66 | return err |
| 67 | } |
| 68 | cr := content.NewReader(ra) |
| 69 | r, err := compression.DecompressStream(cr) |
| 70 | if err != nil { |
| 71 | ra.Close() |
| 72 | return err |
| 73 | } |
| 74 | |
| 75 | filter := archive.WithFilter(func(hdr *tar.Header) (bool, error) { |
| 76 | d := filepath.Dir(hdr.Name) |
| 77 | result := d == binDir |
| 78 | |
| 79 | if config.Libs { |
| 80 | result = result || d == libDir |
| 81 | } |
| 82 | |
| 83 | if runtime.GOOS == "windows" { |
| 84 | hdr.Name = strings.Replace(hdr.Name, "Files", "", 1) |
| 85 | } |
| 86 | if result && !config.Replace { |
| 87 | if _, err := os.Lstat(filepath.Join(path, hdr.Name)); err == nil { |
| 88 | return false, fmt.Errorf("cannot replace %s in %s", hdr.Name, path) |
| 89 | } |
| 90 | } |
| 91 | return result, nil |
| 92 | }) |
| 93 | |
| 94 | opts := []archive.ApplyOpt{filter} |
no test coverage detected