Repository: railwayapp/nixpacks
Pull request #655 (2022-11-04 18:02:35)

remove rvm source after install
This PR decreases the final Ruby image size by a significant amount by removing the rvm source after installation

Fixes: https://github.com/railwayapp/nixpacks/issues/653



Patch:
diff --git a/src/nixpacks/builder/docker/docker_image_builder.rs b/src/nixpacks/builder/docker/docker_image_builder.rs
index 9c5b914..e41434f 100644
--- a/src/nixpacks/builder/docker/docker_image_builder.rs
+++ b/src/nixpacks/builder/docker/docker_image_builder.rs
@@ -65,11 +65,17 @@ impl ImageBuilder for DockerImageBuilder {
             return Ok(());
         }
 
-        println!("{}", plan.get_build_string()?);
+        let phase_count = plan.phases.clone().map_or(0, |phases| phases.len());
+        if phase_count > 0 {
+            println!("{}", plan.get_build_string()?);
 
-        let start = plan.start_phase.clone().unwrap_or_default();
-        if start.cmd.is_none() && !self.options.no_error_without_start {
-            bail!("No start command could be found")
+            let start = plan.start_phase.clone().unwrap_or_default();
+            if start.cmd.is_none() && !self.options.no_error_without_start {
+                bail!("No start command could be found")
+            }
+        } else {
+            println!("\nNixpacks was unable to generate a build plan for this app.\nPlease check the documentation for supported languages: https://nixpacks.com");
+            std::process::exit(1);
         }
 
         self.write_app(app_src, &output).context("Writing app")?;
diff --git a/src/providers/haskell.rs b/src/providers/haskell.rs
index e986692..a5ba893 100644
--- a/src/providers/haskell.rs
+++ b/src/providers/haskell.rs
@@ -20,7 +20,7 @@ pub struct HaskellStackProvider {}
 
 impl Provider for HaskellStackProvider {
     fn name(&self) -> &str {
-        "haskell_stack"
+        "haskell"
     }
 
     fn detect(&self, app: &App, _env: &Environment) -> Result<bool> {
diff --git a/src/providers/java.rs b/src/providers/java.rs
index 1ee6d0b..8d78c10 100644
--- a/src/providers/java.rs
+++ b/src/providers/java.rs
@@ -15,7 +15,7 @@ pub struct JavaProvider {}
 
 impl Provider for JavaProvider {
     fn name(&self) -> &str {
-        "Java"
+        "java"
     }
 
     fn detect(&self, app: &App, _env: &Environment) -> Result<bool> {
diff --git a/src/providers/ruby.rs b/src/providers/ruby.rs
index 04a6d4e..18ee130 100644
--- a/src/providers/ruby.rs
+++ b/src/providers/ruby.rs
@@ -17,7 +17,7 @@ const BUNDLE_CACHE_DIR: &str = "/root/.bundle/cache";
 
 impl Provider for RubyProvider {
     fn name(&self) -> &str {
-        "Ruby"
+        "ruby"
     }
 
     fn detect(&self, app: &App, _env: &Environment) -> Result<bool> {
@@ -85,7 +85,8 @@ impl RubyProvider {
             && . /etc/profile.d/rvm.sh \
             && rvm install {ruby_version} \
             && rvm --default use {ruby_version} \
-            && gem install {bundler_version}",
+            && gem install {bundler_version} \
+            && rm -rf /usr/local/rvm/src",
             ruby_version = self.get_ruby_version(app)?,
             bundler_version = self.get_bundler_version(app)
         ));


Test patch:
diff --git a/tests/snapshots/generate_plan_tests__java_gradle_hello_world.snap b/tests/snapshots/generate_plan_tests__java_gradle_hello_world.snap
index 0cafdd7..7857656 100644
--- a/tests/snapshots/generate_plan_tests__java_gradle_hello_world.snap
+++ b/tests/snapshots/generate_plan_tests__java_gradle_hello_world.snap
@@ -6,7 +6,7 @@ expression: plan
   "providers": [],
   "buildImage": "[build_image]",
   "variables": {
-    "NIXPACKS_METADATA": "Java"
+    "NIXPACKS_METADATA": "java"
   },
   "phases": {
     "build": {
diff --git a/tests/snapshots/generate_plan_tests__java_maven.snap b/tests/snapshots/generate_plan_tests__java_maven.snap
index c2884d1..214dcdd 100644
--- a/tests/snapshots/generate_plan_tests__java_maven.snap
+++ b/tests/snapshots/generate_plan_tests__java_maven.snap
@@ -6,7 +6,7 @@ expression: plan
   "providers": [],
   "buildImage": "[build_image]",
   "variables": {
-    "NIXPACKS_METADATA": "Java"
+    "NIXPACKS_METADATA": "java"
   },
   "phases": {
     "build": {
diff --git a/tests/snapshots/generate_plan_tests__java_maven_wrapper.snap b/tests/snapshots/generate_plan_tests__java_maven_wrapper.snap
index c323b5a..626d865 100644
--- a/tests/snapshots/generate_plan_tests__java_maven_wrapper.snap
+++ b/tests/snapshots/generate_plan_tests__java_maven_wrapper.snap
@@ -6,7 +6,7 @@ expression: plan
   "providers": [],
   "buildImage": "[build_image]",
   "variables": {
-    "NIXPACKS_METADATA": "Java"
+    "NIXPACKS_METADATA": "java"
   },
   "phases": {
     "build": {
diff --git a/tests/snapshots/generate_plan_tests__java_spring_boot.snap b/tests/snapshots/generate_plan_tests__java_spring_boot.snap
index b7455bc..536412b 100644
--- a/tests/snapshots/generate_plan_tests__java_spring_boot.snap
+++ b/tests/snapshots/generate_plan_tests__java_spring_boot.snap
@@ -6,7 +6,7 @@ expression: plan
   "providers": [],
   "buildImage": "[build_image]",
   "variables": {
-    "NIXPACKS_METADATA": "Java"
+    "NIXPACKS_METADATA": "java"
   },
   "phases": {
     "build": {
diff --git a/tests/snapshots/generate_plan_tests__ruby.snap b/tests/snapshots/generate_plan_tests__ruby.snap
index 32e5287..ee48faf 100644
--- a/tests/snapshots/generate_plan_tests__ruby.snap
+++ b/tests/snapshots/generate_plan_tests__ruby.snap
@@ -9,7 +9,7 @@ expression: plan
     "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",
-    "NIXPACKS_METADATA": "Ruby"
+    "NIXPACKS_METADATA": "ruby"
   },
   "phases": {
     "install": {
@@ -35,7 +35,7 @@ expression: plan
         "procps"
       ],
       "cmds": [
-        "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",
+        "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 && rm -rf /usr/local/rvm/src",
         "echo 'source /usr/local/rvm/scripts/rvm' >> /root/.profile"
       ],
       "onlyIncludeFiles": []
diff --git a/tests/snapshots/generate_plan_tests__ruby_execjs.snap b/tests/snapshots/generate_plan_tests__ruby_execjs.snap
index 6b2f3a5..cbcbfb4 100644
--- a/tests/snapshots/generate_plan_tests__ruby_execjs.snap
+++ b/tests/snapshots/generate_plan_tests__ruby_execjs.snap
@@ -9,7 +9,7 @@ expression: plan
     "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",
-    "NIXPACKS_METADATA": "Ruby"
+    "NIXPACKS_METADATA": "ruby"
   },
   "phases": {
     "install": {
@@ -58,7 +58,7 @@ expression: plan
         "procps"
       ],
       "cmds": [
-        "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",
+        "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 && rm -rf /usr/local/rvm/src",
         "echo 'source /usr/local/rvm/scripts/rvm' >> /root/.profile"
       ],
       "onlyIncludeFiles": []
diff --git a/tests/snapshots/generate_plan_tests__ruby_local_deps.snap b/tests/snapshots/generate_plan_tests__ruby_local_deps.snap
index a8ac2f8..efc087f 100644
--- a/tests/snapshots/generate_plan_tests__ruby_local_deps.snap
+++ b/tests/snapshots/generate_plan_tests__ruby_local_deps.snap
@@ -9,7 +9,7 @@ expression: plan
     "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",
-    "NIXPACKS_METADATA": "Ruby"
+    "NIXPACKS_METADATA": "ruby"
   },
   "phases": {
     "install": {
@@ -35,7 +35,7 @@ expression: plan
         "procps"
       ],
       "cmds": [
-        "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",
+        "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 && rm -rf /usr/local/rvm/src",
         "echo 'source /usr/local/rvm/scripts/rvm' >> /root/.profile"
       ],
       "onlyIncludeFiles": []
diff --git a/tests/snapshots/generate_plan_tests__ruby_rails_postgres.snap b/tests/snapshots/generate_plan_tests__ruby_rails_postgres.snap
index bbd5465..90360a9 100644
--- a/tests/snapshots/generate_plan_tests__ruby_rails_postgres.snap
+++ b/tests/snapshots/generate_plan_tests__ruby_rails_postgres.snap
@@ -9,7 +9,7 @@ expression: plan
     "BUNDLE_GEMFILE": "/app/Gemfile",
     "GEM_HOME": "/usr/local/rvm/gems/3.1.2",
     "GEM_PATH": "/usr/local/rvm/gems/3.1.2:/usr/local/rvm/gems/3.1.2@global",
-    "NIXPACKS_METADATA": "Ruby",
+    "NIXPACKS_METADATA": "ruby",
     "RAILS_LOG_TO_STDOUT": "enabled"
   },
   "phases": {
@@ -46,7 +46,7 @@ expression: plan
         "libpq-dev"
       ],
       "cmds": [
-        "curl -sSL https://get.rvm.io | bash -s stable && . /etc/profile.d/rvm.sh && rvm install 3.1.2 && rvm --default use 3.1.2 && gem install bundler:2.3.7",
+        "curl -sSL https://get.rvm.io | bash -s stable && . /etc/profile.d/rvm.sh && rvm install 3.1.2 && rvm --default use 3.1.2 && gem install bundler:2.3.7 && rm -rf /usr/local/rvm/src",
         "echo 'source /usr/local/rvm/scripts/rvm' >> /root/.profile"
       ],
       "onlyIncludeFiles": []
diff --git a/tests/snapshots/generate_plan_tests__ruby_sinatra.snap b/tests/snapshots/generate_plan_tests__ruby_sinatra.snap
index d2ff165..f352383 100644
--- a/tests/snapshots/generate_plan_tests__ruby_sinatra.snap
+++ b/tests/snapshots/generate_plan_tests__ruby_sinatra.snap
@@ -9,7 +9,7 @@ expression: plan
     "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",
-    "NIXPACKS_METADATA": "Ruby"
+    "NIXPACKS_METADATA": "ruby"
   },
   "phases": {
     "install": {
@@ -35,7 +35,7 @@ expression: plan
         "procps"
       ],
       "cmds": [
-        "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",
+        "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 && rm -rf /usr/local/rvm/src",
         "echo 'source /usr/local/rvm/scripts/rvm' >> /root/.profile"
       ],
       "onlyIncludeFiles": []
diff --git a/tests/snapshots/generate_plan_tests__ruby_with_node.snap b/tests/snapshots/generate_plan_tests__ruby_with_node.snap
index b09673c..0ffb7ad 100644
--- a/tests/snapshots/generate_plan_tests__ruby_with_node.snap
+++ b/tests/snapshots/generate_plan_tests__ruby_with_node.snap
@@ -9,7 +9,7 @@ expression: plan
     "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",
-    "NIXPACKS_METADATA": "Ruby"
+    "NIXPACKS_METADATA": "ruby"
   },
   "phases": {
     "install": {
@@ -61,7 +61,7 @@ expression: plan
         "procps"
       ],
       "cmds": [
-        "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",
+        "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 && rm -rf /usr/local/rvm/src",
         "echo 'source /usr/local/rvm/scripts/rvm' >> /root/.profile"
       ],
       "onlyIncludeFiles": []