@@ -4,8 +4,11 @@ import (
4
4
"context"
5
5
"errors"
6
6
"fmt"
7
+ "sync"
7
8
"time"
8
9
10
+ "golang.org/x/sync/errgroup"
11
+
9
12
"github.com/containers/image/v5/copy"
10
13
dockerv5 "github.com/containers/image/v5/docker"
11
14
"github.com/containers/image/v5/signature"
@@ -80,16 +83,30 @@ func runCopyCommand() error {
80
83
81
84
log .Infof ("Finding images that need to be copied ..." )
82
85
86
+ errs , errCtx := errgroup .WithContext (ctx )
87
+ errs .SetLimit (20 )
88
+ var mu sync.Mutex
83
89
var sourcesToCopy []manifest.Source
84
90
for _ , source := range sources {
85
- exists , err := client .ImageExistsAtRemote (ctx , source .TargetImage ())
86
- if err != nil {
87
- return fmt .Errorf ("image exists at remote: %w" , err )
88
- }
91
+ source := source
92
+ errs .Go (func () error {
93
+ exists , err := client .ImageExistsAtRemote (errCtx , source .TargetImage ())
94
+ if err != nil {
95
+ return fmt .Errorf ("image exists at remote: %w" , err )
96
+ }
89
97
90
- if ! exists || viper .GetBool ("force" ) {
91
- sourcesToCopy = append (sourcesToCopy , source )
92
- }
98
+ if ! exists || viper .GetBool ("force" ) {
99
+ mu .Lock ()
100
+ sourcesToCopy = append (sourcesToCopy , source )
101
+ mu .Unlock ()
102
+ }
103
+
104
+ return nil
105
+ })
106
+ }
107
+
108
+ if err := errs .Wait (); err != nil {
109
+ return err
93
110
}
94
111
95
112
if len (sourcesToCopy ) == 0 {
@@ -135,12 +152,12 @@ func runCopyCommand() error {
135
152
log .Infof ("Copying image %s to %s" , source .Image (), source .TargetImage ())
136
153
destRef , err := imageTransport .ParseReference (fmt .Sprintf ("//%s" , source .TargetImage ()))
137
154
if err != nil {
138
- return fmt .Errorf ("Error parsing target image reference: %w" , err )
155
+ return fmt .Errorf ("unable to parse target image reference: %w" , err )
139
156
}
140
157
141
158
srcRef , err := imageTransport .ParseReference (fmt .Sprintf ("//%s" , source .Image ()))
142
159
if err != nil {
143
- return fmt .Errorf ("Error parsing source image reference: %w" , err )
160
+ return fmt .Errorf ("unable to parse source image reference: %w" , err )
144
161
}
145
162
146
163
if _ , err := copy .Image (ctx , policyContext , destRef , srcRef , & copyOptions ); err != nil {
0 commit comments