Repository: railwayapp/nixpacks
Pull request #479 (2022-08-30 23:15:05)

dynamic left column widths
Set the left column width to max text content



Patch:
diff --git a/examples/ruby-local-deps/Gemfile b/examples/ruby-local-deps/Gemfile
new file mode 100644
index 0000000..37c7e89
--- /dev/null
+++ b/examples/ruby-local-deps/Gemfile
@@ -0,0 +1,3 @@
+source 'https://rubygems.org'
+
+gem "local", path: "libs/local"
diff --git a/examples/ruby-local-deps/Gemfile.lock b/examples/ruby-local-deps/Gemfile.lock
new file mode 100644
index 0000000..f877fbe
--- /dev/null
+++ b/examples/ruby-local-deps/Gemfile.lock
@@ -0,0 +1,20 @@
+PATH
+  remote: libs/local
+  specs:
+    local (0.1.0)
+
+GEM
+  remote: https://rubygems.org/
+  specs:
+
+PLATFORMS
+  arm64-darwin-21
+
+DEPENDENCIES
+  local!
+
+RUBY VERSION
+   ruby 3.1.2p20
+
+BUNDLED WITH
+   2.3.7
diff --git a/examples/ruby-local-deps/Procfile b/examples/ruby-local-deps/Procfile
new file mode 100644
index 0000000..4a7f07b
--- /dev/null
+++ b/examples/ruby-local-deps/Procfile
@@ -0,0 +1,1 @@
+web: bundle exec ruby app.rb
diff --git a/examples/ruby-local-deps/app.rb b/examples/ruby-local-deps/app.rb
new file mode 100644
index 0000000..984bf84
--- /dev/null
+++ b/examples/ruby-local-deps/app.rb
@@ -0,0 +1,3 @@
+require "local"
+
+Local.hi
diff --git a/examples/ruby-local-deps/libs/local/Gemfile b/examples/ruby-local-deps/libs/local/Gemfile
new file mode 100644
index 0000000..2d1f73e
--- /dev/null
+++ b/examples/ruby-local-deps/libs/local/Gemfile
@@ -0,0 +1,4 @@
+source "https://rubygems.org"
+git_source(:github) { |repo| "https://github.com/#{repo}.git" }
+
+gemspec
diff --git a/examples/ruby-local-deps/libs/local/lib/local.rb b/examples/ruby-local-deps/libs/local/lib/local.rb
new file mode 100644
index 0000000..510cedc
--- /dev/null
+++ b/examples/ruby-local-deps/libs/local/lib/local.rb
@@ -0,0 +1,5 @@
+class Local
+  def self.hi
+    puts "Hello world from Local lib"
+  end
+end
diff --git a/examples/ruby-local-deps/libs/local/local.gemspec b/examples/ruby-local-deps/libs/local/local.gemspec
new file mode 100644
index 0000000..06d31de
--- /dev/null
+++ b/examples/ruby-local-deps/libs/local/local.gemspec
@@ -0,0 +1,11 @@
+# Describe your gem and declare its dependencies:
+Gem::Specification.new do |s|
+  s.name = "local"
+  s.version = "0.1.0"
+  s.authors = ["Nixpacks"]
+  s.homepage = ""
+  s.summary = ""
+  s.description = ""
+  s.license = "MIT"
+  s.files = ["lib/local.rb"]
+end
diff --git a/examples/ruby-with-node/app.rb b/examples/ruby-with-node/app.rb
index 0bbb7fd..8c0da45 100644
--- a/examples/ruby-with-node/app.rb
+++ b/examples/ruby-with-node/app.rb
@@ -1,1 +1,1 @@
-puts "Hello from Ruby"
+puts "Hello from Ruby with Node"
diff --git a/src/nixpacks/plan/pretty_print.rs b/src/nixpacks/plan/pretty_print.rs
index db2c791..d35249d 100644
--- a/src/nixpacks/plan/pretty_print.rs
+++ b/src/nixpacks/plan/pretty_print.rs
@@ -5,7 +5,7 @@ use colored::Colorize;
 use indoc::formatdoc;
 use std::fmt::Write;
 
-const FIRST_COLUMN_WIDTH: usize = 10;
+const FIRST_COLUMN_MIN_WIDTH: usize = 10;
 const MIN_BOX_WIDTH: usize = 20;
 const MAX_BOX_WIDTH: usize = 80;
 
