Merge pull request #737 from AkihiroSuda/allow-without-git

worker/base: allow running without `git` installed
docker-18.09
Tõnis Tiigi 2018-11-28 22:36:07 -08:00 committed by GitHub
commit 75c4dffb61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 13 deletions

View File

@ -37,17 +37,20 @@ type gitSource struct {
locker *locker.Locker
}
// Supported returns nil if the system supports Git source
func Supported() error {
if err := exec.Command("git", "version").Run(); err != nil {
return errors.Wrap(err, "failed to find git binary")
}
return nil
}
func NewSource(opt Opt) (source.Source, error) {
gs := &gitSource{
md: opt.MetadataStore,
cache: opt.CacheAccessor,
locker: locker.New(),
}
if err := exec.Command("git", "version").Run(); err != nil {
return nil, errors.Wrap(err, "failed to find git binary")
}
return gs, nil
}

View File

@ -46,6 +46,7 @@ import (
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
specs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
)
@ -118,16 +119,19 @@ func NewWorker(opt WorkerOpt) (*Worker, error) {
sm.Register(is)
gs, err := git.NewSource(git.Opt{
CacheAccessor: cm,
MetadataStore: opt.MetadataStore,
})
if err != nil {
return nil, err
if err := git.Supported(); err == nil {
gs, err := git.NewSource(git.Opt{
CacheAccessor: cm,
MetadataStore: opt.MetadataStore,
})
if err != nil {
return nil, err
}
sm.Register(gs)
} else {
logrus.Warnf("git source cannot be enabled: %v", err)
}
sm.Register(gs)
hs, err := http.NewSource(http.Opt{
CacheAccessor: cm,
MetadataStore: opt.MetadataStore,