X Tutup
Skip to content

Commit d21f0f1

Browse files
committed
windows process shim installer
Signed-off-by: Ameya Gawde <ameya.gawde@docker.com>
1 parent 342ce3e commit d21f0f1

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

docs/managed-opt.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,15 @@ ctr: OCI runtime create failed: unable to retrieve OCI runtime error (open /run/
9191
1:M 01 Aug 15:59:53.484 * DB saved on disk
9292
1:M 01 Aug 15:59:53.484 # Redis is now ready to exit, bye bye...
9393
```
94+
For Windows:
95+
96+
```Dockerfile
97+
FROM mcr.microsoft.com/windows/nanoserver:1809
98+
ADD runhcs.exe /bin/runhcs.exe
99+
```
100+
101+
```powershell
102+
> ctr content fetch docker.io/ameyagawde/runhcs:1809 #An example image, not supported by containerd
103+
> ctr install docker.io/ameyagawde/runhcs:1809
104+
```
105+
The Windows equivalent for `/opt/containerd` will be `$env:ProgramData\containerd\root\opt`

install.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"context"
2222
"os"
2323
"path/filepath"
24+
"runtime"
25+
"strings"
2426

2527
introspectionapi "github.com/containerd/containerd/api/services/introspection/v1"
2628
"github.com/containerd/containerd/archive"
@@ -48,6 +50,15 @@ func (c *Client) Install(ctx context.Context, image Image, opts ...InstallOpts)
4850
if err != nil {
4951
return err
5052
}
53+
54+
var binDir, libDir string
55+
if runtime.GOOS == "windows" {
56+
binDir = "Files\\bin"
57+
libDir = "Files\\lib"
58+
} else {
59+
binDir = "bin"
60+
libDir = "lib"
61+
}
5162
for _, layer := range manifest.Layers {
5263
ra, err := cs.ReaderAt(ctx, layer)
5364
if err != nil {
@@ -60,9 +71,14 @@ func (c *Client) Install(ctx context.Context, image Image, opts ...InstallOpts)
6071
}
6172
if _, err := archive.Apply(ctx, path, r, archive.WithFilter(func(hdr *tar.Header) (bool, error) {
6273
d := filepath.Dir(hdr.Name)
63-
result := d == "bin"
74+
result := d == binDir
75+
6476
if config.Libs {
65-
result = result || d == "lib"
77+
result = result || d == libDir
78+
}
79+
80+
if runtime.GOOS == "windows" {
81+
hdr.Name = strings.Replace(hdr.Name, "Files", "", 1)
6682
}
6783
if result && !config.Replace {
6884
if _, err := os.Lstat(filepath.Join(path, hdr.Name)); err == nil {

services/opt/service.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"fmt"
2121
"os"
2222
"path/filepath"
23-
"runtime"
2423

2524
"github.com/containerd/containerd/plugin"
2625
"github.com/pkg/errors"
@@ -42,22 +41,20 @@ func init() {
4241
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
4342
path := ic.Config.(*Config).Path
4443
ic.Meta.Exports["path"] = path
45-
4644
bin := filepath.Join(path, "bin")
4745
if err := os.MkdirAll(bin, 0711); err != nil {
4846
return nil, err
4947
}
50-
if err := os.Setenv("PATH", fmt.Sprintf("%s:%s", bin, os.Getenv("PATH"))); err != nil {
48+
if err := os.Setenv("PATH", fmt.Sprintf("%s%c%s", bin, os.PathListSeparator, os.Getenv("PATH"))); err != nil {
5149
return nil, errors.Wrapf(err, "set binary image directory in path %s", bin)
5250
}
53-
if runtime.GOOS != "windows" {
54-
lib := filepath.Join(path, "lib")
55-
if err := os.MkdirAll(lib, 0711); err != nil {
56-
return nil, err
57-
}
58-
if err := os.Setenv("LD_LIBRARY_PATH", fmt.Sprintf("%s:%s", os.Getenv("LD_LIBRARY_PATH"), lib)); err != nil {
59-
return nil, errors.Wrapf(err, "set binary lib directory in path %s", lib)
60-
}
51+
52+
lib := filepath.Join(path, "lib")
53+
if err := os.MkdirAll(lib, 0711); err != nil {
54+
return nil, err
55+
}
56+
if err := os.Setenv("LD_LIBRARY_PATH", fmt.Sprintf("%s%c%s", lib, os.PathListSeparator, os.Getenv("LD_LIBRARY_PATH"))); err != nil {
57+
return nil, errors.Wrapf(err, "set binary lib directory in path %s", lib)
6158
}
6259
return &manager{}, nil
6360
},

0 commit comments

Comments
 (0)
X Tutup