Can we override the Chef default path while deploying rails app - ruby-on-rails

I am trying to deploy rails app through chef . code deployed successfully ,but bundle install throwing error for specific gems , When installed manually gem installs without any issues , as per the chef error i got to know that , to execute bundle install chef uses its embedded ruby version and path for the same , but system is installed with ruby 2.0 using rvm .Can we override the chef ruby path to system ruby path ? I am using following code to deploy ,
deploy_branch "master" do
repo repo_url
migrate false
action :deploy
branch 'master'
enable_submodules true
before_migrate do
current_release_directory = release_path
running_deploy_user = new_resource.user
bundler_depot = new_resource.shared_path + '/bundle'
excluded_groups = %w(development test)
script 'Bundling the gems' do
interpreter 'bash'
cwd current_release_directory
user running_deploy_user
code <<-EOS
bundle install --quiet --deployment --path #{bundler_depot} \
--without #{excluded_groups.join(' ')}
EOS
end
end
end

Related

Rails capistrano /usr/bin/env no file or such directory

I have a RoR application and when i try to deploy to my server via capistrano, i got this error message
/.rvm/gems/ruby-2.6.4#railsapp1/gems/sshkit-1.21.2/lib/sshkit/command.rb:97:in `exit_status=': bundle exit status: 127 (SSHKit::Command::Failed)
bundle stdout: Nothing written
bundle stderr: /usr/bin/env: bundle: No such file or directory
this is happen when capistrano run task bundler:config (below)
00:52 bundler:config
01 bundle config --local deployment true
01 /usr/bin/env: bundle
01 : No such file or directory
can anyone help me with this ? My server is using ruby virtual env instead of rvm and rbnev
Edit:
I already install bundler, but to run it i have to..let's say activate the ruby first with this script
/home/myusername/rubyvenv/staging_rails__app1/2.6/bin/activate
And i already add that script into capistrano as the first task executed, but the error is still there, is there something that i miss ?
namespace :deploy do
before 'git:wrapper', :run_on_server
end
task :run_on_server do
on roles(:app) do
execute 'source /home/myusername/rubyvenv/staging_rails__app1/2.6/bin/activate'
end
end
It seems you don't have the bundler gem installed in your server environment (which would provide the bundle executable).
You can install bundler with gem install bundler or gem install bundler -v VERSION (with VERSION being the exact version of bundler you are using to develop the app which is indicated in the last line of your Gemfile.lock.

How to use bundle with local gems during Mina deployment of Rails app?

I'm deploying a Rails app with Mina mina:deploy which clones from a git repo and Bundler installs the gems.
# /config/deploy.rb
# ...
task :deploy => :environment do
deploy do
invoke :'git:clone'
invoke :'bundle:install'
# ...
end
end
However, unlike when I bundle install manually, mina is installing each gem anew. With a healthy number of gems, this takes roughly 10 minutes to complete. How can I deploy while pointing bundler to use any locally available (already installed) gems where possible?
I've also tried replacing invoke :'bundle:install' with queue! "bundle install --local" with no change in behavior.
For that you need to use a local copy of the gems that you have without checking rubygems so after installing gems you run bundle package to create a cache of the gems used and instead of running bundle install you should run bundle install --local to use only the cached copy of gems without checking the rubygems.com .

System rvm is not working on direct call

I am using CentOS. Here is my output:
# which rvm
/usr/local/rvm/bin/rvm
# rvm ruby-1.9.3-p392#gemset
# /usr/local/rvm/bin/rvm ruby-1.9.3-p392#gemset
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for a example.
As you can see if I am using just rvm everything is working. But capistrano using full path in commands like this
[46f28bd9] Command: cd /var/www/app/releases/20140718172057 && /usr/local/rvm/bin/rvm ruby-1.9.3-p392#gemset do bundle install --binstubs /var/www/app/shared/bin --path /var/www/app/shared/bundle --without development test --deployment --verbose
So it just fails and all gems being installed on default ruby instead of ruby-1.9.3-p392#gemset
Thanks for any suggestions.
My assumptions:
you are using Capistrano v3
have already included require 'capistrano/rvm' in your Capfile
when you cd into your project directory you have something like .ruby-version and .ruby-gemset setting up RVM for you.
You might want to try something like this
within fetch(:current_path) do
with rails_env: fetch(:rails_env) do
execute :bundle, "install"
end
end
The way Tasks work in v3 is different: https://github.com/capistrano/capistrano#tasks
tl;dr: execute(:bundle, :install) and execute('bundle install') don't behave identically!

Graylog2 Web Interface (Rails) using rbenv in Chef

This is tricky as I'm using about 500 things, but I have a Vagrant box which is set up to handle what equates to 10 nodes (different servers). It's one box which locally does everything, then I split it up to different servers in production and staging.
Currently I cannot get graylog2 to use rbenv via the Chef setup. I have rbenv installed, I have bundle install running using the rbenv shims and the gems are all installed. But, the actual running application is erroring like this:
The chef recipe looks like this:
# Install required APT packages
package "build-essential"
package "postfix"
include_recipe "rbenv::default"
include_recipe "rbenv::ruby_build"
use_ruby_version = "1.9.3-p327"
rbenv_ruby use_ruby_version
# Install gem dependencies
%w{ bundler rake }.each do |g|
rbenv_gem "#{g}" do
ruby_version "#{use_ruby_version}"
end
end
# Create the release directory
directory "#{node.graylog2.basedir}/rel" do
mode 0755
recursive true
end
# Download the desired version of Graylog2 web interface from GitHub
remote_file "download_web_interface" do
path "#{node.graylog2.basedir}/rel/graylog2-web-interface-#{node.graylog2.web_interface.version}.tar.gz"
source "https://github.com/downloads/Graylog2/graylog2-web-interface/graylog2-web-interface-#{node.graylog2.web_interface.version}.tar.gz"
action :create_if_missing
end
# Unpack the desired version of Graylog2 web interface
execute "tar zxf graylog2-web-interface-#{node.graylog2.web_interface.version}.tar.gz" do
cwd "#{node.graylog2.basedir}/rel"
creates "#{node.graylog2.basedir}/rel/graylog2-web-interface-#{node.graylog2.web_interface.version}/build_date"
action :nothing
subscribes :run, resources(:remote_file => "download_web_interface"), :immediately
end
# Link to the desired Graylog2 web interface version
link "#{node.graylog2.basedir}/web" do
to "#{node.graylog2.basedir}/rel/graylog2-web-interface-#{node.graylog2.web_interface.version}"
end
# Perform bundle install on the newly-installed Graylog2 web interface version
bash "bundle install" do
cwd "#{node.graylog2.basedir}/web"
code "rbenv local #{use_ruby_version} && source /etc/profile.d/rbenv.sh && bundle install"
subscribes :run, resources(:link => "#{node.graylog2.basedir}/web"), :immediately
end
# Create mongoid.yml
template "#{node.graylog2.basedir}/web/config/mongoid.yml" do
mode 0644
end
# Create general.yml
template "#{node.graylog2.basedir}/web/config/general.yml" do
owner "nobody"
group "nogroup"
mode 0644
end
# Chown the Graylog2 directory to nobody/nogroup to allow web servers to serve it
execute "sudo chown -R nobody:nogroup graylog2-web-interface-#{node.graylog2.web_interface.version}" do
cwd "#{node.graylog2.basedir}/rel"
not_if do
File.stat("#{node.graylog2.basedir}/rel/graylog2-web-interface-#{node.graylog2.web_interface.version}").uid == 65534
end
action :nothing
subscribes :run, resources(:bash => "bundle install"), :immediately
end
# Stream message rake tasks
cron "Graylog2 send stream alarms" do
minute node[:graylog2][:stream_alarms_cron_minute]
action node[:graylog2][:send_stream_alarms] ? :create : :delete
command "cd #{node[:graylog2][:basedir]}/web && RAILS_ENV=production bundle exec rake streamalarms:send"
end
cron "Graylog2 send stream subscriptions" do
minute node[:graylog2][:stream_subscriptions_cron_minute]
action node[:graylog2][:send_stream_subscriptions] ? :create : :delete
command "cd #{node[:graylog2][:basedir]}/web && RAILS_ENV=production bundle exec rake subscriptions:send"
end
This is mostly the same as the original with the difference that it uses rbenv local in the bash "bundle install" chef resource.
So... if it's intalled, and running... how the heck do I make Rails know about said gems when it runs? Is that even the problem in the screenshot? What is happening and how do I fix it?
It's likely that the way you're starting Graylog2 doesn't properly invoke rbenv first. The easiest way to do that, as per the rbenv wiki page, is to bundle install with binstubs. So I'd change your bundle install line to look more like:
bundle install --deployment --binstubs
You didn't include the command you use to start your server. (Are you using Apache? Unicorn?) If Unicorn or Thin or some other server you can easily start on demand, your problems are nearly solved. Simply start the app through the rbenv wrapper and it should execute with the proper rbenv:
/path/to/my/current/bin/unicorn
I added the following:
LoadModule passenger_module /opt/rbenv/versions/<%= node[:graylog2][:ruby_version] %>/lib/ruby/gems/1.9.1/gems/passenger-4.0.5/libout/apache2/mod_passenger.so
PassengerRoot /opt/rbenv/versions/<%= node[:graylog2][:ruby_version] %>/lib/ruby/gems/1.9.1/gems/passenger-4.0.5
PassengerDefaultRuby /opt/rbenv/versions/<%= node[:graylog2][:ruby_version] %>/bin/ruby
I'm sending in a pull request to the graylog2 cookbook which will take care of all of this soon, and hopefully it gets accepted.

Deploying Chiliproject to Dreamhost

Having some issues deploying this. I've tried to deploy it twice now. Here's what I've done so far....
Installed the gems and versions required on the install page:
gem install -v=2.3.5 rails
gem install -v=1.0.1 rack
gem install -v=0.8.7 rake
gem install -v=0.4.2 i18n
Downloaded the package:
git clone git://github.com/chiliproject/chiliproject.git
cd chiliproject
git checkout stable
Had to find and set bundle since it wasn't in my path:
BUNDLE="/usr/lib/ruby/gems/1.8/bin/bundle"
Put my database info into database.yml:
And then started the bundle stuff:
$BUNDLE install --without=postgres rmagick
$BUNDLE exec rake generate_session_store
The last command got the error:
rake aborted!
can't activate rails (= 2.3.5, runtime), already activated rails-2.3.12. Make sure all dependencies are added to Gemfile.
So I changed 2.3.12 to 2.3.5 in the Gemfile and carried on:
RAIL_ENV=production $BUNDLE exec rake db:migrate
Then I got an error on this command too:
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
undefined method `autoload_paths' for #<Rails::Configuration:0x68a68dbb82c0>
/home/USERNAME/DOMAIN/public/config/environment.rb:44
I tried commenting out line 44 there, but then it threw another error undefined methodconvert_to_without_fallback_on_iso_8859_1' for class Class' so I didn't want to play around with it further. Note this only happened the second time I tried to deploy it. The first time I tried db:migrate succeeded (and I checked there was not data already in the DB).
*So for the second try I am stuck here :-( *
But this is what happened the first time after db:migrate succeded....
RAILS_ENV=production $BUNDLE exec rake redmine:load_default_data
With the last command however it failed saying permission denied for mysql 'user'#'173.236.128.0/255.255.128.0' and I was like WTF is it trying to connect to a network as if it were a host?
So I moved on, copied my configuration file and environment files in. Changed/added these lines:
# Uncomment below to force Rails into production mode when
# you don't control web/app server and can't set it the proper way
ENV['RAILS_ENV'] ||= 'production'
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.5'# unless defined? RAILS_GEM_VERSION
if ENV['RAILS_ENV'] == 'production' # don't bother on dev
ENV['GEM_PATH'] = '/home/USERNAME/.gems' + ':/usr/lib/ruby/gems/1.8'
end
Then made this stuff writable and restarted Passenger:
chmod -R 777 files log tmp public/plugin_assets/
touch tmp/restart.txt
Sorry for the wall of text, is anybody able to shine some light on something I've done wrong?
Thanks in advance.
EDIT: So this is all wrong, here's how I got it working
rm ~/.gem*
gem install bundler
PATH=$PATH:/usr/lib/ruby/gems/1.8/bin
cd ~
git clone git://github.com/chiliproject/chiliproject.git
cd chiliproject
git checkout stable
cp * ../example.com/ -R
cd ../example.com
# Make sure database is working
bundle install --without postgres rmagick test
bundle exec rake generate_session_store
RAILS_ENV=production bundle exec rake db:migrate
# No output is no good, check database.yml
RAILS_ENV=production bundle exec rake redmine:load_default_data
Or see this: https://gist.github.com/1127306
The current ChiliProject stable releases (2.x) require the use of bundler. Thus the answer by Slotos is incorrect here. gen install doesn't work anymore, we NEED bundler.
Also, we require Rails 2.3.12 now. You won't get any working results if you arbitrarily edit files. On certain platforms, you need to adapt the Gemfile (e.g. when using Ruby 1.8.6 or for certain versions of ImageMagick). For the currently suggested setup using Ruby 1.8.7 or REE, you don't need to adapt anything though.
For installing the dependencies of the currently stable ChiliProject 2.x releases, you basically need to do the following:
At first you need to make sure that the directory where gem binaries re installed to is in your $PATH. This can be temporarily be achieved by running this (in your case)
export PATH=/usr/lib/ruby/gems/1.8/bin:$PATH
Then you need to install the bundler gem and instruct it to install all dependencies
gem install bundler
bundle install --without rmagick postgres test # in your case
What is really strange in your case is that rake seems to try to enable Rails 2.3.5. It should not do that (and doesn't unless you have changed certain files). I strongly recommend to start with a new clean source tree and don't change any arbitrary files.
Don't mix up gem install commands with bundler package management. You will get unexpected results from doing so.
If you really want to use bundler - add all the gems you want into a Gemfile.
Otherwise just omit it.
Quick search for "bundler chiliproject" lead me to chiliproject-gemfile. Apparently it have been merged into unstable already.

Resources