|
|
@@ -47,6 +47,7 @@ type LowLevelClient interface {
|
|
|
ContainersForService(ctx context.Context, projectName string, serviceName string) ([]moby.Container, error)
|
|
|
|
|
|
Exec(ctx context.Context, containerID string, cmd []string, in io.Reader) error
|
|
|
+ Untar(ctx context.Context, id string, reader io.ReadCloser) error
|
|
|
}
|
|
|
|
|
|
type Tar struct {
|
|
|
@@ -84,39 +85,24 @@ func (t *Tar) Sync(ctx context.Context, service types.ServiceConfig, paths []Pat
|
|
|
if len(pathsToDelete) != 0 {
|
|
|
deleteCmd = append([]string{"rm", "-rf"}, pathsToDelete...)
|
|
|
}
|
|
|
- copyCmd := []string{"tar", "-v", "-C", "/", "-x", "-f", "-"}
|
|
|
-
|
|
|
var eg multierror.Group
|
|
|
- writers := make([]*io.PipeWriter, len(containers))
|
|
|
for i := range containers {
|
|
|
containerID := containers[i].ID
|
|
|
- r, w := io.Pipe()
|
|
|
- writers[i] = w
|
|
|
+ tarReader := tarArchive(pathsToCopy)
|
|
|
+
|
|
|
eg.Go(func() error {
|
|
|
if len(deleteCmd) != 0 {
|
|
|
if err := t.client.Exec(ctx, containerID, deleteCmd, nil); err != nil {
|
|
|
return fmt.Errorf("deleting paths in %s: %w", containerID, err)
|
|
|
}
|
|
|
}
|
|
|
- if err := t.client.Exec(ctx, containerID, copyCmd, r); err != nil {
|
|
|
+
|
|
|
+ if err := t.client.Untar(ctx, containerID, tarReader); err != nil {
|
|
|
return fmt.Errorf("copying files to %s: %w", containerID, err)
|
|
|
}
|
|
|
return nil
|
|
|
})
|
|
|
}
|
|
|
-
|
|
|
- multiWriter := newLossyMultiWriter(writers...)
|
|
|
- tarReader := tarArchive(pathsToCopy)
|
|
|
- defer func() {
|
|
|
- _ = tarReader.Close()
|
|
|
- multiWriter.Close()
|
|
|
- }()
|
|
|
- _, err = io.Copy(multiWriter, tarReader)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- multiWriter.Close()
|
|
|
-
|
|
|
return eg.Wait().ErrorOrNil()
|
|
|
}
|
|
|
|