11package image
22
33import (
4- "bytes"
54 "fmt"
65 "io"
76 "os"
87
9- "github.com/deislabs/cnab-go/driver"
10-
118 "github.com/deislabs/cnab-go/action"
9+ "github.com/deislabs/cnab-go/driver"
1210 "github.com/docker/app/internal"
1311 bdl "github.com/docker/app/internal/bundle"
1412 "github.com/docker/app/internal/cliopts"
1513 "github.com/docker/app/internal/cnab"
14+ "github.com/docker/app/internal/packager"
1615 appstore "github.com/docker/app/internal/store"
1716 "github.com/docker/cli/cli"
1817 "github.com/docker/cli/cli/command"
@@ -47,8 +46,6 @@ func renderCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContext
4746}
4847
4948func runRender (dockerCli command.Cli , appname string , opts renderOptions , installerContext * cliopts.InstallerContextOptions ) error {
50- defer muteDockerCli (dockerCli )()
51-
5249 var w io.Writer = os .Stdout
5350 if opts .renderOutput != "-" {
5451 f , err := os .Create (opts .renderOutput )
@@ -59,61 +56,51 @@ func runRender(dockerCli command.Cli, appname string, opts renderOptions, instal
5956 w = f
6057 }
6158
62- cfgFunc := func (op * driver.Operation ) error {
63- op .Out = w
64- return nil
65- }
66-
67- action , installation , errBuf , err := prepareCustomAction (internal .ActionRenderName , dockerCli , appname , w , opts , installerContext )
68- if err != nil {
69- return err
70- }
71- installation .Parameters [internal .ParameterRenderFormatName ] = opts .formatDriver
72-
73- if err := action .Run (& installation .Claim , nil , cfgFunc , cnab .WithRelocationMap (installation )); err != nil {
74- return fmt .Errorf ("render failed: %s\n %s" , err , errBuf )
75- }
76- return nil
77- }
78-
79- func prepareCustomAction (actionName string ,
80- dockerCli command.Cli ,
81- appname string ,
82- stdout io.Writer ,
83- opts renderOptions ,
84- installerContext * cliopts.InstallerContextOptions ) (* action.RunCustom , * appstore.Installation , * bytes.Buffer , error ) {
85-
8659 s , err := appstore .NewApplicationStore (config .Dir ())
8760 if err != nil {
88- return nil , nil , nil , err
61+ return err
8962 }
9063 bundleStore , err := s .BundleStore ()
9164 if err != nil {
92- return nil , nil , nil , err
65+ return err
9366 }
94- bundle , ref , err := cnab .GetBundle (dockerCli , bundleStore , appname )
67+ bndl , ref , err := cnab .GetBundle (dockerCli , bundleStore , appname )
9568 if err != nil {
96- return nil , nil , nil , errors .Wrapf (err , "could not render %q: no such App image" , appname )
69+ return errors .Wrapf (err , "could not render %q: no such App image" , appname )
70+ }
71+ if err := packager .CheckAppVersion (dockerCli .Err (), bndl .Bundle ); err != nil {
72+ return err
9773 }
98- installation , err := appstore .NewInstallation ("custom-action" , ref .String (), bundle )
74+ installation , err := appstore .NewInstallation ("custom-action" , ref .String (), bndl )
9975 if err != nil {
100- return nil , nil , nil , err
76+ return err
10177 }
10278
10379 if err := bdl .MergeBundleParameters (installation ,
10480 bdl .WithFileParameters (opts .ParametersFiles ),
10581 bdl .WithCommandLineParameters (opts .Overrides ),
10682 ); err != nil {
107- return nil , nil , nil , err
83+ return err
10884 }
10985
110- driverImpl , errBuf , err := cnab .SetupDriver (installation , dockerCli , installerContext , stdout )
86+ defer muteDockerCli (dockerCli )()
87+ driverImpl , errBuf , err := cnab .SetupDriver (installation , dockerCli , installerContext , w )
11188 if err != nil {
112- return nil , nil , nil , err
89+ return err
11390 }
114- a := & action.RunCustom {
115- Action : actionName ,
91+ action := & action.RunCustom {
92+ Action : internal . ActionRenderName ,
11693 Driver : driverImpl ,
11794 }
118- return a , installation , errBuf , nil
95+ installation .Parameters [internal .ParameterRenderFormatName ] = opts .formatDriver
96+
97+ cfgFunc := func (op * driver.Operation ) error {
98+ op .Out = w
99+ return nil
100+ }
101+
102+ if err := action .Run (& installation .Claim , nil , cfgFunc , cnab .WithRelocationMap (installation )); err != nil {
103+ return fmt .Errorf ("render failed: %s\n %s" , err , errBuf )
104+ }
105+ return nil
119106}
0 commit comments