@@ -8,13 +8,6 @@ import (
88 "github.com/sirupsen/logrus"
99)
1010
11- const (
12- // Podman cli tool
13- Podman = "podman"
14- // Docker cli tool
15- Docker = "docker"
16- )
17-
1811// CommandRunner defines methods to shell out to common container tools
1912type CommandRunner interface {
2013 GetToolName () string
@@ -28,42 +21,32 @@ type CommandRunner interface {
2821// execute commands with that tooling.
2922type ContainerCommandRunner struct {
3023 logger * logrus.Entry
31- containerTool string
24+ containerTool ContainerTool
3225}
3326
3427// NewCommandRunner takes the containerTool as an input string and returns a
3528// CommandRunner to run commands with that cli tool
36- func NewCommandRunner (containerTool string , logger * logrus.Entry ) CommandRunner {
29+ func NewCommandRunner (containerTool ContainerTool , logger * logrus.Entry ) CommandRunner {
3730 r := ContainerCommandRunner {
3831 logger : logger ,
32+ containerTool : containerTool ,
3933 }
40-
41- switch containerTool {
42- case Podman :
43- r .containerTool = Podman
44- case Docker :
45- r .containerTool = Docker
46- default :
47- r .containerTool = Podman
48- }
49-
5034 return & r
5135}
5236
5337// GetToolName returns the container tool this command runner is using
5438func (r * ContainerCommandRunner ) GetToolName () string {
55- return r .containerTool
39+ return r .containerTool . String ()
5640}
5741
5842// Pull takes a container image path hosted on a container registry and runs the
5943// pull command to download it onto the local environment
6044func (r * ContainerCommandRunner ) Pull (image string ) error {
6145 args := []string {"pull" , image }
6246
63- command := exec .Command (r .containerTool , args ... )
47+ command := exec .Command (r .containerTool . String () , args ... )
6448
65- r .logger .Infof ("running %s pull" , r .containerTool )
66- r .logger .Debugf ("%s" , command .Args )
49+ r .logger .Infof ("running %s" , command .String ())
6750
6851 out , err := command .CombinedOutput ()
6952 if err != nil {
@@ -84,7 +67,7 @@ func (r *ContainerCommandRunner) Build(dockerfile, tag string) error {
8467
8568 args = append (args , "." )
8669
87- command := exec .Command (r .containerTool , args ... )
70+ command := exec .Command (r .containerTool . String () , args ... )
8871
8972 r .logger .Infof ("running %s build" , r .containerTool )
9073 r .logger .Infof ("%s" , command .Args )
@@ -103,7 +86,7 @@ func (r *ContainerCommandRunner) Build(dockerfile, tag string) error {
10386func (r * ContainerCommandRunner ) Save (image , tarFile string ) error {
10487 args := []string {"save" , image , "-o" , tarFile }
10588
106- command := exec .Command (r .containerTool , args ... )
89+ command := exec .Command (r .containerTool . String () , args ... )
10790
10891 r .logger .Infof ("running %s save" , r .containerTool )
10992 r .logger .Debugf ("%s" , command .Args )
@@ -122,7 +105,7 @@ func (r *ContainerCommandRunner) Save(image, tarFile string) error {
122105func (r * ContainerCommandRunner ) Inspect (image string ) ([]byte , error ) {
123106 args := []string {"inspect" , image }
124107
125- command := exec .Command (r .containerTool , args ... )
108+ command := exec .Command (r .containerTool . String () , args ... )
126109
127110 r .logger .Infof ("running %s inspect" , r .containerTool )
128111 r .logger .Debugf ("%s" , command .Args )
0 commit comments