@@ -38,7 +38,7 @@ type buildOptions struct {
3838 out string
3939}
4040
41- func BuildCmd (dockerCli command.Cli ) * cobra.Command {
41+ func Cmd (dockerCli command.Cli ) * cobra.Command {
4242 var opts buildOptions
4343 cmd := & cobra.Command {
4444 Use : "build [APPLICATION]" ,
@@ -124,8 +124,27 @@ func runBuild(dockerCli command.Cli, application string, opt buildOptions) (refe
124124 }
125125
126126 fmt .Println ("Successfully built service images" )
127- debugSolveResponses (resp )
127+ updateBundle (bundle , resp )
128+
129+ var ref reference.Named
130+ ref , err = packager .GetNamedTagged (opt .tag )
131+ if err != nil {
132+ return nil , err
133+ }
134+ if ref == nil {
135+ if ref , err = computeDigest (bundle ); err != nil {
136+ return nil , err
137+ }
138+ }
139+
140+ if err = persistBundle (opt , bundle , ref ); err != nil {
141+ return nil , err
142+ }
143+ return ref , nil
144+ }
128145
146+ func updateBundle (bundle * bundle.Bundle , resp map [string ]* client.SolveResponse ) {
147+ debugSolveResponses (resp )
129148 for service , r := range resp {
130149 digest := r .ExporterResponse ["containerimage.digest" ]
131150 if service == "invocation-image" {
@@ -137,39 +156,33 @@ func runBuild(dockerCli command.Cli, application string, opt buildOptions) (refe
137156 image .Digest = digest
138157 bundle .Images [service ] = image
139158 }
140- fmt .Fprintf (dockerCli .Out (), " - %s : %s\n " , service , digest )
141159 }
142160 debugBundle (bundle )
161+ }
143162
144- var ref reference.Named
145- ref , err = packager .GetNamedTagged (opt .tag )
146- if err != nil {
147- return nil , err
148- }
149- if ref == nil {
150- if ref , err = computeDigest (bundle ); err != nil {
151- return nil , err
152- }
153- }
154-
163+ func persistBundle (opt buildOptions , bndl * bundle.Bundle , ref reference.Named ) error {
155164 if opt .out != "" {
156- b , err := json .MarshalIndent (bundle , "" , " " )
165+ b , err := json .MarshalIndent (bndl , "" , " " )
157166 if err != nil {
158- return ref , err
167+ return err
159168 }
160169 if opt .out == "-" {
161170 _ , err = os .Stdout .Write (b )
171+ if err != nil {
172+ return err
173+ }
162174 } else {
163175 err = ioutil .WriteFile (opt .out , b , 0644 )
176+ if err != nil {
177+ return err
178+ }
179+ }
180+ } else {
181+ if err := packager .PersistInBundleStore (ref , bndl ); err != nil {
182+ return err
164183 }
165- return ref , err
166- }
167-
168- if err := packager .PersistInBundleStore (ref , bundle ); err != nil {
169- return ref , err
170184 }
171-
172- return ref , nil
185+ return nil
173186}
174187
175188func createInvocationImageBuildOptions (dockerCli command.Cli , app * types.App ) (build.Options , error ) {
0 commit comments