11package image
22
33import (
4- "bytes"
54 "fmt"
65 "io"
76 "os"
87
9- "github.com/docker/app/internal/packager"
10-
11- "github.com/deislabs/cnab-go/driver"
12-
138 "github.com/deislabs/cnab-go/action"
9+ "github.com/deislabs/cnab-go/driver"
1410 "github.com/docker/app/internal"
1511 bdl "github.com/docker/app/internal/bundle"
1612 "github.com/docker/app/internal/cliopts"
1713 "github.com/docker/app/internal/cnab"
14+ "github.com/docker/app/internal/packager"
1815 appstore "github.com/docker/app/internal/store"
1916 "github.com/docker/cli/cli"
2017 "github.com/docker/cli/cli/command"
@@ -49,8 +46,6 @@ func renderCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContext
4946}
5047
5148func runRender (dockerCli command.Cli , appname string , opts renderOptions , installerContext * cliopts.InstallerContextOptions ) error {
52- defer muteDockerCli (dockerCli )()
53-
5449 var w io.Writer = os .Stdout
5550 if opts .renderOutput != "-" {
5651 f , err := os .Create (opts .renderOutput )
@@ -61,64 +56,51 @@ func runRender(dockerCli command.Cli, appname string, opts renderOptions, instal
6156 w = f
6257 }
6358
64- cfgFunc := func (op * driver.Operation ) error {
65- op .Out = w
66- return nil
67- }
68-
69- action , installation , errBuf , err := prepareCustomAction (internal .ActionRenderName , dockerCli , appname , w , opts , installerContext )
70- if err != nil {
71- return err
72- }
73- installation .Parameters [internal .ParameterRenderFormatName ] = opts .formatDriver
74-
75- if err := action .Run (& installation .Claim , nil , cfgFunc , cnab .WithRelocationMap (installation )); err != nil {
76- return fmt .Errorf ("render failed: %s\n %s" , err , errBuf )
77- }
78- return nil
79- }
80-
81- func prepareCustomAction (actionName string ,
82- dockerCli command.Cli ,
83- appname string ,
84- stdout io.Writer ,
85- opts renderOptions ,
86- installerContext * cliopts.InstallerContextOptions ) (* action.RunCustom , * appstore.Installation , * bytes.Buffer , error ) {
87-
8859 s , err := appstore .NewApplicationStore (config .Dir ())
8960 if err != nil {
90- return nil , nil , nil , err
61+ return err
9162 }
9263 bundleStore , err := s .BundleStore ()
9364 if err != nil {
94- return nil , nil , nil , err
65+ return err
9566 }
9667 bndl , ref , err := cnab .GetBundle (dockerCli , bundleStore , appname )
9768 if err != nil {
98- 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 )
9970 }
10071 if err := packager .CheckAppVersion (dockerCli .Err (), bndl .Bundle ); err != nil {
101- return nil , nil , nil , err
72+ return err
10273 }
10374 installation , err := appstore .NewInstallation ("custom-action" , ref .String (), bndl )
10475 if err != nil {
105- return nil , nil , nil , err
76+ return err
10677 }
10778
10879 if err := bdl .MergeBundleParameters (installation ,
10980 bdl .WithFileParameters (opts .ParametersFiles ),
11081 bdl .WithCommandLineParameters (opts .Overrides ),
11182 ); err != nil {
112- return nil , nil , nil , err
83+ return err
11384 }
11485
115- driverImpl , errBuf , err := cnab .SetupDriver (installation , dockerCli , installerContext , stdout )
86+ defer muteDockerCli (dockerCli )()
87+ driverImpl , errBuf , err := cnab .SetupDriver (installation , dockerCli , installerContext , w )
11688 if err != nil {
117- return nil , nil , nil , err
89+ return err
11890 }
119- a := & action.RunCustom {
120- Action : actionName ,
91+ action := & action.RunCustom {
92+ Action : internal . ActionRenderName ,
12193 Driver : driverImpl ,
12294 }
123- 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
124106}
0 commit comments