Skip to content

Commit 7c46beb

Browse files
committed
resurrect --all flag for cp to target oneoff container
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent aa1ec45 commit 7c46beb

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

cmd/compose/cp.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ func copyCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service)
6666

6767
flags := copyCmd.Flags()
6868
flags.IntVar(&opts.index, "index", 0, "Index of the container if service has multiple replicas")
69-
flags.BoolVar(&opts.all, "all", false, "Copy to all the containers of the service")
70-
flags.MarkHidden("all") //nolint:errcheck
71-
flags.MarkDeprecated("all", "By default all the containers of the service will get the source file/directory to be copied") //nolint:errcheck
69+
flags.BoolVar(&opts.all, "all", false, "Include containers created by the run command")
7270
flags.BoolVarP(&opts.followLink, "follow-link", "L", false, "Always follow symbol link in SRC_PATH")
7371
flags.BoolVarP(&opts.copyUIDGID, "archive", "a", false, "Archive mode (copy all uid/gid information)")
7472

docs/reference/compose_cp.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Copy files/folders between a service container and the local filesystem
77

88
| Name | Type | Default | Description |
99
|:----------------------|:-------|:--------|:--------------------------------------------------------|
10+
| `--all` | `bool` | | Include containers created by the run command |
1011
| `-a`, `--archive` | `bool` | | Archive mode (copy all uid/gid information) |
1112
| `--dry-run` | `bool` | | Execute command in dry run mode |
1213
| `-L`, `--follow-link` | `bool` | | Always follow symbol link in SRC_PATH |

docs/reference/docker_compose_cp.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ options:
1010
- option: all
1111
value_type: bool
1212
default_value: "false"
13-
description: Copy to all the containers of the service
14-
deprecated: true
15-
hidden: true
13+
description: Include containers created by the run command
14+
deprecated: false
15+
hidden: false
1616
experimental: false
1717
experimentalcli: false
1818
kubernetes: false

pkg/compose/cp.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ func (s *composeService) copy(ctx context.Context, projectName string, options a
6161
direction |= fromService
6262
serviceName = srcService
6363
copyFunc = s.copyFromContainer
64-
65-
// copying from multiple containers of a services doesn't make sense.
66-
if options.All {
67-
return errors.New("cannot use the --all flag when copying from a service")
68-
}
6964
}
7065
if destService != "" {
7166
direction |= toService
@@ -80,7 +75,7 @@ func (s *composeService) copy(ctx context.Context, projectName string, options a
8075
return errors.New("unknown copy direction")
8176
}
8277

83-
containers, err := s.listContainersTargetedForCopy(ctx, projectName, options.Index, direction, serviceName)
78+
containers, err := s.listContainersTargetedForCopy(ctx, projectName, options, direction, serviceName)
8479
if err != nil {
8580
return err
8681
}
@@ -119,18 +114,22 @@ func (s *composeService) copy(ctx context.Context, projectName string, options a
119114
return g.Wait()
120115
}
121116

122-
func (s *composeService) listContainersTargetedForCopy(ctx context.Context, projectName string, index int, direction copyDirection, serviceName string) (Containers, error) {
117+
func (s *composeService) listContainersTargetedForCopy(ctx context.Context, projectName string, options api.CopyOptions, direction copyDirection, serviceName string) (Containers, error) {
123118
var containers Containers
124119
var err error
125120
switch {
126-
case index > 0:
127-
ctr, err := s.getSpecifiedContainer(ctx, projectName, oneOffExclude, true, serviceName, index)
121+
case options.Index > 0:
122+
ctr, err := s.getSpecifiedContainer(ctx, projectName, oneOffExclude, true, serviceName, options.Index)
128123
if err != nil {
129124
return nil, err
130125
}
131126
return append(containers, ctr), nil
132127
default:
133-
containers, err = s.getContainers(ctx, projectName, oneOffExclude, true, serviceName)
128+
withOneOff := oneOffExclude
129+
if options.All {
130+
withOneOff = oneOffInclude
131+
}
132+
containers, err = s.getContainers(ctx, projectName, withOneOff, true, serviceName)
134133
if err != nil {
135134
return nil, err
136135
}

0 commit comments

Comments
 (0)