@@ -56,17 +56,25 @@ func (a *ImageCopy) Run(cmd *cobra.Command, args []string) error {
56
56
return err
57
57
}
58
58
59
+ if ! a .AllTags {
60
+ // Check if the source argument matches the name of a local image, and use it if it does.
61
+ // If there is an error, ignore it and move on, treating the argument as a remote image name.
62
+ if _ , err := c .ImageGet (cmd .Context (), args [0 ]); err == nil {
63
+ return a .copyLocalToRemote (cmd , c , args , creds )
64
+ }
65
+ }
66
+
59
67
source , err := name .ParseReference (args [0 ])
60
68
if err != nil {
61
69
return err
62
70
}
63
71
64
- dest , err := name . ParseReference ( args [ 1 ] )
72
+ sourceAuth , _ , err := creds . Get ( cmd . Context (), source . Context (). RegistryStr () )
65
73
if err != nil {
66
74
return err
67
75
}
68
76
69
- sourceAuth , _ , err := creds . Get ( cmd . Context (), source . Context (). RegistryStr () )
77
+ dest , err := name . ParseReference ( args [ 1 ] )
70
78
if err != nil {
71
79
return err
72
80
}
@@ -88,3 +96,25 @@ func (a *ImageCopy) Run(cmd *cobra.Command, args []string) error {
88
96
89
97
return progressbar .Print (progress )
90
98
}
99
+
100
+ func (a * ImageCopy ) copyLocalToRemote (cmd * cobra.Command , c client.Client , args []string , creds * credentials.Store ) error {
101
+ dest , err := name .ParseReference (args [1 ])
102
+ if err != nil {
103
+ return err
104
+ }
105
+
106
+ destAuth , _ , err := creds .Get (cmd .Context (), dest .Context ().RegistryStr ())
107
+ if err != nil {
108
+ return err
109
+ }
110
+
111
+ progress , err := c .ImageCopy (cmd .Context (), args [0 ], args [1 ], & client.ImageCopyOptions {
112
+ Force : a .Force ,
113
+ DestAuth : destAuth ,
114
+ })
115
+ if err != nil {
116
+ return err
117
+ }
118
+
119
+ return progressbar .Print (progress )
120
+ }
0 commit comments