MCPcopy
hub / github.com/containerd/containerd / Install

Method Install

client/install.go:37–109  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

35// Install a binary image into the opt service.
36// More info: https://github.com/containerd/containerd/blob/main/docs/managed-opt.md.
37func (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}

Callers 1

install.goFile · 0.80

Calls 13

getInstallPathMethod · 0.95
ManifestFunction · 0.92
NewReaderFunction · 0.92
DecompressStreamFunction · 0.92
WithFilterFunction · 0.92
WithNoSameOwnerFunction · 0.92
ApplyFunction · 0.92
DirMethod · 0.80
LstatMethod · 0.80
ContentStoreMethod · 0.65
TargetMethod · 0.65
ReaderAtMethod · 0.65

Tested by

no test coverage detected