(ctx context.Context, client *containerd.Client, container containerd.Container, args []string, options types.ContainerExecOptions)
| 149 | } |
| 150 | |
| 151 | func generateExecProcessSpec(ctx context.Context, client *containerd.Client, container containerd.Container, args []string, options types.ContainerExecOptions) (*specs.Process, error) { |
| 152 | spec, err := container.Spec(ctx) |
| 153 | if err != nil { |
| 154 | return nil, err |
| 155 | } |
| 156 | userOpts, err := generateUserOpts(options.User) |
| 157 | if err != nil { |
| 158 | return nil, err |
| 159 | } |
| 160 | if userOpts != nil { |
| 161 | c, err := container.Info(ctx) |
| 162 | if err != nil { |
| 163 | return nil, err |
| 164 | } |
| 165 | for _, opt := range userOpts { |
| 166 | if err := opt(ctx, client, &c, spec); err != nil { |
| 167 | return nil, err |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | pspec := spec.Process |
| 173 | pspec.Terminal = options.TTY |
| 174 | if pspec.Terminal { |
| 175 | con, err := consoleutil.Current() |
| 176 | if err != nil { |
| 177 | return nil, err |
| 178 | } |
| 179 | if size, err := con.Size(); err == nil { |
| 180 | pspec.ConsoleSize = &specs.Box{Height: uint(size.Height), Width: uint(size.Width)} |
| 181 | } |
| 182 | } |
| 183 | pspec.Args = args[1:] |
| 184 | |
| 185 | if options.Workdir != "" { |
| 186 | pspec.Cwd = options.Workdir |
| 187 | } |
| 188 | envs, err := flagutil.MergeEnvFileAndOSEnv(options.EnvFile, options.Env) |
| 189 | if err != nil { |
| 190 | return nil, err |
| 191 | } |
| 192 | pspec.Env = flagutil.ReplaceOrAppendEnvValues(pspec.Env, envs) |
| 193 | |
| 194 | if options.Privileged { |
| 195 | err = setExecCapabilities(pspec) |
| 196 | if err != nil { |
| 197 | return nil, err |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | return pspec, nil |
| 202 | } |
no test coverage detected
searching dependent graphs…