Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Fixes #914 by changing Docker's invocation command (#925)
Browse files Browse the repository at this point in the history
* Fixes #914 by changing Docker's invocation command from 'docker' to 'com.docker.cli'.

Signed-off-by: Danilo Cominotti Marques <[email protected]>

* Fixes #914 by changing Docker's invocation command from 'docker' to 'com.docker.cli'.

Signed-off-by: Danilo Cominotti Marques <[email protected]>
  • Loading branch information
dcominottim authored and GuillaumeFalourd committed May 14, 2021
1 parent 57d8fdb commit 1ead82f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions pkg/formula/runner/docker/pre_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"time"

Expand All @@ -39,7 +40,6 @@ const (
loadConfigErrMsg = `Failed to load formula config file
Try running rit update repo
Config file path not found: %s`
dockerCmd = "docker"
)

var (
Expand Down Expand Up @@ -208,7 +208,7 @@ func buildRunImg(def formula.Definition) (string, error) {
containerId = strings.ToLower(containerId)
args := []string{"build", "-t", containerId, "."}
//nolint:gosec
cmd := exec.Command(dockerCmd, args...) // Run command "docker build -t (randomId) ."
cmd := exec.Command(getDockerCmd(), args...) // Run command "docker build -t (randomId) ."
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout

Expand All @@ -223,7 +223,7 @@ func buildRunImg(def formula.Definition) (string, error) {
// validate checks if able to run inside docker
func validateDocker(dockerImg string) error {
args := []string{"version", "--format", "'{{.Server.Version}}'"}
cmd := exec.Command(dockerCmd, args...)
cmd := exec.Command(getDockerCmd(), args...)
output, err := cmd.CombinedOutput()
if output == nil || err != nil {
return ErrDockerNotInstalled
Expand All @@ -245,3 +245,11 @@ func validateVolumes(dockerVolumes []string) error {
}
return nil
}

func getDockerCmd() string {
if runtime.GOOS == "linux" {
return "docker"
} else {
return "com.docker.cli"
}
}
2 changes: 1 addition & 1 deletion pkg/formula/runner/docker/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (ru RunManager) runDocker(setup formula.Setup, inputType api.TermInputType,
)

//nolint:gosec,lll
cmd := exec.Command(dockerCmd, args...) // Run command "docker run -env-file .env -v "$(pwd):/app" --name (randomId) (randomId)"
cmd := exec.Command(getDockerCmd(), args...) // Run command "docker run -env-file .env -v "$(pwd):/app" --name (randomId) (randomId)"
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
Expand Down

0 comments on commit 1ead82f

Please sign in to comment.