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