client_windows.go 3.1 KB

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