@@ -42,6 +42,15 @@ impl BuildPlan {
             console::measure_text_width(start_contents.as_str()),
         );
 
+        let first_column_width = std::cmp::max(
+            FIRST_COLUMN_MIN_WIDTH,
+            phase_contents
+                .iter()
+                .map(|(name, _)| console::measure_text_width(name))
+                .max()
+                .unwrap_or(0),
+        );
+
         let edge = format!("{} ", box_drawing::double::VERTICAL);
         let edge_width = console::measure_text_width(edge.as_str());
 
@@ -53,12 +62,12 @@ impl BuildPlan {
             MAX_BOX_WIDTH,
             std::cmp::max(
                 MIN_BOX_WIDTH,
-                (edge_width * 2) + FIRST_COLUMN_WIDTH + middle_padding_width + max_right_content,
+                (edge_width * 2) + first_column_width + middle_padding_width + max_right_content,
             ),
         );
 
         let second_column_width =
-            box_width - (edge_width * 2) - FIRST_COLUMN_WIDTH - middle_padding_width;
+            box_width - (edge_width * 2) - first_column_width - middle_padding_width;
 
         let title_side_padding = ((box_width as f64) - (title_width as f64) - 2.0) / 2.0;
 
@@ -107,6 +116,7 @@ impl BuildPlan {
                     content.as_str(),
                     edge.as_str(),
                     middle_padding.as_str(),
+                    first_column_width,
                     second_column_width,
                     false,
                 )
@@ -119,6 +129,7 @@ impl BuildPlan {
             start_contents.as_str(),
             edge.as_str(),
             middle_padding.as_str(),
+            first_column_width,
             second_column_width,
             false,
         );
