Ver Fonte

api: client: build: do not fall through if git isn't installed

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
Antonio Murdaca há 9 anos atrás
pai
commit
167cc42986
2 ficheiros alterados com 19 adições e 4 exclusões
  1. 4 4
      api/client/build.go
  2. 15 0
      integration-cli/docker_cli_build_test.go

+ 4 - 4
api/client/build.go

@@ -81,9 +81,6 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
 		err     error
 		err     error
 	)
 	)
 
 
-	_, err = exec.LookPath("git")
-	hasGit := err == nil
-
 	specifiedContext := cmd.Arg(0)
 	specifiedContext := cmd.Arg(0)
 
 
 	var (
 	var (
@@ -104,7 +101,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
 	switch {
 	switch {
 	case specifiedContext == "-":
 	case specifiedContext == "-":
 		context, relDockerfile, err = getContextFromReader(cli.in, *dockerfileName)
 		context, relDockerfile, err = getContextFromReader(cli.in, *dockerfileName)
-	case urlutil.IsGitURL(specifiedContext) && hasGit:
+	case urlutil.IsGitURL(specifiedContext):
 		tempDir, relDockerfile, err = getContextFromGitURL(specifiedContext, *dockerfileName)
 		tempDir, relDockerfile, err = getContextFromGitURL(specifiedContext, *dockerfileName)
 	case urlutil.IsURL(specifiedContext):
 	case urlutil.IsURL(specifiedContext):
 		context, relDockerfile, err = getContextFromURL(progBuff, specifiedContext, *dockerfileName)
 		context, relDockerfile, err = getContextFromURL(progBuff, specifiedContext, *dockerfileName)
@@ -503,6 +500,9 @@ func getContextFromReader(r io.ReadCloser, dockerfileName string) (out io.ReadCl
 // path of the dockerfile in that context directory, and a non-nil error on
 // path of the dockerfile in that context directory, and a non-nil error on
 // success.
 // success.
 func getContextFromGitURL(gitURL, dockerfileName string) (absContextDir, relDockerfile string, err error) {
 func getContextFromGitURL(gitURL, dockerfileName string) (absContextDir, relDockerfile string, err error) {
+	if _, err := exec.LookPath("git"); err != nil {
+		return "", "", fmt.Errorf("unable to find 'git': %v", err)
+	}
 	if absContextDir, err = gitutils.Clone(gitURL); err != nil {
 	if absContextDir, err = gitutils.Clone(gitURL); err != nil {
 		return "", "", fmt.Errorf("unable to 'git clone' to temporary context directory: %v", err)
 		return "", "", fmt.Errorf("unable to 'git clone' to temporary context directory: %v", err)
 	}
 	}

+ 15 - 0
integration-cli/docker_cli_build_test.go

@@ -6632,3 +6632,18 @@ func (s *DockerSuite) TestBuildCacheRootSource(c *check.C) {
 
 
 	c.Assert(out, checker.Not(checker.Contains), "Using cache")
 	c.Assert(out, checker.Not(checker.Contains), "Using cache")
 }
 }
+
+// #19375
+func (s *DockerSuite) TestBuildFailsGitNotCallable(c *check.C) {
+	cmd := exec.Command(dockerBinary, "build", "github.com/docker/v1.10-migrator.git")
+	cmd.Env = append(cmd.Env, "PATH=")
+	out, _, err := runCommandWithOutput(cmd)
+	c.Assert(err, checker.NotNil)
+	c.Assert(out, checker.Contains, "unable to prepare context: unable to find 'git': ")
+
+	cmd = exec.Command(dockerBinary, "build", "https://github.com/docker/v1.10-migrator.git")
+	cmd.Env = append(cmd.Env, "PATH=")
+	out, _, err = runCommandWithOutput(cmd)
+	c.Assert(err, checker.NotNil)
+	c.Assert(out, checker.Contains, "unable to prepare context: unable to find 'git': ")
+}