11package commands
22
33import (
4+ "bytes"
45 "fmt"
6+ "io"
57 "io/ioutil"
68 "os"
79 "path/filepath"
@@ -90,13 +92,18 @@ func duffleHome() home.Home {
9092}
9193
9294// prepareDriver prepares a driver per the user's request.
93- func prepareDriver (dockerCli command.Cli , bindMount bindMount ) (driver.Driver , error ) {
95+ func prepareDriver (dockerCli command.Cli , bindMount bindMount , stdout io. Writer ) (driver.Driver , * bytes. Buffer , error ) {
9496 driverImpl , err := driver .Lookup ("docker" )
9597 if err != nil {
96- return driverImpl , err
98+ return driverImpl , nil , err
9799 }
100+ errBuf := bytes .NewBuffer (nil )
98101 if d , ok := driverImpl .(* driver.DockerDriver ); ok {
99102 d .SetDockerCli (dockerCli )
103+ if stdout != nil {
104+ d .SetContainerOut (stdout )
105+ }
106+ d .SetContainerErr (errBuf )
100107 if bindMount .required {
101108 d .AddConfigurationOptions (func (config * container.Config , hostConfig * container.HostConfig ) error {
102109 config .User = "0:0"
@@ -122,7 +129,7 @@ func prepareDriver(dockerCli command.Cli, bindMount bindMount) (driver.Driver, e
122129 configurable .SetConfig (driverCfg )
123130 }
124131
125- return driverImpl , err
132+ return driverImpl , errBuf , err
126133}
127134
128135func getAppNameKind (name string ) (string , nameKind ) {
@@ -243,21 +250,20 @@ func isDockerHostLocal(host string) bool {
243250 return host == "" || strings .HasPrefix (host , "unix://" ) || strings .HasPrefix (host , "npipe://" )
244251}
245252
246- func prepareCustomAction (actionName string , dockerCli command.Cli , appname string ,
247- registryOpts registryOptions , pullOpts pullOptions , paramsOpts parametersOptions ) (* action.RunCustom , * claim.Claim , error ) {
248- defer muteDockerCli (dockerCli )()
253+ func prepareCustomAction (actionName string , dockerCli command.Cli , appname string , stdout io.Writer ,
254+ registryOpts registryOptions , pullOpts pullOptions , paramsOpts parametersOptions ) (* action.RunCustom , * claim.Claim , * bytes.Buffer , error ) {
249255
250256 c , err := claim .New (actionName )
251257 if err != nil {
252- return nil , nil , err
258+ return nil , nil , nil , err
253259 }
254- driverImpl , err := prepareDriver (dockerCli , bindMount {})
260+ driverImpl , errBuf , err := prepareDriver (dockerCli , bindMount {}, stdout )
255261 if err != nil {
256- return nil , nil , err
262+ return nil , nil , nil , err
257263 }
258264 bundle , err := resolveBundle (dockerCli , appname , pullOpts .pull , registryOpts .insecureRegistries )
259265 if err != nil {
260- return nil , nil , err
266+ return nil , nil , nil , err
261267 }
262268 c .Bundle = bundle
263269
@@ -266,13 +272,13 @@ func prepareCustomAction(actionName string, dockerCli command.Cli, appname strin
266272 withCommandLineParameters (paramsOpts .overrides ),
267273 )
268274 if err != nil {
269- return nil , nil , err
275+ return nil , nil , nil , err
270276 }
271277 c .Parameters = parameters
272278
273279 a := & action.RunCustom {
274280 Action : internal .Namespace + actionName ,
275281 Driver : driverImpl ,
276282 }
277- return a , c , nil
283+ return a , c , errBuf , nil
278284}
0 commit comments