github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/builder/remotecontext/git.go (about)

     1  package remotecontext // import "github.com/docker/docker/builder/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  	"github.com/sirupsen/logrus"
    10  )
    11  
    12  // MakeGitContext returns a Context from gitURL that is cloned in a temporary directory.
    13  func MakeGitContext(gitURL string) (builder.Source, error) {
    14  	root, err := git.Clone(gitURL)
    15  	if err != nil {
    16  		return nil, err
    17  	}
    18  
    19  	c, err := archive.Tar(root, archive.Uncompressed)
    20  	if err != nil {
    21  		return nil, err
    22  	}
    23  
    24  	defer func() {
    25  		err := c.Close()
    26  		if err != nil {
    27  			logrus.WithField("action", "MakeGitContext").WithField("module", "builder").WithField("url", gitURL).WithError(err).Error("error while closing git context")
    28  		}
    29  		err = os.RemoveAll(root)
    30  		if err != nil {
    31  			logrus.WithField("action", "MakeGitContext").WithField("module", "builder").WithField("url", gitURL).WithError(err).Error("error while removing path and children of root")
    32  		}
    33  	}()
    34  	return FromArchive(c)
    35  }