Skip to content

Commit b7af076

Browse files
Merge pull request #156 from dinhxuanvu/fix/docker-error-output
Fix issue with empty docker error output
2 parents 0d3a65b + c6cd9fe commit b7af076

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

pkg/containertools/command.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package containertools
33

44
import (
5+
"fmt"
56
"os/exec"
67

78
"github.com/sirupsen/logrus"
@@ -23,15 +24,15 @@ type CommandRunner interface {
2324
Inspect(image string) ([]byte, error)
2425
}
2526

26-
// ContainerCommandRunner is configured to select a container cli tool and execute commands with that
27-
// tooling.
27+
// ContainerCommandRunner is configured to select a container cli tool and
28+
// execute commands with that tooling.
2829
type ContainerCommandRunner struct {
2930
logger *logrus.Entry
3031
containerTool string
3132
}
3233

33-
// NewCommandRunner takes the containerTool as an input string and returns a CommandRunner to
34-
// run commands with that cli tool
34+
// NewCommandRunner takes the containerTool as an input string and returns a
35+
// CommandRunner to run commands with that cli tool
3536
func NewCommandRunner(containerTool string, logger *logrus.Entry) CommandRunner {
3637
r := ContainerCommandRunner{
3738
logger: logger,
@@ -54,8 +55,8 @@ func (r *ContainerCommandRunner) GetToolName() string {
5455
return r.containerTool
5556
}
5657

57-
// Pull takes a container image path hosted on a container registry and runs the pull command to
58-
// download it onto the local environment
58+
// Pull takes a container image path hosted on a container registry and runs the
59+
// pull command to download it onto the local environment
5960
func (r *ContainerCommandRunner) Pull(image string) error {
6061
args := []string{"pull", image}
6162

@@ -64,10 +65,10 @@ func (r *ContainerCommandRunner) Pull(image string) error {
6465
r.logger.Infof("running %s pull", r.containerTool)
6566
r.logger.Debugf("%s", command.Args)
6667

67-
out, err := command.Output()
68+
out, err := command.CombinedOutput()
6869
if err != nil {
6970
r.logger.Errorf(string(out))
70-
return err
71+
return fmt.Errorf("error pulling image: %s. %v", string(out), err)
7172
}
7273

7374
return nil
@@ -88,17 +89,17 @@ func (r *ContainerCommandRunner) Build(dockerfile, tag string) error {
8889
r.logger.Infof("running %s build", r.containerTool)
8990
r.logger.Infof("%s", command.Args)
9091

91-
out, err := command.Output()
92+
out, err := command.CombinedOutput()
9293
if err != nil {
9394
r.logger.Errorf(string(out))
94-
return err
95+
return fmt.Errorf("error building image: %s. %v", string(out), err)
9596
}
9697

9798
return nil
9899
}
99100

100-
// Save takes a local container image and runs the save commmand to convert the image into a specified
101-
// tarball and push it to the local directory
101+
// Save takes a local container image and runs the save commmand to convert the
102+
// image into a specified tarball and push it to the local directory
102103
func (r *ContainerCommandRunner) Save(image, tarFile string) error {
103104
args := []string{"save", image, "-o", tarFile}
104105

@@ -107,17 +108,17 @@ func (r *ContainerCommandRunner) Save(image, tarFile string) error {
107108
r.logger.Infof("running %s save", r.containerTool)
108109
r.logger.Debugf("%s", command.Args)
109110

110-
out, err := command.Output()
111+
out, err := command.CombinedOutput()
111112
if err != nil {
112113
r.logger.Errorf(string(out))
113-
return err
114+
return fmt.Errorf("error saving image: %s. %v", string(out), err)
114115
}
115116

116117
return nil
117118
}
118119

119-
// Inspect runs the 'inspect' command to get image metadata of a local container image
120-
// and returns a byte array of the command's output
120+
// Inspect runs the 'inspect' command to get image metadata of a local container
121+
// image and returns a byte array of the command's output
121122
func (r *ContainerCommandRunner) Inspect(image string) ([]byte, error) {
122123
args := []string{"inspect", image}
123124

0 commit comments

Comments
 (0)