Skip to content

Commit

Permalink
windows process shim installer
Browse files Browse the repository at this point in the history
Signed-off-by: Ameya Gawde <ameya.gawde@docker.com>
  • Loading branch information
ameyag committed Oct 30, 2019
1 parent 342ce3e commit d21f0f1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
12 changes: 12 additions & 0 deletions docs/managed-opt.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
20 changes: 18 additions & 2 deletions install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
19 changes: 8 additions & 11 deletions services/opt/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"

"github.com/containerd/containerd/plugin"
"github.com/pkg/errors"
Expand All @@ -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
},
Expand Down

0 comments on commit d21f0f1

Please sign in to comment.