github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/builder/remotecontext/git.go (about)

     1  package remotecontext // import "github.com/Prakhar-Agarwal-byte/moby/builder/remotecontext"
     2  
     3  import (
     4  	"context"
     5  	"os"
     6  
     7  	"github.com/containerd/log"
     8  	"github.com/Prakhar-Agarwal-byte/moby/builder"
     9  	"github.com/Prakhar-Agarwal-byte/moby/builder/remotecontext/git"
    10  	"github.com/Prakhar-Agarwal-byte/moby/pkg/archive"
    11  )
    12  
    13  // MakeGitContext returns a Context from gitURL that is cloned in a temporary directory.
    14  func MakeGitContext(gitURL string) (builder.Source, error) {
    15  	root, err := git.Clone(gitURL, git.WithIsolatedConfig(true))
    16  	if err != nil {
    17  		return nil, err
    18  	}
    19  
    20  	c, err := archive.Tar(root, archive.Uncompressed)
    21  	if err != nil {
    22  		return nil, err
    23  	}
    24  
    25  	defer func() {
    26  		err := c.Close()
    27  		if err != nil {
    28  			log.G(context.TODO()).WithField("action", "MakeGitContext").WithField("module", "builder").WithField("url", gitURL).WithError(err).Error("error while closing git context")
    29  		}
    30  		err = os.RemoveAll(root)
    31  		if err != nil {
    32  			log.G(context.TODO()).WithField("action", "MakeGitContext").WithField("module", "builder").WithField("url", gitURL).WithError(err).Error("error while removing path and children of root")
    33  		}
    34  	}()
    35  	return FromArchive(c)
    36  }