github.com/jiasir/docker@v1.3.3-0.20170609024000-252e610103e7/builder/remotecontext/git.go (about)

     1  package remotecontext
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/docker/docker/builder"
     7  	"github.com/docker/docker/builder/remotecontext/git"
     8  	"github.com/docker/docker/pkg/archive"
     9  )
    10  
    11  // MakeGitContext returns a Context from gitURL that is cloned in a temporary directory.
    12  func MakeGitContext(gitURL string) (builder.Source, error) {
    13  	root, err := git.Clone(gitURL)
    14  	if err != nil {
    15  		return nil, err
    16  	}
    17  
    18  	c, err := archive.Tar(root, archive.Uncompressed)
    19  	if err != nil {
    20  		return nil, err
    21  	}
    22  
    23  	defer func() {
    24  		// TODO: print errors?
    25  		c.Close()
    26  		os.RemoveAll(root)
    27  	}()
    28  	return MakeTarSumContext(c)
    29  }