Skip to content

Commit

Permalink
resurrect --all flag for cp to target oneoff container
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Oct 25, 2024
1 parent aa1ec45 commit 7c46beb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
4 changes: 1 addition & 3 deletions cmd/compose/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ func copyCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service)

flags := copyCmd.Flags()
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.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.BoolVar(&opts.all, "all", false, "Include containers created by the run command")
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)")

Expand Down
1 change: 1 addition & 0 deletions docs/reference/compose_cp.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Copy files/folders between a service container and the local filesystem

| Name | Type | Default | Description |
|:----------------------|:-------|:--------|:--------------------------------------------------------|
| `--all` | `bool` | | Include containers created by the run command |
| `-a`, `--archive` | `bool` | | Archive mode (copy all uid/gid information) |
| `--dry-run` | `bool` | | Execute command in dry run mode |
| `-L`, `--follow-link` | `bool` | | Always follow symbol link in SRC_PATH |
Expand Down
6 changes: 3 additions & 3 deletions docs/reference/docker_compose_cp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ options:
- option: all
value_type: bool
default_value: "false"
description: Copy to all the containers of the service
deprecated: true
hidden: true
description: Include containers created by the run command
deprecated: false
hidden: false
experimental: false
experimentalcli: false
kubernetes: false
Expand Down
19 changes: 9 additions & 10 deletions pkg/compose/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ func (s *composeService) copy(ctx context.Context, projectName string, options a
direction |= fromService
serviceName = srcService
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 != "" {
direction |= toService
Expand All @@ -80,7 +75,7 @@ func (s *composeService) copy(ctx context.Context, projectName string, options a
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 {
return err
}
Expand Down Expand Up @@ -119,18 +114,22 @@ func (s *composeService) copy(ctx context.Context, projectName string, options a
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 err error
switch {
case index > 0:
ctr, err := s.getSpecifiedContainer(ctx, projectName, oneOffExclude, true, serviceName, index)
case options.Index > 0:
ctr, err := s.getSpecifiedContainer(ctx, projectName, oneOffExclude, true, serviceName, options.Index)
if err != nil {
return nil, err
}
return append(containers, ctr), nil
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 {
return nil, err
}
Expand Down

0 comments on commit 7c46beb

Please sign in to comment.