Don't ignore errors from checkout source code (#1584)

Don't check out code for builtin services.
This commit is contained in:
Janos Dobronszki 2020-04-28 10:51:39 +02:00 committed by GitHub
parent 8148e0a0f8
commit b875868a39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 8 deletions

View File

@ -55,11 +55,17 @@ func NewRuntime(opts ...Option) Runtime {
// @todo move this to runtime default // @todo move this to runtime default
func (r *runtime) checkoutSourceIfNeeded(s *Service) error { func (r *runtime) checkoutSourceIfNeeded(s *Service) error {
// Runtime service like config have no source.
// Skip checkout in that case
if len(s.Source) == 0 {
return nil
}
source, err := git.ParseSourceLocal("", s.Source) source, err := git.ParseSourceLocal("", s.Source)
if err != nil { if err != nil {
return err return err
} }
source.Ref = s.Version source.Ref = s.Version
err = git.CheckoutSource(os.TempDir(), source) err = git.CheckoutSource(os.TempDir(), source)
if err != nil { if err != nil {
return err return err
@ -209,7 +215,10 @@ func serviceKey(s *Service) string {
// Create creates a new service which is then started by runtime // Create creates a new service which is then started by runtime
func (r *runtime) Create(s *Service, opts ...CreateOption) error { func (r *runtime) Create(s *Service, opts ...CreateOption) error {
r.checkoutSourceIfNeeded(s) err := r.checkoutSourceIfNeeded(s)
if err != nil {
return err
}
r.Lock() r.Lock()
defer r.Unlock() defer r.Unlock()
@ -389,14 +398,17 @@ func (r *runtime) Read(opts ...ReadOption) ([]*Service, error) {
// Update attemps to update the service // Update attemps to update the service
func (r *runtime) Update(s *Service, opts ...UpdateOption) error { func (r *runtime) Update(s *Service, opts ...UpdateOption) error {
r.checkoutSourceIfNeeded(s) err := r.checkoutSourceIfNeeded(s)
if err != nil {
return err
}
r.Lock() r.Lock()
service, ok := r.services[serviceKey(s)] service, ok := r.services[serviceKey(s)]
r.Unlock() r.Unlock()
if !ok { if !ok {
return errors.New("Service not found") return errors.New("Service not found")
} }
err := service.Stop() err = service.Stop()
if err != nil { if err != nil {
return err return err
} }

View File

@ -1,6 +1,7 @@
package git package git
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
@ -105,7 +106,7 @@ type binaryGitter struct {
} }
func (g binaryGitter) Clone(repo string) error { func (g binaryGitter) Clone(repo string) error {
fold := filepath.Join(g.folder, dirifyRepo(repo)) fold := filepath.Join(g.folder, dirifyRepo(repo), ".git")
exists, err := pathExists(fold) exists, err := pathExists(fold)
if err != nil { if err != nil {
return err return err
@ -113,6 +114,7 @@ func (g binaryGitter) Clone(repo string) error {
if exists { if exists {
return nil return nil
} }
fold = filepath.Join(g.folder, dirifyRepo(repo))
cmd := exec.Command("git", "clone", repo, ".") cmd := exec.Command("git", "clone", repo, ".")
err = os.MkdirAll(fold, 0777) err = os.MkdirAll(fold, 0777)
@ -130,9 +132,9 @@ func (g binaryGitter) Clone(repo string) error {
func (g binaryGitter) FetchAll(repo string) error { func (g binaryGitter) FetchAll(repo string) error {
cmd := exec.Command("git", "fetch", "--all") cmd := exec.Command("git", "fetch", "--all")
cmd.Dir = filepath.Join(g.folder, dirifyRepo(repo)) cmd.Dir = filepath.Join(g.folder, dirifyRepo(repo))
_, err := cmd.Output() outp, err := cmd.CombinedOutput()
if err != nil { if err != nil {
return err return errors.New(string(outp))
} }
return err return err
} }
@ -143,9 +145,9 @@ func (g binaryGitter) Checkout(repo, branchOrCommit string) error {
} }
cmd := exec.Command("git", "checkout", "-f", branchOrCommit) cmd := exec.Command("git", "checkout", "-f", branchOrCommit)
cmd.Dir = filepath.Join(g.folder, dirifyRepo(repo)) cmd.Dir = filepath.Join(g.folder, dirifyRepo(repo))
_, err := cmd.Output() outp, err := cmd.CombinedOutput()
if err != nil { if err != nil {
return err return errors.New(string(outp))
} }
return nil return nil
} }