github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/libcontainerd/remote/client_windows.go (about)

     1  package remote // import "github.com/docker/docker/libcontainerd/remote"
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"os"
     7  	"path/filepath"
     8  
     9  	"github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/options"
    10  	"github.com/containerd/containerd"
    11  	"github.com/containerd/containerd/cio"
    12  	"github.com/containerd/containerd/containers"
    13  	libcontainerdtypes "github.com/docker/docker/libcontainerd/types"
    14  	specs "github.com/opencontainers/runtime-spec/specs-go"
    15  	"github.com/pkg/errors"
    16  	"github.com/sirupsen/logrus"
    17  )
    18  
    19  const (
    20  	runtimeName       = "io.containerd.runhcs.v1"
    21  	shimV2RuntimeName = runtimeName
    22  )
    23  
    24  func summaryFromInterface(i interface{}) (*libcontainerdtypes.Summary, error) {
    25  	switch pd := i.(type) {
    26  	case *options.ProcessDetails:
    27  		return &libcontainerdtypes.Summary{
    28  			ImageName:                    pd.ImageName,
    29  			CreatedAt:                    pd.CreatedAt,
    30  			KernelTime_100Ns:             pd.KernelTime_100Ns,
    31  			MemoryCommitBytes:            pd.MemoryCommitBytes,
    32  			MemoryWorkingSetPrivateBytes: pd.MemoryWorkingSetPrivateBytes,
    33  			MemoryWorkingSetSharedBytes:  pd.MemoryWorkingSetSharedBytes,
    34  			ProcessID:                    pd.ProcessID,
    35  			UserTime_100Ns:               pd.UserTime_100Ns,
    36  			ExecID:                       pd.ExecID,
    37  		}, nil
    38  	default:
    39  		return nil, errors.Errorf("Unknown process details type %T", pd)
    40  	}
    41  }
    42  
    43  // WithBundle creates the bundle for the container
    44  func WithBundle(bundleDir string, ociSpec *specs.Spec) containerd.NewContainerOpts {
    45  	return func(ctx context.Context, client *containerd.Client, c *containers.Container) error {
    46  		// TODO: (containerd) Determine if we need to use system.MkdirAllWithACL here
    47  		if c.Labels == nil {
    48  			c.Labels = make(map[string]string)
    49  		}
    50  		c.Labels[DockerContainerBundlePath] = bundleDir
    51  		return os.MkdirAll(bundleDir, 0755)
    52  	}
    53  }
    54  
    55  func withLogLevel(level logrus.Level) containerd.NewTaskOpts {
    56  	// Make sure we set the runhcs options to debug if we are at debug level.
    57  	return func(_ context.Context, _ *containerd.Client, info *containerd.TaskInfo) error {
    58  		if level == logrus.DebugLevel {
    59  			info.Options = &options.Options{Debug: true}
    60  		}
    61  		return nil
    62  	}
    63  }
    64  
    65  func pipeName(containerID, processID, name string) string {
    66  	return fmt.Sprintf(`\\.\pipe\containerd-%s-%s-%s`, containerID, processID, name)
    67  }
    68  
    69  func newFIFOSet(bundleDir, processID string, withStdin, withTerminal bool) *cio.FIFOSet {
    70  	containerID := filepath.Base(bundleDir)
    71  	config := cio.Config{
    72  		Terminal: withTerminal,
    73  		Stdout:   pipeName(containerID, processID, "stdout"),
    74  	}
    75  
    76  	if withStdin {
    77  		config.Stdin = pipeName(containerID, processID, "stdin")
    78  	}
    79  
    80  	if !config.Terminal {
    81  		config.Stderr = pipeName(containerID, processID, "stderr")
    82  	}
    83  
    84  	return cio.NewFIFOSet(config, nil)
    85  }
    86  
    87  func (c *client) newDirectIO(ctx context.Context, fifos *cio.FIFOSet) (*cio.DirectIO, error) {
    88  	pipes, err := c.newStdioPipes(fifos)
    89  	if err != nil {
    90  		return nil, err
    91  	}
    92  	return cio.NewDirectIOFromFIFOSet(ctx, pipes.stdin, pipes.stdout, pipes.stderr, fifos), nil
    93  }
    94  
    95  func (c *client) UpdateResources(ctx context.Context, containerID string, resources *libcontainerdtypes.Resources) error {
    96  	// TODO: (containerd): Not implemented, but don't error.
    97  	return nil
    98  }
    99  
   100  func getSpecUser(ociSpec *specs.Spec) (int, int) {
   101  	// TODO: (containerd): Not implemented, but don't error.
   102  	// Not clear if we can even do this for LCOW.
   103  	return 0, 0
   104  }