windows process shim installer

Signed-off-by: Ameya Gawde <ameya.gawde@docker.com>
This commit is contained in:
Ameya Gawde 2019-10-30 08:03:59 -07:00
parent 342ce3e602
commit d21f0f116e
No known key found for this signature in database
GPG Key ID: 932609844D310CD2
3 changed files with 38 additions and 13 deletions

View File

@ -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 * DB saved on disk
1:M 01 Aug 15:59:53.484 # Redis is now ready to exit, bye bye... 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`

View File

@ -21,6 +21,8 @@ import (
"context" "context"
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"strings"
introspectionapi "github.com/containerd/containerd/api/services/introspection/v1" introspectionapi "github.com/containerd/containerd/api/services/introspection/v1"
"github.com/containerd/containerd/archive" "github.com/containerd/containerd/archive"
@ -48,6 +50,15 @@ func (c *Client) Install(ctx context.Context, image Image, opts ...InstallOpts)
if err != nil { if err != nil {
return err 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 { for _, layer := range manifest.Layers {
ra, err := cs.ReaderAt(ctx, layer) ra, err := cs.ReaderAt(ctx, layer)
if err != nil { 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) { if _, err := archive.Apply(ctx, path, r, archive.WithFilter(func(hdr *tar.Header) (bool, error) {
d := filepath.Dir(hdr.Name) d := filepath.Dir(hdr.Name)
result := d == "bin" result := d == binDir
if config.Libs { 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 result && !config.Replace {
if _, err := os.Lstat(filepath.Join(path, hdr.Name)); err == nil { if _, err := os.Lstat(filepath.Join(path, hdr.Name)); err == nil {

View File

@ -20,7 +20,6 @@ import (
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"github.com/containerd/containerd/plugin" "github.com/containerd/containerd/plugin"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -42,22 +41,20 @@ func init() {
InitFn: func(ic *plugin.InitContext) (interface{}, error) { InitFn: func(ic *plugin.InitContext) (interface{}, error) {
path := ic.Config.(*Config).Path path := ic.Config.(*Config).Path
ic.Meta.Exports["path"] = path ic.Meta.Exports["path"] = path
bin := filepath.Join(path, "bin") bin := filepath.Join(path, "bin")
if err := os.MkdirAll(bin, 0711); err != nil { if err := os.MkdirAll(bin, 0711); err != nil {
return nil, err 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) return nil, errors.Wrapf(err, "set binary image directory in path %s", bin)
} }
if runtime.GOOS != "windows" {
lib := filepath.Join(path, "lib") lib := filepath.Join(path, "lib")
if err := os.MkdirAll(lib, 0711); err != nil { if err := os.MkdirAll(lib, 0711); err != nil {
return nil, err return nil, err
} }
if err := os.Setenv("LD_LIBRARY_PATH", fmt.Sprintf("%s:%s", os.Getenv("LD_LIBRARY_PATH"), lib)); err != nil { 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 nil, errors.Wrapf(err, "set binary lib directory in path %s", lib)
}
} }
return &manager{}, nil return &manager{}, nil
}, },