mirror of
https://github.com/docker/compose.git
synced 2025-07-27 07:34:10 +02:00
use progress to show copy status
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
bef9c48a1a
commit
9e19bc8441
@ -24,6 +24,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/docker/compose/v2/pkg/progress"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
|
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
@ -43,6 +44,12 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (s *composeService) Copy(ctx context.Context, projectName string, options api.CopyOptions) error {
|
func (s *composeService) Copy(ctx context.Context, projectName string, options api.CopyOptions) error {
|
||||||
|
return progress.Run(ctx, func(ctx context.Context) error {
|
||||||
|
return s.copy(ctx, projectName, options)
|
||||||
|
}, s.stderr())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *composeService) copy(ctx context.Context, projectName string, options api.CopyOptions) error {
|
||||||
projectName = strings.ToLower(projectName)
|
projectName = strings.ToLower(projectName)
|
||||||
srcService, srcPath := splitCpArg(options.Source)
|
srcService, srcPath := splitCpArg(options.Source)
|
||||||
destService, dstPath := splitCpArg(options.Destination)
|
destService, dstPath := splitCpArg(options.Destination)
|
||||||
@ -78,18 +85,33 @@ func (s *composeService) Copy(ctx context.Context, projectName string, options a
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
w := progress.ContextWriter(ctx)
|
||||||
g := errgroup.Group{}
|
g := errgroup.Group{}
|
||||||
for _, cont := range containers {
|
for _, cont := range containers {
|
||||||
container := cont
|
container := cont
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
|
name := getCanonicalContainerName(container)
|
||||||
|
var msg string
|
||||||
|
if direction == fromService {
|
||||||
|
msg = fmt.Sprintf("copy %s:%s to %s", name, srcPath, dstPath)
|
||||||
|
} else {
|
||||||
|
msg = fmt.Sprintf("copy %s to %s:%s", srcPath, name, dstPath)
|
||||||
|
}
|
||||||
|
w.Event(progress.Event{
|
||||||
|
ID: name,
|
||||||
|
Text: msg,
|
||||||
|
Status: progress.Working,
|
||||||
|
StatusText: "Copying",
|
||||||
|
})
|
||||||
if err := copyFunc(ctx, container.ID, srcPath, dstPath, options); err != nil {
|
if err := copyFunc(ctx, container.ID, srcPath, dstPath, options); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fromOrInside := "inside"
|
w.Event(progress.Event{
|
||||||
if direction == fromService {
|
ID: name,
|
||||||
fromOrInside = "from"
|
Text: msg,
|
||||||
}
|
Status: progress.Done,
|
||||||
fmt.Fprintf(s.stderr(), "Copy %s to path %s %s %s service container\n", srcPath, dstPath, fromOrInside, getCanonicalContainerName(container))
|
StatusText: "Copied",
|
||||||
|
})
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user