Files
moby/daemon/builder/remotecontext/git.go
Sebastiaan van Stijn 734bb626e4 remove uses of deprecated go-archive consts
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 7239c72eca)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-01-08 10:54:50 +01:00

46 lines
1.1 KiB
Go

package remotecontext
import (
"context"
"os"
"github.com/containerd/log"
"github.com/moby/go-archive"
"github.com/moby/go-archive/compression"
"github.com/moby/moby/v2/daemon/builder"
"github.com/moby/moby/v2/daemon/builder/remotecontext/git"
)
// MakeGitContext returns a Context from gitURL that is cloned in a temporary directory.
func MakeGitContext(gitURL string) (builder.Source, error) {
root, err := git.Clone(gitURL, git.WithIsolatedConfig(true))
if err != nil {
return nil, err
}
c, err := archive.Tar(root, compression.None)
if err != nil {
return nil, err
}
defer func() {
if err := c.Close(); err != nil {
log.G(context.TODO()).WithFields(log.Fields{
"error": err,
"action": "MakeGitContext",
"module": "builder",
"url": gitURL,
}).Error("error while closing git context")
}
if err := os.RemoveAll(root); err != nil {
log.G(context.TODO()).WithFields(log.Fields{
"error": err,
"action": "MakeGitContext",
"module": "builder",
"url": gitURL,
}).Error("error while removing path and children of root")
}
}()
return FromArchive(c)
}