@@ -187,6 +198,7 @@ fn print_row(
     content: &str,
     left_edge: &str,
     middle: &str,
+    first_column_width: usize,
     second_column_width: usize,
     indent_second_line: bool,
 ) -> String {
@@ -202,7 +214,7 @@ fn print_row(
     let mut output = format!(
         "{}{}{}{}{}",
         left_edge.cyan().dimmed(),
-        console::pad_str(title, FIRST_COLUMN_WIDTH, console::Alignment::Left, None),
+        console::pad_str(title, first_column_width, console::Alignment::Left, None),
         middle,
         console::pad_str(
             &list_lines[0],
@@ -218,7 +230,7 @@ fn print_row(
             "{}\n{}{}{}{}{}",
             output,
             left_edge.cyan().dimmed(),
-            console::pad_str("", FIRST_COLUMN_WIDTH, console::Alignment::Left, None),
+            console::pad_str("", first_column_width, console::Alignment::Left, None),
             middle,
             console::pad_str(line, second_column_width, console::Alignment::Left, None),
             right_edge.cyan().dimmed()
diff --git a/src/providers/ruby.rs b/src/providers/ruby.rs
index cd54f6d..c06ef5a 100644
--- a/src/providers/ruby.rs
+++ b/src/providers/ruby.rs
@@ -81,7 +81,6 @@ impl RubyProvider {
 
     fn get_install(&self, app: &App) -> Result<Option<Phase>> {
         let mut install = Phase::install(None);
-        install.add_file_dependency("Gemfile*".to_string());
         install.add_cache_directory(BUNDLE_CACHE_DIR.to_string());
 
         install.add_cmd("bundle install".to_string());


Test patch:
diff --git a/tests/docker_run_tests.rs b/tests/docker_run_tests.rs
index 06b23f1..60860b4 100644
--- a/tests/docker_run_tests.rs
+++ b/tests/docker_run_tests.rs
@@ -645,6 +645,20 @@ fn test_ruby_sinatra() {
     assert!(output.contains("Hello from Sinatra"));
 }
 
+#[test]
+fn test_ruby_node() {
+    let name = simple_build("./examples/ruby-with-node/");
+    let output = run_image(&name, None);
+    assert!(output.contains("Hello from Ruby with Node"));
+}
+
+#[test]
+fn test_ruby_local_deps() {
+    let name = simple_build("./examples/ruby-local-deps/");
+    let output = run_image(&name, None);
+    assert!(output.contains("Hello world from Local lib"));
+}
+
 #[test]
 fn test_ruby_rails() {
     // Create the network
diff --git a/tests/snapshots/generate_plan_tests__ruby.snap b/tests/snapshots/generate_plan_tests__ruby.snap
index 55195b0..788cccf 100644
--- a/tests/snapshots/generate_plan_tests__ruby.snap
+++ b/tests/snapshots/generate_plan_tests__ruby.snap
@@ -32,9 +32,6 @@ expression: plan
       "commands": [
         "bundle install"
       ],
-      "onlyIncludeFiles": [
-        "Gemfile*"
-      ],
       "cacheDirectories": [
         "/root/.bundle/cache"
       ],
diff --git a/tests/snapshots/generate_plan_tests__ruby_local_deps.snap b/tests/snapshots/generate_plan_tests__ruby_local_deps.snap
new file mode 100644
index 0000000..20ad7e7
--- /dev/null
+++ b/tests/snapshots/generate_plan_tests__ruby_local_deps.snap
@@ -0,0 +1,54 @@
+---
+source: tests/generate_plan_tests.rs
+expression: plan
+---
+{
+  "nixpacksVersion": "[version]",
+  "buildImage": "[build_image]",
+  "variables": {
+    "BUNDLE_GEMFILE": "/app/Gemfile",
+    "GEM_HOME": "/usr/local/rvm/gems/ruby-3.1.2",
+    "GEM_PATH": "/usr/local/rvm/gems/ruby-3.1.2:/usr/local/rvm/gems/ruby-3.1.2@global"
+  },
+  "phases": [
+    {
+      "name": "setup",
+      "aptPackages": [
+        "procps"
+      ],
+      "commands": [
+        "curl -sSL https://get.rvm.io | bash -s stable && . /etc/profile.d/rvm.sh",
+        "rvm install ruby-3.1.2",
+        "rvm --default use ruby-3.1.2",
+        "gem install bundler:2.3.7",
+        "echo 'source /usr/local/rvm/scripts/rvm' >> /root/.profile"
+      ]
+    },
+    {
+      "name": "install",
+      "dependsOn": [
+        "setup"
+      ],
+      "commands": [
+        "bundle install"
+      ],
+      "cacheDirectories": [
+        "/root/.bundle/cache"
+      ],
+      "paths": [
+        "/usr/local/rvm/rubies/ruby-3.1.2/bin",
+        "/usr/local/rvm/gems/ruby-3.1.2/bin",
+        "/usr/local/rvm/gems/ruby-3.1.2@global/bin"
+      ]
+    },
+    {
+      "name": "build",
+      "dependsOn": [
+        "install"
+      ]
+    }
+  ],
+  "startPhase": {
+    "cmd": "bundle exec ruby app.rb"
+  }
+}
diff --git a/tests/snapshots/generate_plan_tests__ruby_rails_postgres.snap b/tests/snapshots/generate_plan_tests__ruby_rails_postgres.snap
index 04c5848..2f3f6f1 100644
--- a/tests/snapshots/generate_plan_tests__ruby_rails_postgres.snap
+++ b/tests/snapshots/generate_plan_tests__ruby_rails_postgres.snap
@@ -19,9 +19,6 @@ expression: plan
       "commands": [
         "bundle install"
       ],
-      "onlyIncludeFiles": [
-        "Gemfile*"
-      ],
       "cacheDirectories": [
         "/root/.bundle/cache"
       ],
diff --git a/tests/snapshots/generate_plan_tests__ruby_sinatra.snap b/tests/snapshots/generate_plan_tests__ruby_sinatra.snap
index 4d662d3..cd70545 100644
--- a/tests/snapshots/generate_plan_tests__ruby_sinatra.snap
+++ b/tests/snapshots/generate_plan_tests__ruby_sinatra.snap
@@ -32,9 +32,6 @@ expression: plan
       "commands": [
         "bundle install"
       ],
-      "onlyIncludeFiles": [
-        "Gemfile*"
-      ],
       "cacheDirectories": [
         "/root/.bundle/cache"
       ],
diff --git a/tests/snapshots/generate_plan_tests__ruby_with_node.snap b/tests/snapshots/generate_plan_tests__ruby_with_node.snap
index debca78..5ee43fa 100644
--- a/tests/snapshots/generate_plan_tests__ruby_with_node.snap
+++ b/tests/snapshots/generate_plan_tests__ruby_with_node.snap
@@ -59,9 +59,6 @@ expression: plan
       "commands": [
         "bundle install"
       ],
-      "onlyIncludeFiles": [
-        "Gemfile*"
-      ],
       "cacheDirectories": [
         "/root/.bundle/cache"
       ],