git.go 1.1 KB

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