@@ -72,32 +72,46 @@ func pushCmd(dockerCli command.Cli) *cobra.Command {
72
72
73
73
func runPush (dockerCli command.Cli , name string , opts pushOptions ) error {
74
74
defer muteDockerCli (dockerCli )()
75
-
76
- bundleStore , err := prepareBundleStore ( )
75
+ // Get the bundle
76
+ bndl , ref , err := resolveReferenceAndBundle ( dockerCli , name )
77
77
if err != nil {
78
78
return err
79
79
}
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 )
82
82
if err != nil {
83
83
return err
84
84
}
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 {
86
92
return err
87
93
}
94
+ // Push the bundle
95
+ return pushBundle (dockerCli , opts , bndl , retag )
96
+ }
88
97
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 ()
90
100
if err != nil {
91
- return err
101
+ return nil , "" , err
92
102
}
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
98
110
}
111
+ return bndl , ref , err
112
+ }
99
113
100
- // pushing invocation image
114
+ func pushInvocationImage ( dockerCli command. Cli , retag retagResult ) error {
101
115
repoInfo , err := registry .ParseRepositoryInfo (retag .invocationImageRef )
102
116
if err != nil {
103
117
return err
@@ -113,10 +127,13 @@ func runPush(dockerCli command.Cli, name string, opts pushOptions) error {
113
127
return errors .Wrapf (err , "starting push of %q" , retag .invocationImageRef .String ())
114
128
}
115
129
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 {
117
131
return errors .Wrapf (err , "pushing to %q" , retag .invocationImageRef .String ())
118
132
}
133
+ return nil
134
+ }
119
135
136
+ func pushBundle (dockerCli command.Cli , opts pushOptions , bndl * bundle.Bundle , retag retagResult ) error {
120
137
resolver := remotes .CreateResolver (dockerCli .ConfigFile (), opts .registry .insecureRegistries ... )
121
138
var display fixupDisplay = & plainDisplay {out : os .Stdout }
122
139
if term .IsTerminal (os .Stdout .Fd ()) {
@@ -129,9 +146,7 @@ func runPush(dockerCli command.Cli, name string, opts pushOptions) error {
129
146
fixupOptions = append (fixupOptions , remotes .WithComponentImagePlatforms (platforms ))
130
147
}
131
148
// 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 {
135
150
return errors .Wrapf (err , "fixing up %q for push" , retag .cnabRef )
136
151
}
137
152
// push bundle manifest
@@ -181,7 +196,11 @@ type retagResult struct {
181
196
invocationImageRef reference.Named
182
197
}
183
198
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
+ }
185
204
imgName := tagOverride
186
205
var err error
187
206
if imgName == "" {
0 commit comments