Merge pull request #737 from AkihiroSuda/allow-without-git
worker/base: allow running without `git` installeddocker-18.09
commit
75c4dffb61
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue