move git clone from daemon to client

Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)

add a little doc
This commit is contained in:
Victor Vieux 2014-02-26 23:20:58 +00:00
parent b5a544b02e
commit 8301fc8e56
3 changed files with 33 additions and 11 deletions

View file

@ -24,6 +24,7 @@ import (
"net/http/httputil"
"net/url"
"os"
"os/exec"
gosignal "os/signal"
"path"
"reflect"
@ -168,17 +169,34 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
return err
}
context, err = archive.Generate("Dockerfile", string(dockerfile))
} else if utils.IsURL(cmd.Arg(0)) || utils.IsGIT(cmd.Arg(0)) {
} else if utils.IsURL(cmd.Arg(0)) && !utils.IsGIT(cmd.Arg(0)) {
isRemote = true
} else {
if _, err := os.Stat(cmd.Arg(0)); err != nil {
root := cmd.Arg(0)
if utils.IsGIT(root) {
remoteURL := cmd.Arg(0)
if !strings.HasPrefix(remoteURL, "git://") && !strings.HasPrefix(remoteURL, "git@") && !utils.IsURL(remoteURL) {
remoteURL = "https://" + remoteURL
}
root, err = ioutil.TempDir("", "docker-build-git")
if err != nil {
return err
}
defer os.RemoveAll(root)
if output, err := exec.Command("git", "clone", "--recursive", remoteURL, root).CombinedOutput(); err != nil {
return fmt.Errorf("Error trying to use git: %s (%s)", err, output)
}
}
if _, err := os.Stat(root); err != nil {
return err
}
filename := path.Join(cmd.Arg(0), "Dockerfile")
filename := path.Join(root, "Dockerfile")
if _, err = os.Stat(filename); os.IsNotExist(err) {
return fmt.Errorf("no Dockerfile found in %s", cmd.Arg(0))
}
context, err = archive.Tar(cmd.Arg(0), archive.Uncompressed)
context, err = archive.Tar(root, archive.Uncompressed)
}
var body io.Reader
// Setup an upload progress bar

View file

@ -202,12 +202,16 @@ Examples:
--no-cache: Do not use the cache when building the image.
--rm=true: Remove intermediate containers after a successful build
The files at ``PATH`` or ``URL`` are called the "context" of the build. The
build process may refer to any of the files in the context, for example when
using an :ref:`ADD <dockerfile_add>` instruction. When a single ``Dockerfile``
is given as ``URL``, then no context is set. When a Git repository is set as
``URL``, then the repository is used as the context. Git repositories are
cloned with their submodules (`git clone --recursive`).
The files at ``PATH`` or ``URL`` are called the "context" of the build.
The build process may refer to any of the files in the context, for example when
using an :ref:`ADD <dockerfile_add>` instruction.
When a single ``Dockerfile`` is given as ``URL``, then no context is set.
When a Git repository is set as ``URL``, then the repository is used as the context.
The Git repository is cloned with its submodules (`git clone --recursive`).
A fresh git clone occurs in a temporary directory on your local host, and then this
is sent to the Docker daemon as the context.
This way, your local user credentials and vpn's etc can be used to access private repositories
.. _cli_build_examples:

View file

@ -714,7 +714,7 @@ func IsURL(str string) bool {
}
func IsGIT(str string) bool {
return strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "github.com/")
return strings.HasPrefix(str, "git://") || strings.HasPrefix(str, "github.com/") || strings.HasPrefix(str, "git@github.com:") || (strings.HasSuffix(str, ".git") && IsURL(str))
}
// GetResolvConf opens and read the content of /etc/resolv.conf.