Skip to content

Commit

Permalink
Merge pull request #138 from CircleCI-Public/no-docker-error
Browse files Browse the repository at this point in the history
Improve error message when docker is not present or not started.
  • Loading branch information
Zachary Scott authored Sep 27, 2018
2 parents 4cccbce + d5f3536 commit 599362a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
21 changes: 19 additions & 2 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,22 @@ You can use 'circleci config process' to pre-process your config into a version
return nil
}

func ensureDockerIsAvailable() error {
if _, err := exec.LookPath("docker"); err != nil {
return errors.New("could not find `docker` on the PATH; please ensure than docker is installed")
}

dockerRunning := exec.Command("docker", "version").Run() == nil // #nosec

if !dockerRunning {
return errors.New("failed to connect to docker; please ensure that docker is running, and that `docker version` succeeds")
}

return nil
}

func runExecute(cmd *cobra.Command, args []string) error {
err := validateConfigVersion(args)
if err != nil {
if err := validateConfigVersion(args); err != nil {
return err
}

Expand All @@ -223,6 +236,10 @@ func runExecute(cmd *cobra.Command, args []string) error {
return errors.Wrap(err, "Could not find pwd")
}

if err = ensureDockerIsAvailable(); err != nil {
return err
}

image, err := picardImage()

if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ func updateBuildAgent(cmd *cobra.Command, args []string) error {

// Still depends on a function in cmd/build.go
func findLatestPicardSha() (string, error) {

if err := ensureDockerIsAvailable(); err != nil {
return "", err
}

outputBytes, err := exec.Command("docker", "pull", picardRepo).CombinedOutput() // #nosec

if err != nil {
Expand Down

0 comments on commit 599362a

Please sign in to comment.