From d69cec829bb476ede631a7206b7d3a09d777c629 Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Wed, 14 Aug 2024 14:55:03 -0400 Subject: [PATCH] defer the running of bundle install in the rails scanner to the callback --- scanner/rails.go | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/scanner/rails.go b/scanner/rails.go index 17eb3dbe3d..f5da94ee60 100644 --- a/scanner/rails.go +++ b/scanner/rails.go @@ -57,18 +57,6 @@ func configureRails(sourceDir string, config *ScannerConfig) (*SourceInfo, error } } - // attempt to install bundle before proceeding - args := []string{"install"} - - if checksPass(sourceDir, fileExists("Gemfile.lock")) { - args = append(args, "--quiet") - } - - cmd := exec.Command(bundle, args...) - cmd.Stdin = nil - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - s := &SourceInfo{ Family: "Rails", Callback: RailsCallback, @@ -332,17 +320,7 @@ func RailsCallback(appName string, srcInfo *SourceInfo, plan *plan.LaunchPlan, f if pendingError != nil { pendingError = errors.Wrap(pendingError, "Failed to add dockerfile-rails gem") } else { - cmd = exec.Command(bundle, "install", "--quiet") - cmd.Stdin = nil - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - - pendingError = cmd.Run() - if pendingError != nil { - pendingError = errors.Wrap(pendingError, "Failed to install dockerfile-rails gem") - } else { - generatorInstalled = true - } + generatorInstalled = true } } } else { @@ -350,6 +328,16 @@ func RailsCallback(appName string, srcInfo *SourceInfo, plan *plan.LaunchPlan, f generatorInstalled = true } + cmd := exec.Command(bundle, "install", "--quiet") + cmd.Stdin = nil + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + + err = cmd.Run() + if err != nil { + return errors.Wrap(pendingError, "Failed to install bundle, exiting") + } + // ensure Gemfile.lock includes the x86_64-linux platform if out, err := exec.Command(bundle, "platform").Output(); err == nil { if !strings.Contains(string(out), "x86_64-linux") {