Skip to content

Commit

Permalink
Support installing Ruby local deps (#477)
Browse files Browse the repository at this point in the history
* don't have any file deps for ruby to support installing local deps

* update snapshot tests

* ruby local deps test

* add ruby local snapshot test

* fix ruby local deps procfile

* update snapshot tests
  • Loading branch information
coffee-cup authored Aug 30, 2022
1 parent bf8edfe commit 41ea665
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 14 deletions.
3 changes: 3 additions & 0 deletions examples/ruby-local-deps/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'https://rubygems.org'

gem "local", path: "libs/local"
20 changes: 20 additions & 0 deletions examples/ruby-local-deps/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions examples/ruby-local-deps/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: bundle exec ruby app.rb
3 changes: 3 additions & 0 deletions examples/ruby-local-deps/app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require "local"

Local.hi
4 changes: 4 additions & 0 deletions examples/ruby-local-deps/libs/local/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gemspec
5 changes: 5 additions & 0 deletions examples/ruby-local-deps/libs/local/lib/local.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Local
def self.hi
puts "Hello world from Local lib"
end
end
11 changes: 11 additions & 0 deletions examples/ruby-local-deps/libs/local/local.gemspec
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion examples/ruby-with-node/app.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
puts "Hello from Ruby"
puts "Hello from Ruby with Node"
1 change: 0 additions & 1 deletion src/providers/ruby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
14 changes: 14 additions & 0 deletions tests/docker_run_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions tests/snapshots/generate_plan_tests__ruby.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ expression: plan
"commands": [
"bundle install"
],
"onlyIncludeFiles": [
"Gemfile*"
],
"cacheDirectories": [
"/root/.bundle/cache"
],
Expand Down
54 changes: 54 additions & 0 deletions tests/snapshots/generate_plan_tests__ruby_local_deps.snap
Original file line number Diff line number Diff line change
@@ -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"
}
}
3 changes: 0 additions & 3 deletions tests/snapshots/generate_plan_tests__ruby_rails_postgres.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ expression: plan
"commands": [
"bundle install"
],
"onlyIncludeFiles": [
"Gemfile*"
],
"cacheDirectories": [
"/root/.bundle/cache"
],
Expand Down
3 changes: 0 additions & 3 deletions tests/snapshots/generate_plan_tests__ruby_sinatra.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ expression: plan
"commands": [
"bundle install"
],
"onlyIncludeFiles": [
"Gemfile*"
],
"cacheDirectories": [
"/root/.bundle/cache"
],
Expand Down
3 changes: 0 additions & 3 deletions tests/snapshots/generate_plan_tests__ruby_with_node.snap
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ expression: plan
"commands": [
"bundle install"
],
"onlyIncludeFiles": [
"Gemfile*"
],
"cacheDirectories": [
"/root/.bundle/cache"
],
Expand Down

0 comments on commit 41ea665

Please sign in to comment.