@@ -201,16 +201,17 @@ func getAppNameKind(name string) (string, nameKind) {
201201 return name , nameKindFile
202202}
203203
204- func extractAndLoadAppBasedBundle (dockerCli command.Cli , name string ) (* bundle.Bundle , error ) {
204+ func extractAndLoadAppBasedBundle (dockerCli command.Cli , name string ) (* bundle.Bundle , string , error ) {
205205 app , err := packager .Extract (name )
206206 if err != nil {
207- return nil , err
207+ return nil , "" , err
208208 }
209209 defer app .Cleanup ()
210- return makeBundleFromApp (dockerCli , app )
210+ bndl , err := makeBundleFromApp (dockerCli , app )
211+ return bndl , "" , err
211212}
212213
213- func resolveBundle (dockerCli command.Cli , bundleStore appstore.BundleStore , name string , pullRef bool , insecureRegistries []string ) (* bundle.Bundle , error ) {
214+ func resolveBundle (dockerCli command.Cli , bundleStore appstore.BundleStore , name string , pullRef bool , insecureRegistries []string ) (* bundle.Bundle , string , error ) {
214215 // resolution logic:
215216 // - if there is a docker-app package in working directory, or an http:// / https:// prefix, use packager.Extract result
216217 // - the name has a .json or .cnab extension and refers to an existing file or web resource: load the bundle
@@ -220,28 +221,31 @@ func resolveBundle(dockerCli command.Cli, bundleStore appstore.BundleStore, name
220221 switch kind {
221222 case nameKindFile :
222223 if pullRef {
223- return nil , errors .Errorf ("%s: cannot pull when referencing a file based app" , name )
224+ return nil , "" , errors .Errorf ("%s: cannot pull when referencing a file based app" , name )
224225 }
225226 if strings .HasSuffix (name , internal .AppExtension ) {
226227 return extractAndLoadAppBasedBundle (dockerCli , name )
227228 }
228- return loader .NewLoader ().Load (name )
229+ bndl , err := loader .NewLoader ().Load (name )
230+ return bndl , "" , err
229231 case nameKindDir , nameKindEmpty :
230232 if pullRef {
231233 if kind == nameKindDir {
232- return nil , errors .Errorf ("%s: cannot pull when referencing a directory based app" , name )
234+ return nil , "" , errors .Errorf ("%s: cannot pull when referencing a directory based app" , name )
233235 }
234- return nil , errors .Errorf ("cannot pull when referencing a directory based app" )
236+ return nil , "" , errors .Errorf ("cannot pull when referencing a directory based app" )
235237 }
236238 return extractAndLoadAppBasedBundle (dockerCli , name )
237239 case nameKindReference :
238240 ref , err := reference .ParseNormalizedNamed (name )
239241 if err != nil {
240- return nil , errors .Wrap (err , name )
242+ return nil , "" , errors .Wrap (err , name )
241243 }
242- return bundleStore .LookupOrPullBundle (reference .TagNameOnly (ref ), pullRef , dockerCli .ConfigFile (), insecureRegistries )
244+ tagRef := reference .TagNameOnly (ref )
245+ bndl , err := bundleStore .LookupOrPullBundle (tagRef , pullRef , dockerCli .ConfigFile (), insecureRegistries )
246+ return bndl , tagRef .String (), err
243247 }
244- return nil , fmt .Errorf ("could not resolve bundle %q" , name )
248+ return nil , "" , fmt .Errorf ("could not resolve bundle %q" , name )
245249}
246250
247251func requiredClaimBindMount (c claim.Claim , targetContextName string , dockerCli command.Cli ) (bindMount , error ) {
@@ -298,7 +302,7 @@ func isDockerHostLocal(host string) bool {
298302}
299303
300304func prepareCustomAction (actionName string , dockerCli command.Cli , appname string , stdout io.Writer ,
301- registryOpts registryOptions , pullOpts pullOptions , paramsOpts parametersOptions ) (* action.RunCustom , * claim. Claim , * bytes.Buffer , error ) {
305+ registryOpts registryOptions , pullOpts pullOptions , paramsOpts parametersOptions ) (* action.RunCustom , * appstore. Installation , * bytes.Buffer , error ) {
302306 s , err := appstore .NewApplicationStore (config .Dir ())
303307 if err != nil {
304308 return nil , nil , nil , err
@@ -307,22 +311,21 @@ func prepareCustomAction(actionName string, dockerCli command.Cli, appname strin
307311 if err != nil {
308312 return nil , nil , nil , err
309313 }
310-
311- c , err := claim .New ("custom-action" )
314+ driverImpl , errBuf , err := prepareDriver (dockerCli , bindMount {}, stdout )
312315 if err != nil {
313316 return nil , nil , nil , err
314317 }
315- driverImpl , errBuf , err := prepareDriver (dockerCli , bindMount {}, stdout )
318+ bundle , ref , err := resolveBundle (dockerCli , bundleStore , appname , pullOpts . pull , registryOpts . insecureRegistries )
316319 if err != nil {
317320 return nil , nil , nil , err
318321 }
319- bundle , err := resolveBundle ( dockerCli , bundleStore , appname , pullOpts . pull , registryOpts . insecureRegistries )
322+ installation , err := appstore . NewInstallation ( "custom-action" , ref )
320323 if err != nil {
321324 return nil , nil , nil , err
322325 }
323- c .Bundle = bundle
326+ installation .Bundle = bundle
324327
325- if err := mergeBundleParameters (c ,
328+ if err := mergeBundleParameters (installation ,
326329 withFileParameters (paramsOpts .parametersFiles ),
327330 withCommandLineParameters (paramsOpts .overrides ),
328331 ); err != nil {
@@ -333,10 +336,10 @@ func prepareCustomAction(actionName string, dockerCli command.Cli, appname strin
333336 Action : actionName ,
334337 Driver : driverImpl ,
335338 }
336- return a , c , errBuf , nil
339+ return a , installation , errBuf , nil
337340}
338341
339- func isInstallationFailed (installation * claim. Claim ) bool {
342+ func isInstallationFailed (installation * appstore. Installation ) bool {
340343 return installation .Result .Action == claim .ActionInstall &&
341344 installation .Result .Status == claim .StatusFailure
342345}
0 commit comments