@@ -72,36 +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 , ref , 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
- // Use the bundle reference as a tag
86
- if ref != "" && opts .tag == "" {
87
- opts .tag = ref
85
+ if retag .shouldRetag {
86
+ if err := retagInvocationImage (dockerCli , bndl , retag .invocationImageRef .String ()); err != nil {
87
+ return err
88
+ }
88
89
}
89
- if err := bndl .Validate (); err != nil {
90
+ // Push the invocation image
91
+ if err := pushInvocationImage (dockerCli , retag ); err != nil {
90
92
return err
91
93
}
94
+ // Push the bundle
95
+ return pushBundle (dockerCli , opts , bndl , retag )
96
+ }
92
97
93
- 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 ()
94
100
if err != nil {
95
- return err
101
+ return nil , "" , err
96
102
}
97
- if retag .shouldRetag {
98
- err := retagInvocationImage (dockerCli , bndl , retag .invocationImageRef .String ())
99
- if err != nil {
100
- return err
101
- }
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
102
110
}
111
+ return bndl , ref , err
112
+ }
103
113
104
- // pushing invocation image
114
+ func pushInvocationImage ( dockerCli command. Cli , retag retagResult ) error {
105
115
repoInfo , err := registry .ParseRepositoryInfo (retag .invocationImageRef )
106
116
if err != nil {
107
117
return err
@@ -117,10 +127,13 @@ func runPush(dockerCli command.Cli, name string, opts pushOptions) error {
117
127
return errors .Wrapf (err , "starting push of %q" , retag .invocationImageRef .String ())
118
128
}
119
129
defer reader .Close ()
120
- 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 {
121
131
return errors .Wrapf (err , "pushing to %q" , retag .invocationImageRef .String ())
122
132
}
133
+ return nil
134
+ }
123
135
136
+ func pushBundle (dockerCli command.Cli , opts pushOptions , bndl * bundle.Bundle , retag retagResult ) error {
124
137
resolver := remotes .CreateResolver (dockerCli .ConfigFile (), opts .registry .insecureRegistries ... )
125
138
var display fixupDisplay = & plainDisplay {out : os .Stdout }
126
139
if term .IsTerminal (os .Stdout .Fd ()) {
@@ -133,9 +146,7 @@ func runPush(dockerCli command.Cli, name string, opts pushOptions) error {
133
146
fixupOptions = append (fixupOptions , remotes .WithComponentImagePlatforms (platforms ))
134
147
}
135
148
// bundle fixup
136
- err = remotes .FixupBundle (context .Background (), bndl , retag .cnabRef , resolver , fixupOptions ... )
137
-
138
- if err != nil {
149
+ if err := remotes .FixupBundle (context .Background (), bndl , retag .cnabRef , resolver , fixupOptions ... ); err != nil {
139
150
return errors .Wrapf (err , "fixing up %q for push" , retag .cnabRef )
140
151
}
141
152
// push bundle manifest
@@ -185,7 +196,11 @@ type retagResult struct {
185
196
invocationImageRef reference.Named
186
197
}
187
198
188
- 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
+ }
189
204
imgName := tagOverride
190
205
var err error
191
206
if imgName == "" {
0 commit comments