Add lib support as an option

Some images like `criu` will have extra libs that it requires.  This
adds lib support via LD_LIBRARY_PATH and InstallOpts

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2018-08-01 15:49:39 -04:00
parent 1537f31381
commit 5a47c5ec1d
9 changed files with 101 additions and 11 deletions

View File

@@ -19,7 +19,7 @@ package containerd
import (
"archive/tar"
"context"
"errors"
"os"
"path/filepath"
introspectionapi "github.com/containerd/containerd/api/services/introspection/v1"
@@ -28,10 +28,11 @@ import (
"github.com/containerd/containerd/content"
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/platforms"
"github.com/pkg/errors"
)
// Install a binary image into the opt service
func (c *Client) Install(ctx context.Context, image Image) error {
func (c *Client) Install(ctx context.Context, image Image, opts ...InstallOpts) error {
resp, err := c.IntrospectionService().Plugins(ctx, &introspectionapi.PluginsRequest{
Filters: []string{
"id==opt",
@@ -47,6 +48,10 @@ func (c *Client) Install(ctx context.Context, image Image) error {
if path == "" {
return errors.New("opt path not exported")
}
var config InstallConfig
for _, o := range opts {
o(&config)
}
var (
cs = image.ContentStore()
platform = platforms.Default()
@@ -66,8 +71,18 @@ func (c *Client) Install(ctx context.Context, image Image) error {
return err
}
defer r.Close()
if _, err := archive.Apply(ctx, path, r, archive.WithFilter(func(hdr *tar.Header) bool {
return filepath.Dir(hdr.Name) == "bin"
if _, err := archive.Apply(ctx, path, r, archive.WithFilter(func(hdr *tar.Header) (bool, error) {
d := filepath.Dir(hdr.Name)
result := d == "bin"
if config.Libs {
result = result || d == "lib"
}
if result && !config.Replace {
if _, err := os.Lstat(filepath.Join(path, hdr.Name)); err == nil {
return false, errors.Errorf("cannot replace %s in %s", hdr.Name, path)
}
}
return result, nil
})); err != nil {
return err
}