@@ -17,11 +17,9 @@ import (
1717 "github.com/docker/cli/cli/streams"
1818 "github.com/docker/cli/cli/trust"
1919 "github.com/docker/cli/internal/jsonstream"
20- "github.com/docker/cli/internal/registry"
2120 "github.com/docker/cli/internal/tui"
2221 "github.com/docker/docker/api/types/auxprogress"
2322 "github.com/docker/docker/api/types/image"
24- registrytypes "github.com/docker/docker/api/types/registry"
2523 "github.com/morikuni/aec"
2624 ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2725 "github.com/pkg/errors"
@@ -100,9 +98,11 @@ To push the complete multi-platform image, remove the --platform flag.
10098 }
10199
102100 ref , err := reference .ParseNormalizedNamed (opts .remote )
103- switch {
104- case err != nil :
101+ if err != nil {
105102 return err
103+ }
104+
105+ switch {
106106 case opts .all && ! reference .IsNameOnly (ref ):
107107 return errors .New ("tag can't be used with --all-tags/-a" )
108108 case ! opts .all && reference .IsNameOnly (ref ):
@@ -112,43 +112,37 @@ To push the complete multi-platform image, remove the --platform flag.
112112 }
113113 }
114114
115- // Resolve the Repository name from fqn to RepositoryInfo
116- indexInfo := registry .NewIndexInfo (ref )
117-
118115 // Resolve the Auth config relevant for this server
119- authConfig := command .ResolveAuthConfig (dockerCli .ConfigFile (), indexInfo )
120- encodedAuth , err := registrytypes .EncodeAuthConfig (authConfig )
116+ encodedAuth , err := command .RetrieveAuthTokenFromImage (dockerCli .ConfigFile (), ref .String ())
121117 if err != nil {
122118 return err
123119 }
124- options := image.PushOptions {
120+
121+ responseBody , err := dockerCli .Client ().ImagePush (ctx , reference .FamiliarString (ref ), image.PushOptions {
125122 All : opts .all ,
126123 RegistryAuth : encodedAuth ,
127124 PrivilegeFunc : nil ,
128125 Platform : platform ,
129- }
130-
131- responseBody , err := dockerCli .Client ().ImagePush (ctx , reference .FamiliarString (ref ), options )
126+ })
132127 if err != nil {
133128 return err
134129 }
135130
136131 defer func () {
132+ _ = responseBody .Close ()
137133 for _ , note := range notes {
138134 out .PrintNote (note )
139135 }
140136 }()
141137
142- defer responseBody .Close ()
143138 if ! opts .untrusted {
144- // TODO pushTrustedReference currently doesn't respect `--quiet`
145- return pushTrustedReference (ctx , dockerCli , indexInfo , ref , authConfig , responseBody )
139+ return pushTrustedReference (ctx , dockerCli , ref , responseBody )
146140 }
147141
148142 if opts .quiet {
149143 err = jsonstream .Display (ctx , responseBody , streams .NewOut (io .Discard ), jsonstream .WithAuxCallback (handleAux ()))
150144 if err == nil {
151- fmt .Fprintln (dockerCli .Out (), ref .String ())
145+ _ , _ = fmt .Fprintln (dockerCli .Out (), ref .String ())
152146 }
153147 return err
154148 }
0 commit comments