From d21f0f116e29e498eeebf8440e9f43a06cf39cfc Mon Sep 17 00:00:00 2001 From: Ameya Gawde Date: Wed, 30 Oct 2019 08:03:59 -0700 Subject: [PATCH] windows process shim installer Signed-off-by: Ameya Gawde --- docs/managed-opt.md | 12 ++++++++++++ install.go | 20 ++++++++++++++++++-- services/opt/service.go | 19 ++++++++----------- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/docs/managed-opt.md b/docs/managed-opt.md index 7fe1db137..73955d6e8 100644 --- a/docs/managed-opt.md +++ b/docs/managed-opt.md @@ -91,3 +91,15 @@ ctr: OCI runtime create failed: unable to retrieve OCI runtime error (open /run/ 1:M 01 Aug 15:59:53.484 * DB saved on disk 1:M 01 Aug 15:59:53.484 # Redis is now ready to exit, bye bye... ``` +For Windows: + +```Dockerfile +FROM mcr.microsoft.com/windows/nanoserver:1809 +ADD runhcs.exe /bin/runhcs.exe +``` + +```powershell +> ctr content fetch docker.io/ameyagawde/runhcs:1809 #An example image, not supported by containerd +> ctr install docker.io/ameyagawde/runhcs:1809 +``` +The Windows equivalent for `/opt/containerd` will be `$env:ProgramData\containerd\root\opt` \ No newline at end of file diff --git a/install.go b/install.go index 5b8b735de..df6c8bc8a 100644 --- a/install.go +++ b/install.go @@ -21,6 +21,8 @@ import ( "context" "os" "path/filepath" + "runtime" + "strings" introspectionapi "github.com/containerd/containerd/api/services/introspection/v1" "github.com/containerd/containerd/archive" @@ -48,6 +50,15 @@ func (c *Client) Install(ctx context.Context, image Image, opts ...InstallOpts) if err != nil { return err } + + var binDir, libDir string + if runtime.GOOS == "windows" { + binDir = "Files\\bin" + libDir = "Files\\lib" + } else { + binDir = "bin" + libDir = "lib" + } for _, layer := range manifest.Layers { ra, err := cs.ReaderAt(ctx, layer) if err != nil { @@ -60,9 +71,14 @@ func (c *Client) Install(ctx context.Context, image Image, opts ...InstallOpts) } if _, err := archive.Apply(ctx, path, r, archive.WithFilter(func(hdr *tar.Header) (bool, error) { d := filepath.Dir(hdr.Name) - result := d == "bin" + result := d == binDir + if config.Libs { - result = result || d == "lib" + result = result || d == libDir + } + + if runtime.GOOS == "windows" { + hdr.Name = strings.Replace(hdr.Name, "Files", "", 1) } if result && !config.Replace { if _, err := os.Lstat(filepath.Join(path, hdr.Name)); err == nil { diff --git a/services/opt/service.go b/services/opt/service.go index 756a05f0a..5ac7665f1 100644 --- a/services/opt/service.go +++ b/services/opt/service.go @@ -20,7 +20,6 @@ import ( "fmt" "os" "path/filepath" - "runtime" "github.com/containerd/containerd/plugin" "github.com/pkg/errors" @@ -42,22 +41,20 @@ func init() { InitFn: func(ic *plugin.InitContext) (interface{}, error) { path := ic.Config.(*Config).Path ic.Meta.Exports["path"] = path - bin := filepath.Join(path, "bin") if err := os.MkdirAll(bin, 0711); err != nil { return nil, err } - if err := os.Setenv("PATH", fmt.Sprintf("%s:%s", bin, os.Getenv("PATH"))); err != nil { + if err := os.Setenv("PATH", fmt.Sprintf("%s%c%s", bin, os.PathListSeparator, os.Getenv("PATH"))); err != nil { return nil, errors.Wrapf(err, "set binary image directory in path %s", bin) } - if runtime.GOOS != "windows" { - lib := filepath.Join(path, "lib") - if err := os.MkdirAll(lib, 0711); err != nil { - return nil, err - } - if err := os.Setenv("LD_LIBRARY_PATH", fmt.Sprintf("%s:%s", os.Getenv("LD_LIBRARY_PATH"), lib)); err != nil { - return nil, errors.Wrapf(err, "set binary lib directory in path %s", lib) - } + + lib := filepath.Join(path, "lib") + if err := os.MkdirAll(lib, 0711); err != nil { + return nil, err + } + if err := os.Setenv("LD_LIBRARY_PATH", fmt.Sprintf("%s%c%s", lib, os.PathListSeparator, os.Getenv("LD_LIBRARY_PATH"))); err != nil { + return nil, errors.Wrapf(err, "set binary lib directory in path %s", lib) } return &manager{}, nil },