2017-03-20 18:22:29 -04:00
|
|
|
package remotecontext
|
2015-09-06 13:26:40 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
2017-03-20 18:22:29 -04:00
|
|
|
"github.com/docker/docker/builder"
|
2017-06-01 17:15:13 -04:00
|
|
|
"github.com/docker/docker/builder/remotecontext/git"
|
2015-09-06 13:26:40 -04:00
|
|
|
"github.com/docker/docker/pkg/archive"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MakeGitContext returns a Context from gitURL that is cloned in a temporary directory.
|
2017-03-20 18:22:29 -04:00
|
|
|
func MakeGitContext(gitURL string) (builder.Source, error) {
|
2017-06-01 17:15:13 -04:00
|
|
|
root, err := git.Clone(gitURL)
|
2015-09-06 13:26:40 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
c, err := archive.Tar(root, archive.Uncompressed)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
// TODO: print errors?
|
|
|
|
c.Close()
|
|
|
|
os.RemoveAll(root)
|
|
|
|
}()
|
2017-05-15 17:54:27 -04:00
|
|
|
return FromArchive(c)
|
2015-09-06 13:26:40 -04:00
|
|
|
}
|