(ctx context.Context, client *containerd.Client, container containerd.Container, args []string, options types.ContainerExecOptions)
| 61 | } |
| 62 | |
| 63 | func execActionWithContainer(ctx context.Context, client *containerd.Client, container containerd.Container, args []string, options types.ContainerExecOptions) error { |
| 64 | pspec, err := generateExecProcessSpec(ctx, client, container, args, options) |
| 65 | if err != nil { |
| 66 | return err |
| 67 | } |
| 68 | |
| 69 | task, err := container.Task(ctx, nil) |
| 70 | if err != nil { |
| 71 | return err |
| 72 | } |
| 73 | var ( |
| 74 | ioCreator cio.Creator |
| 75 | in io.Reader |
| 76 | stdinC = &taskutil.StdinCloser{ |
| 77 | Stdin: os.Stdin, |
| 78 | } |
| 79 | ) |
| 80 | |
| 81 | if options.Interactive { |
| 82 | in = stdinC |
| 83 | } |
| 84 | cioOpts := []cio.Opt{cio.WithStreams(in, os.Stdout, os.Stderr)} |
| 85 | if options.TTY { |
| 86 | cioOpts = append(cioOpts, cio.WithTerminal) |
| 87 | } |
| 88 | ioCreator = cio.NewCreator(cioOpts...) |
| 89 | |
| 90 | execID := "exec-" + idgen.GenerateID() |
| 91 | process, err := task.Exec(ctx, execID, pspec, ioCreator) |
| 92 | if err != nil { |
| 93 | return err |
| 94 | } |
| 95 | stdinC.Closer = func() { |
| 96 | process.CloseIO(ctx, containerd.WithStdinCloser) |
| 97 | } |
| 98 | // if detach, we should not call this defer |
| 99 | if !options.Detach { |
| 100 | defer process.Delete(ctx) |
| 101 | } |
| 102 | |
| 103 | statusC, err := process.Wait(ctx) |
| 104 | if err != nil { |
| 105 | return err |
| 106 | } |
| 107 | |
| 108 | var con console.Console |
| 109 | if options.TTY { |
| 110 | con, err = consoleutil.Current() |
| 111 | if err != nil { |
| 112 | return err |
| 113 | } |
| 114 | defer con.Reset() |
| 115 | if _, err := term.MakeRaw(int(con.Fd())); err != nil { |
| 116 | return err |
| 117 | } |
| 118 | } |
| 119 | if !options.Detach { |
| 120 | if options.TTY { |
no test coverage detected
searching dependent graphs…