(ctx context.Context, projectName string, options api.RunOptions)
| 29 | ) |
| 30 | |
| 31 | func (s *composeService) Exec(ctx context.Context, projectName string, options api.RunOptions) (int, error) { |
| 32 | projectName = strings.ToLower(projectName) |
| 33 | target, err := s.getExecTarget(ctx, projectName, options) |
| 34 | if err != nil { |
| 35 | return 0, err |
| 36 | } |
| 37 | |
| 38 | exec := container.NewExecOptions() |
| 39 | exec.Interactive = options.Interactive |
| 40 | exec.TTY = options.Tty |
| 41 | exec.Detach = options.Detach |
| 42 | exec.User = options.User |
| 43 | exec.Privileged = options.Privileged |
| 44 | exec.Workdir = options.WorkingDir |
| 45 | exec.Command = options.Command |
| 46 | for _, v := range options.Environment { |
| 47 | err := exec.Env.Set(v) |
| 48 | if err != nil { |
| 49 | return 0, err |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | err = container.RunExec(ctx, s.dockerCli, target.ID, exec) |
| 54 | var sterr cli.StatusError |
| 55 | if errors.As(err, &sterr) { |
| 56 | return sterr.StatusCode, err |
| 57 | } |
| 58 | return 0, err |
| 59 | } |
| 60 | |
| 61 | func (s *composeService) getExecTarget(ctx context.Context, projectName string, opts api.RunOptions) (containerType.Summary, error) { |
| 62 | return s.getSpecifiedContainer(ctx, projectName, oneOffInclude, false, opts.Service, opts.Index) |
nothing calls this directly
no test coverage detected