git.go 585 B

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