git.go 984 B

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