resurrect --all flag for cp to target oneoff container

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2024-10-23 09:05:49 +02:00 committed by Nicolas De loof
parent aa1ec4524c
commit 7c46beb8af
4 changed files with 14 additions and 16 deletions

View File

@ -66,9 +66,7 @@ func copyCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service)
flags := copyCmd.Flags() flags := copyCmd.Flags()
flags.IntVar(&opts.index, "index", 0, "Index of the container if service has multiple replicas") flags.IntVar(&opts.index, "index", 0, "Index of the container if service has multiple replicas")
flags.BoolVar(&opts.all, "all", false, "Copy to all the containers of the service") flags.BoolVar(&opts.all, "all", false, "Include containers created by the run command")
flags.MarkHidden("all") //nolint:errcheck
flags.MarkDeprecated("all", "By default all the containers of the service will get the source file/directory to be copied") //nolint:errcheck
flags.BoolVarP(&opts.followLink, "follow-link", "L", false, "Always follow symbol link in SRC_PATH") flags.BoolVarP(&opts.followLink, "follow-link", "L", false, "Always follow symbol link in SRC_PATH")
flags.BoolVarP(&opts.copyUIDGID, "archive", "a", false, "Archive mode (copy all uid/gid information)") flags.BoolVarP(&opts.copyUIDGID, "archive", "a", false, "Archive mode (copy all uid/gid information)")

View File

@ -7,6 +7,7 @@ Copy files/folders between a service container and the local filesystem
| Name | Type | Default | Description | | Name | Type | Default | Description |
|:----------------------|:-------|:--------|:--------------------------------------------------------| |:----------------------|:-------|:--------|:--------------------------------------------------------|
| `--all` | `bool` | | Include containers created by the run command |
| `-a`, `--archive` | `bool` | | Archive mode (copy all uid/gid information) | | `-a`, `--archive` | `bool` | | Archive mode (copy all uid/gid information) |
| `--dry-run` | `bool` | | Execute command in dry run mode | | `--dry-run` | `bool` | | Execute command in dry run mode |
| `-L`, `--follow-link` | `bool` | | Always follow symbol link in SRC_PATH | | `-L`, `--follow-link` | `bool` | | Always follow symbol link in SRC_PATH |

View File

@ -10,9 +10,9 @@ options:
- option: all - option: all
value_type: bool value_type: bool
default_value: "false" default_value: "false"
description: Copy to all the containers of the service description: Include containers created by the run command
deprecated: true deprecated: false
hidden: true hidden: false
experimental: false experimental: false
experimentalcli: false experimentalcli: false
kubernetes: false kubernetes: false

View File

@ -61,11 +61,6 @@ func (s *composeService) copy(ctx context.Context, projectName string, options a
direction |= fromService direction |= fromService
serviceName = srcService serviceName = srcService
copyFunc = s.copyFromContainer copyFunc = s.copyFromContainer
// copying from multiple containers of a services doesn't make sense.
if options.All {
return errors.New("cannot use the --all flag when copying from a service")
}
} }
if destService != "" { if destService != "" {
direction |= toService direction |= toService
@ -80,7 +75,7 @@ func (s *composeService) copy(ctx context.Context, projectName string, options a
return errors.New("unknown copy direction") return errors.New("unknown copy direction")
} }
containers, err := s.listContainersTargetedForCopy(ctx, projectName, options.Index, direction, serviceName) containers, err := s.listContainersTargetedForCopy(ctx, projectName, options, direction, serviceName)
if err != nil { if err != nil {
return err return err
} }
@ -119,18 +114,22 @@ func (s *composeService) copy(ctx context.Context, projectName string, options a
return g.Wait() return g.Wait()
} }
func (s *composeService) listContainersTargetedForCopy(ctx context.Context, projectName string, index int, direction copyDirection, serviceName string) (Containers, error) { func (s *composeService) listContainersTargetedForCopy(ctx context.Context, projectName string, options api.CopyOptions, direction copyDirection, serviceName string) (Containers, error) {
var containers Containers var containers Containers
var err error var err error
switch { switch {
case index > 0: case options.Index > 0:
ctr, err := s.getSpecifiedContainer(ctx, projectName, oneOffExclude, true, serviceName, index) ctr, err := s.getSpecifiedContainer(ctx, projectName, oneOffExclude, true, serviceName, options.Index)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return append(containers, ctr), nil return append(containers, ctr), nil
default: default:
containers, err = s.getContainers(ctx, projectName, oneOffExclude, true, serviceName) withOneOff := oneOffExclude
if options.All {
withOneOff = oneOffInclude
}
containers, err = s.getContainers(ctx, projectName, withOneOff, true, serviceName)
if err != nil { if err != nil {
return nil, err return nil, err
} }