@@ -81,7 +81,7 @@ func imagePushToRegistry(config imagePushToRegistryOptions, telemetryData *telem
81
81
}
82
82
83
83
func runImagePushToRegistry (config * imagePushToRegistryOptions , telemetryData * telemetry.CustomData , utils imagePushToRegistryUtils ) error {
84
- if ! config .PushLocalDockerImage {
84
+ if ! config .PushLocalDockerImage && ! config . UseImageNameTags {
85
85
if len (config .TargetImages ) == 0 {
86
86
config .TargetImages = mapSourceTargetImages (config .SourceImages )
87
87
}
@@ -91,6 +91,13 @@ func runImagePushToRegistry(config *imagePushToRegistryOptions, telemetryData *t
91
91
}
92
92
}
93
93
94
+ if config .UseImageNameTags {
95
+ if len (config .TargetImageNameTags ) > 0 && len (config .TargetImageNameTags ) != len (config .SourceImageNameTags ) {
96
+ log .SetErrorCategory (log .ErrorConfiguration )
97
+ return errors .New ("configuration error: please configure targetImageNameTags and sourceImageNameTags properly" )
98
+ }
99
+ }
100
+
94
101
// Docker image tags don't allow plus signs in tags, thus replacing with dash
95
102
config .SourceImageTag = strings .ReplaceAll (config .SourceImageTag , "+" , "-" )
96
103
config .TargetImageTag = strings .ReplaceAll (config .TargetImageTag , "+" , "-" )
@@ -115,6 +122,13 @@ func runImagePushToRegistry(config *imagePushToRegistryOptions, telemetryData *t
115
122
return errors .Wrap (err , "failed to handle credentials for source registry" )
116
123
}
117
124
125
+ if config .UseImageNameTags {
126
+ if err := pushImageNameTagsToTargetRegistry (config , utils ); err != nil {
127
+ return errors .Wrapf (err , "failed to push imageNameTags to target registry" )
128
+ }
129
+ return nil
130
+ }
131
+
118
132
if err := copyImages (config , utils ); err != nil {
119
133
return errors .Wrap (err , "failed to copy images" )
120
134
}
@@ -242,6 +256,37 @@ func pushLocalImageToTargetRegistry(config *imagePushToRegistryOptions, utils im
242
256
return nil
243
257
}
244
258
259
+ func pushImageNameTagsToTargetRegistry (config * imagePushToRegistryOptions , utils imagePushToRegistryUtils ) error {
260
+ g , ctx := errgroup .WithContext (context .Background ())
261
+ g .SetLimit (10 )
262
+
263
+ for i , sourceImageNameTag := range config .SourceImageNameTags {
264
+ src := fmt .Sprintf ("%s/%s" , config .SourceRegistryURL , sourceImageNameTag )
265
+
266
+ dst := ""
267
+ if len (config .TargetImageNameTags ) == 0 {
268
+ dst = fmt .Sprintf ("%s/%s" , config .TargetRegistryURL , sourceImageNameTag )
269
+ } else {
270
+ dst = fmt .Sprintf ("%s/%s" , config .TargetRegistryURL , config .TargetImageNameTags [i ])
271
+ }
272
+
273
+ g .Go (func () error {
274
+ log .Entry ().Infof ("Copying %s to %s..." , src , dst )
275
+ if err := utils .CopyImage (ctx , src , dst , "" ); err != nil {
276
+ return err
277
+ }
278
+ log .Entry ().Infof ("Copying %s to %s... Done" , src , dst )
279
+ return nil
280
+ })
281
+ }
282
+
283
+ if err := g .Wait (); err != nil {
284
+ return err
285
+ }
286
+
287
+ return nil
288
+ }
289
+
245
290
func mapSourceTargetImages (sourceImages []string ) map [string ]any {
246
291
targetImages := make (map [string ]any , len (sourceImages ))
247
292
for _ , sourceImage := range sourceImages {
0 commit comments