@@ -72,32 +72,46 @@ func pushCmd(dockerCli command.Cli) *cobra.Command {
7272
7373func runPush (dockerCli command.Cli , name string , opts pushOptions ) error {
7474 defer muteDockerCli (dockerCli )()
75-
76- bundleStore , err := prepareBundleStore ( )
75+ // Get the bundle
76+ bndl , ref , err := resolveReferenceAndBundle ( dockerCli , name )
7777 if err != nil {
7878 return err
7979 }
80-
81- bndl , _ , err := resolveBundle ( dockerCli , bundleStore , name , false , nil )
80+ // Retag invocation image if needed
81+ retag , err := shouldRetagInvocationImage ( metadata . FromBundle ( bndl ), bndl , opts . tag , ref )
8282 if err != nil {
8383 return err
8484 }
85- if err := bndl .Validate (); err != nil {
85+ if retag .shouldRetag {
86+ if err := retagInvocationImage (dockerCli , bndl , retag .invocationImageRef .String ()); err != nil {
87+ return err
88+ }
89+ }
90+ // Push the invocation image
91+ if err := pushInvocationImage (dockerCli , retag ); err != nil {
8692 return err
8793 }
94+ // Push the bundle
95+ return pushBundle (dockerCli , opts , bndl , retag )
96+ }
8897
89- retag , err := shouldRetagInvocationImage (metadata .FromBundle (bndl ), bndl , opts .tag )
98+ func resolveReferenceAndBundle (dockerCli command.Cli , name string ) (* bundle.Bundle , string , error ) {
99+ bundleStore , err := prepareBundleStore ()
90100 if err != nil {
91- return err
101+ return nil , "" , err
92102 }
93- if retag .shouldRetag {
94- err := retagInvocationImage (dockerCli , bndl , retag .invocationImageRef .String ())
95- if err != nil {
96- return err
97- }
103+
104+ bndl , ref , err := resolveBundle (dockerCli , bundleStore , name , false , nil )
105+ if err != nil {
106+ return nil , "" , err
107+ }
108+ if err := bndl .Validate (); err != nil {
109+ return nil , "" , err
98110 }
111+ return bndl , ref , err
112+ }
99113
100- // pushing invocation image
114+ func pushInvocationImage ( dockerCli command. Cli , retag retagResult ) error {
101115 repoInfo , err := registry .ParseRepositoryInfo (retag .invocationImageRef )
102116 if err != nil {
103117 return err
@@ -113,10 +127,13 @@ func runPush(dockerCli command.Cli, name string, opts pushOptions) error {
113127 return errors .Wrapf (err , "starting push of %q" , retag .invocationImageRef .String ())
114128 }
115129 defer reader .Close ()
116- if err = jsonmessage .DisplayJSONMessagesStream (reader , ioutil .Discard , 0 , false , nil ); err != nil {
130+ if err : = jsonmessage .DisplayJSONMessagesStream (reader , ioutil .Discard , 0 , false , nil ); err != nil {
117131 return errors .Wrapf (err , "pushing to %q" , retag .invocationImageRef .String ())
118132 }
133+ return nil
134+ }
119135
136+ func pushBundle (dockerCli command.Cli , opts pushOptions , bndl * bundle.Bundle , retag retagResult ) error {
120137 resolver := remotes .CreateResolver (dockerCli .ConfigFile (), opts .registry .insecureRegistries ... )
121138 var display fixupDisplay = & plainDisplay {out : os .Stdout }
122139 if term .IsTerminal (os .Stdout .Fd ()) {
@@ -129,9 +146,7 @@ func runPush(dockerCli command.Cli, name string, opts pushOptions) error {
129146 fixupOptions = append (fixupOptions , remotes .WithComponentImagePlatforms (platforms ))
130147 }
131148 // bundle fixup
132- err = remotes .FixupBundle (context .Background (), bndl , retag .cnabRef , resolver , fixupOptions ... )
133-
134- if err != nil {
149+ if err := remotes .FixupBundle (context .Background (), bndl , retag .cnabRef , resolver , fixupOptions ... ); err != nil {
135150 return errors .Wrapf (err , "fixing up %q for push" , retag .cnabRef )
136151 }
137152 // push bundle manifest
@@ -181,7 +196,11 @@ type retagResult struct {
181196 invocationImageRef reference.Named
182197}
183198
184- func shouldRetagInvocationImage (meta metadata.AppMetadata , bndl * bundle.Bundle , tagOverride string ) (retagResult , error ) {
199+ func shouldRetagInvocationImage (meta metadata.AppMetadata , bndl * bundle.Bundle , tagOverride , bundleRef string ) (retagResult , error ) {
200+ // Use the bundle reference as a tag override
201+ if tagOverride == "" && bundleRef != "" {
202+ tagOverride = bundleRef
203+ }
185204 imgName := tagOverride
186205 var err error
187206 if imgName == "" {
0 commit comments