In RubyMine I am able to select the target Ruby version for project and run it.
Now about a production.
We have two variants to build a host for Rails apps:
Apache + Phusion Passenger
Nginx + Unicorn
How to run on each of these configurations two Rails applications built for different Ruby versions?
Requirements: both apps should run on the same server, on different virtual hosts.
RVM is installed.
An easy way to select a different Ruby version when deploying apps is by using Capistrano for deployment. After capifying your application it is time to add some lines to your Capfile
Your Capfile should look something like this
require 'capistrano/setup'
# Include default deployment tasks
require 'capistrano/deploy'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/rvm'
This way you load special RVM options into Capistrano so you can specify the ruby version to use.
To specify a specific Ruby version to use, you can add a line to your deploy.rb for a system wide deployment option or to your production.rb or staging.rb if you want different ruby version per server.
By adding the following line you can specify your desired Ruby version:
set :rvm_ruby_version, '2.0.0-p247'
After you have deployed your application you still have to specify which ruby version Passenger will use. You can specify this by editing the apache config file specific to your site or subdomain. When editing your Apache config file.
<VirtualHost *:80>
PassengerRuby /home/someuser/.rvm/wrappers/<ruby-version-here>/ruby
******
</VirtualHost>
You can see which ruby version you need by first executing rvm use <ruby version> and then executing which ruby which should give you the path to enter in your VirtualHost file.
Hope that works for you
Related
I have a project in jRuby that I try to run.
So I'm installling jruby using rvm like this
rvm install jruby-9.1.15.0 (bc thats the version required by the project)
then im making sure that im actually using jruby by typing
ruby -v which shows me that I have jruby
next thing, I want to run the rails server so I'm typing
bundle exec rails server
and unfortunately I get an error:
/Users/foouser/Documents/Projects/fooproject/bin/config/application
LoadError: no such file to load -- /Users/foouser/Documents/Projects/fooproject/bin/config/application
require at org/jruby/RubyKernel.java:955
block in server at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:78
tap at org/jruby/RubyKernel.java:1741
server at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:75
run_command! at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:39
<main> at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands.rb:17
require at org/jruby/RubyKernel.java:955
<main> at bin/rails:5
I've tried googling that but to no avail. People seem to not encounter this issue at all. I'm sure it's got something to do with my setup because other people are successfully using said project.
Any ideas?
rails version - 4.2
jruby version - 9.1.15.0
EDIT:
after some digging, in bin/rails file the line defining the APP_PATH was like that:
APP_PATH = File.expand_path('../config/application', __FILE__)
which somehow made it looking for application.rb inside fooproject/bin/config instead of fooproject/config
but when I changed the line to
APP_PATH = File.expand_path('../../config/application', __FILE__)
it goes to the correct path where application.rb exist but still reports it as not existing.
the error is nearly the same (apart for path)
LoadError: no such file to load -- /Users/foouser/Documents/Projects/fooproject/config/application
require at org/jruby/RubyKernel.java:955
block in server at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:78
tap at org/jruby/RubyKernel.java:1741
server at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:75
run_command! at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands/commands_tasks.rb:39
<main> at /Users/foouser/.rvm/gems/jruby-9.1.15.0-jrubu/gems/railties-4.2.10/lib/rails/commands.rb:17
require at org/jruby/RubyKernel.java:955
<main> at bin/rails:4
EDIT 2:
requested permissions for application.rb:
-rw-r--r-- 1 foouser staff 5818 20 Jun 15:12 config/application.rb
config.ru:
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run Rails.application
environment.rb
# Load the Rails application.
require File.expand_path('../application', __FILE__)
# Initialize the Rails application.
Rails.application.initialize!
So, the solution I have is the "have you tried to turn it off and on again?" type.
I have deleted the whole project and cloned it again from the repo.
Everything is working now, it must have been something with my local env but I can't tell what.
Anyway, if you ever encounter something similar - purge and clone is definitely something you can try.
I use rvm for development. In order to create a new Rails project directory initially, I will install the full Rails stack of gems in my default gemset so I can run "rails new". I then will create the ".ruby-version" and ".ruby-gemset" files in the new project directory so rvm can automatically switch me the proper ruby version and gemset when navigating into the project. I then have to install the full Rails stack again in the project's gemset. So I never really end up using my Rails stack installed in my default gemset (except to run "rails new").
So is there a subset of the Rails gems which I can install just to run the equivalent of "rails new" to generate the new project? Is there something else I can use to do the same, but is technically outside of Rails?
I don't know how to specify when creating the rails project which portions of the Rails stack to include/exclude, but once it's installed you can choose which portions to not import into your application by modifying your application.rb file.
Your application.rb file contains the following code:
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/engine"
require "sprockets/railtie"
require "dotenv-rails"
Simply comment out the frameworks you don't want to include in your running application and they won't be imported.
Not sure if this is what you're looking for or not, hope it helps though.
I trying to deploy rails app through capistrano. All assets (css, js and images) build by webpacker. I removed app/assets folder and now deploy failed when capistrano trying to backup manifest. This task running always https://github.com/capistrano/rails/blob/master/lib/capistrano/tasks/assets.rake
If I enable sprockets require "sprockets/railtie" everything is fine.
As explained in the capistrano-rails README, if you don't use the asset pipeline, then exclude capistrano/rails/assets from your Capfile. In other words:
# Instead of this:
require "capistrano/rails"
# Require only these:
require "capistrano/bundler"
require "capistrano/rails/migrations"
However, if you are using Webpacker, then there is a good chance that you still need to run asset-pipeline tasks. Notably, you still probably need to run assets:precompile during deployment, in order to trigger the webpack build.
In this case, you would need a more precise exclusion of the backup_manifest task. Following the instructions in the official Capistrano docs, you can clear the default implementation as follows:
# In deploy.rb
Rake::Task["deploy:assets:backup_manifest"].clear_actions
I have installed Capistrano 3 and I'm not able to get my app to call bundle install and precompile my assets on deploy.
I've seen that I have to configure my environment for RVM there http://rvm.io/deployment/capistrano#environment
But I was wondering, I have a dev computer A, and a deployment computer B, which both have RVM user-installed.
Should I configure Capistrano to use RVM on my dev computer or on the deployment computer?
Does your Capfile have the following?
require 'capistrano/rails'
require 'capistrano/rvm'
capistrano/rails includes dependencies for bundler, assets and migrations.
https://github.com/capistrano/rails/blob/master/lib/capistrano/rails.rb
https://github.com/capistrano/rvm
Also make sure to read the readme on capistrano/rvm, as you need to have the correct capistrano/bundler version.
Working to get RVM working with Capistrano and Rails 3.1rc5 and confused by the instructions I found.
RVM's website provides these instructions that say:
In the new option, you can do the following (adjust to your personal setup):
$:.unshift(File.expand_path('./lib', ENV['rvm_path'])) # Add RVM's lib directory to the load path.
require "rvm/capistrano" # Load RVM's capistrano plugin.
set :rvm_ruby_string, 'ree#rails3' # Or whatever env you want it to run in.
Now I assume they want this at the top of our deploy.rb file!?! I only ask because I've not seen a "$:." in the, albeit few, deploy.rb's that I've seen.
What does the line starting with "$:." do exactly? And does it belong in deploy.rb or somewhere else?
$: is a special Ruby variable that is equivalent to $LOAD_PATH, which is the path that Ruby searches whenever you use a require statement. Calling .unshift(...) on it adds the provided path to the front of the load path.
If you just called require 'rvm/capistrano' without the $:.unshift statement, you would get an error, because by default, RVM's Capistrano library is not in Ruby's load path. The reason you haven't seen this in other deploy.rb files is because typically, the only libraries that are needed are Capistrano's, which are already included by running cap deploy (or any of the other cap commands).
My deploy.rb files have this exact same code in them and it works great.
I believe this needs to be at the top level, so that it gets set before any calls--i.e. before bundle, any rake tasks, etc. This has been problematic for me. In my case, my web and app servers are not the same, and I do not want rvm on the web server.
It also seems a little black magic, when the real solution is rather easy. After updating your code, set up a blessed gemset in an .rvmrc file, and nothing else needs to be done.
after "deploy:update_code", "deploy:rvm:setup"
namespace :deploy do
namespace :rvm do
# Set up .rvmrc
# Note, not using method described in:
# https://rvm.beginrescueend.com/integration/capistrano/
# We want to use RVM only on the app server, so better to set up and bless an .rvmrc file
task :setup, :roles => :app do
run "cd #{latest_release}; rvm use 1.9.2##{application} --rvmrc --create && rvm rvmrc trust"
end
end
end