1
1
package image
2
2
3
3
import (
4
- "bytes"
5
4
"fmt"
6
5
"io"
7
6
"os"
8
7
9
- "github.com/docker/app/internal/packager"
10
-
11
- "github.com/deislabs/cnab-go/driver"
12
-
13
8
"github.com/deislabs/cnab-go/action"
9
+ "github.com/deislabs/cnab-go/driver"
14
10
"github.com/docker/app/internal"
15
11
bdl "github.com/docker/app/internal/bundle"
16
12
"github.com/docker/app/internal/cliopts"
17
13
"github.com/docker/app/internal/cnab"
14
+ "github.com/docker/app/internal/packager"
18
15
appstore "github.com/docker/app/internal/store"
19
16
"github.com/docker/cli/cli"
20
17
"github.com/docker/cli/cli/command"
@@ -49,8 +46,6 @@ func renderCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContext
49
46
}
50
47
51
48
func runRender (dockerCli command.Cli , appname string , opts renderOptions , installerContext * cliopts.InstallerContextOptions ) error {
52
- defer muteDockerCli (dockerCli )()
53
-
54
49
var w io.Writer = os .Stdout
55
50
if opts .renderOutput != "-" {
56
51
f , err := os .Create (opts .renderOutput )
@@ -61,64 +56,51 @@ func runRender(dockerCli command.Cli, appname string, opts renderOptions, instal
61
56
w = f
62
57
}
63
58
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
-
88
59
s , err := appstore .NewApplicationStore (config .Dir ())
89
60
if err != nil {
90
- return nil , nil , nil , err
61
+ return err
91
62
}
92
63
bundleStore , err := s .BundleStore ()
93
64
if err != nil {
94
- return nil , nil , nil , err
65
+ return err
95
66
}
96
67
bndl , ref , err := cnab .GetBundle (dockerCli , bundleStore , appname )
97
68
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 )
99
70
}
100
71
if err := packager .CheckAppVersion (dockerCli .Err (), bndl .Bundle ); err != nil {
101
- return nil , nil , nil , err
72
+ return err
102
73
}
103
74
installation , err := appstore .NewInstallation ("custom-action" , ref .String (), bndl )
104
75
if err != nil {
105
- return nil , nil , nil , err
76
+ return err
106
77
}
107
78
108
79
if err := bdl .MergeBundleParameters (installation ,
109
80
bdl .WithFileParameters (opts .ParametersFiles ),
110
81
bdl .WithCommandLineParameters (opts .Overrides ),
111
82
); err != nil {
112
- return nil , nil , nil , err
83
+ return err
113
84
}
114
85
115
- driverImpl , errBuf , err := cnab .SetupDriver (installation , dockerCli , installerContext , stdout )
86
+ defer muteDockerCli (dockerCli )()
87
+ driverImpl , errBuf , err := cnab .SetupDriver (installation , dockerCli , installerContext , w )
116
88
if err != nil {
117
- return nil , nil , nil , err
89
+ return err
118
90
}
119
- a := & action.RunCustom {
120
- Action : actionName ,
91
+ action := & action.RunCustom {
92
+ Action : internal . ActionRenderName ,
121
93
Driver : driverImpl ,
122
94
}
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
124
106
}
0 commit comments