Capistrano Production Deploy -> rbenv - ruby-on-rails

I think I have set up Capistrano3 correctly on my machine and that it should be connecting to my server. When I run cap production deploy (on my machine) I receive the following error messenger:
DEBUG [2959f403] Running /usr/bin/env [ -d ~/.rbenv/versions/2.1.2 ] as [user#myIP]
DEBUG [2959f403] Command: [ -d ~/.rbenv/versions/2.1.2 ]
DEBUG [2959f403] Finished in 0.420 seconds with exit status 1 (failed).
ERROR rbenv: 2.1.2 is not installed or not found in ~/.rbenv/versions/2.1.2
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as [user#myIP]: exit
SystemExit: exit
Tasks: TOP => rbenv:validate
(See full trace by running task with --trace)
On my machine (iMac):
$ ruby -v
ruby 2.1.2p95
$ rbenv -v
rbenv 0.4.0
$ which rebind
/usr/local/bin/rbenv
On my server (ubuntu)
$ ruby -v
ruby 2.1.2p95
$ rbenv -v
rbenv 0.4.0-151-g83ac0fb
$ which rebind
/home/[user]/.rbenv/bin/rbenv
Any ideas how to fix this?
** More Info From Comments **
deploy.rb
# config valid only for current version of Capistrano
lock '3.4.0'
set :application, [app name]
set :repo_url, [repo location]
set :repository, [repo location]
set :scm, :git
set :deploy_user, [user]
set :user, [user]
set :use_sudo, false
set :rails_env, "production"
set :deploy_via, :copy
# setup rvm.
# how many old releases do we want to keep
set :keep_releases, 5
# files we want symlinking to specific entries in shared.
set :linked_files, %w{config/database.yml config/application.yml}
# dirs we want symlinking to shared
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
# what specs should be run before deployment is allowed to
# continue, see lib/capistrano/tasks/run_tests.cap
set :tests, []
# which config files should be copied by deploy:setup_config
# see documentation in lib/capistrano/tasks/setup_config.cap
# for details of operations
set(:config_files, %w(
nginx.conf
database.example.yml
log_rotation
monit
unicorn.rb
unicorn_init.sh
))
# which config files should be made executable after copying
# by deploy:setup_config
set(:executable_config_files, %w(
unicorn_init.sh
))
# files which need to be symlinked to other parts of the
# filesystem. For example nginx virtualhosts, log rotation
# init scripts etc.
set(:symlinks, [
{
source: "nginx.conf",
link: "/etc/nginx/sites-enabled/#{fetch(:full_app_name)}"
},
{
source: "unicorn_init.sh",
link: "/etc/init.d/unicorn_#{fetch(:full_app_name)}"
},
{
source: "log_rotation",
link: "/etc/logrotate.d/#{fetch(:full_app_name)}"
},
{
source: "monit",
link: "/etc/monit/conf.d/#{fetch(:full_app_name)}.conf"
}
])
namespace :deploy do
# make sure we're deploying what we think we're deploying
before :deploy, "deploy:check_revision"
# only allow a deploy with passing tests to deployed
before :deploy, "deploy:run_tests"
# compile assets locally then rsync
after :finishing, 'deploy:cleanup'
after 'deploy:publishing', 'deploy:restart'
end
Server
$ ls /home/[user]/.rbenv/versions/
[blank... ]
$

If /home/[user]/.rbenv/versions is an empty directory on the server, then you have no versions of ruby installed.
Try running rbenv install 2.1.2 on the server. You may need to install the ruby-build plugin first.

Related

Capistrano 3 deployment broke for some reason

Okay,
I'm running into some weird issue with our deployment no longer working anymore. I cannot track everything that changed, but I'm hoping someone can help me out with debugging this issue and find out what is going wrong.
deploy.rb
# config valid only for current version of Capistrano
lock '3.4.0'
set :application, 'app_name'
set :repo_url, 'github_url'
set :deploy_to, '/home/user/path'
# Source Control Configuration
set :scm, :git
# Produces: Please enter the name of the branch. (develop):
set(:branch, ask('the name of the branch.', 'develop'))
# Ask whether we want to perform a backup.
# Produces: Please enter whether to perform a backup of the database? (Y):
set(:backup, ask('whether to perform a backup of the database?', 'Y'))
puts("setting branch to: #{fetch(:branch)}")
set :user, 'my_user'
set :assets_roles, [:web, :app, :vm]
set :keep_assets, 2
set :linked_files, fetch(:linked_files, []).push('.chamber.pem', 'Procfile', '.env')
set :linked_dirs, fetch(:linked_dirs, []).push('data', 'tmp', 'log', 'uploads')
set :keep_releases, 10
set :bundle_path, nil
set :bundle_binstubs, nil
set :bundle_flags, '--system'
set :rvm1_map_bins, fetch(:rvm1_map_bins, []).push('honeybadger')
# Slack integration options
set :slack_via_slackbot, Settings.slack.via_slackbot
set :slack_team, Settings.slack.team
set :slack_token, Settings.slack.token
set :slack_icon_emoji, -> { Settings.slack.icon_emoji }
set :slack_channel, -> { Settings.slack.channel }
set :slack_username, -> { Settings.slack.username }
set :slack_run_starting, -> { Settings.slack.run_starting }
set :slack_run_finished, -> { Settings.slack.run_finished }
set :slack_run_failed, -> { Settings.slack.run_failed }
set :slack_msg_finished, -> { "#channel #{ENV['USER'] || ENV['USERNAME']} has deployed branch *#{fetch :branch}* of #{fetch :application} to *#{fetch :rails_env}*." }
set :slack_msg_failed, -> { "#{ENV['USER'] || ENV['USERNAME']} failed to deploy branch #{fetch :branch} of #{fetch :application} to #{fetch :rails_env, 'production'}." }
# Rake config
SSHKit.config.command_map[:rake] = 'bundle exec rake'
before 'deploy:started', 'deploy:rm:stop'
after 'deploy:rm:stop', 'deploy:rm:backup'
after 'deploy:finished', 'deploy:rm:start'
after 'deploy:migrate', 'deploy:rm:seed
Capfile
# Load DSL and set up stages
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'rvm1/capistrano3' # Do not use capistrano/bundler
require 'whenever/capistrano'
require 'capistrano/honeybadger'
require 'slackistrano/capistrano'
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
require 'net/ssh/proxy/command'
def vm(tunnel:, tunnel_user: fetch(:user), vm_user: fetch(:user))
server "#{fetch(:stage)}-vm01", {
roles: [:vm],
# The user on the VM
user: vm_user,
ssh_options: {
# The user on the machine we're tunneling through
proxy: Net::SSH::Proxy::Command.new("ssh #{tunnel_user}##{tunnel} -W %h:%p"),
}
}
end
So I can run the cap command locally, and it does part of the work. Had some issues first with the new sprockets, but now it's complaining about the following when it needs to precompile the assets:
INFO [21eca199] Running bundle exec rake assets:precompile as riskmethods#playground.riskmethods.net DEBUG [21eca199] Command: cd /home/riskmethods/riskmethods/releases/20160212152030 && ( export RAILS_ENV="playground" ; bundle exec rake assets:precompile )
DEBUG [2eac7a5b] Finished in 0.078 seconds with exit status 0 (successful).
INFO [4b29f0c4] Running bundle exec rake assets:precompile as riskmethods#playground-vm01
DEBUG [4b29f0c4] Command: cd /home/riskmethods/riskmethods/releases/20160212152030 && ( export RAILS_ENV="playground" ; bundle exec rake assets:precompile )
DEBUG [21eca199] bash: bundle: command not found
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as riskmethods#playground.riskmethods.net: rake exit status: 127
rake stdout: Nothing written
rake stderr: bash: bundle: command not found
SSHKit::Command::Failed:
rake exit status: 127
rake stdout: Nothing written
rake stderr: bash: bundle: command not found
Tasks: TOP => deploy:assets:precompile
(See full trace by running task with --trace)
The deploy has failed with an error:
Exception while executing as riskmethods#playground.riskmethods.net:
rake exit status: 127
rake stdout: Nothing written
rake stderr: bash: bundle: command not found
DEBUG [4b29f0c4] bash: bundle: command not found
As your error message saying bash: bundle: command not found
It seems you dont have the gem bundler installed on the server
install bundler gem on server by running the following command that should do the trick
gem install bundler

Rails 4 + Capistrano 3 - Deploy to Production Server from Local Repo

I'm using Windows 10 and Cygwin, and I am setting up Capistrano 3 for deployment to my production environment. I believe I have everything set up correctly, but I can't figure out how to push my local repo to my production server. I don't have my repo on GitHub or another such site and would like to keep it local. I receive the following error message when I run cap production deploy.
SSHKit::Runner::ExecuteError: Exception while executing as
myappuser#myappname.website.com: git exit status: 128 git stdout:
Nothing written git stderr: fatal: No remote configured to list refs
from.
SSHKit::Command::Failed: git exit status: 128 git stdout: Nothing
written git stderr: fatal: No remote configured to list refs from.
Tasks: TOP => git:check (See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as
myappuser#myappname.website.com: git exit status : 128 git stdout:
Nothing written git stderr: fatal: No remote configured to list refs
from.
Here's my config\deploy.rb file:
# config valid only for current version of Capistrano
lock '3.4.0'
set :application, 'myappname
set :deploy_user, 'myappuser'
set :repo_url, "file:///C:/Users/me/Documents/repo/myappname.git"
# setup rvm.
set :rbenv_type, :user
set :rbenv_ruby, '2.1.5-p273'
set :rbenv_prefix, "RBENV_ROOT=#{fetch(:rbenv_path)} RBENV_VERSION=#{fetch(:rbenv_ruby)} #{fetch(:rbenv_path)}/bin/rbenv exec"
set :rbenv_map_bins, %w{rake gem bundle ruby rails}
set :assets_roles, [:app]
# Default value for :scm is :git
set :scm, :git
# Default value for :linked_files is []
set :linked_files, %w{config/database.yml config/application.yml}
# Default value for linked_dirs is []
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
# Default value for keep_releases is 5
set :keep_releases, 5
# which config files should be copied by deploy:setup_config
# see documentation in lib/capistrano/tasks/setup_config.cap
# for details of operations
set(:config_files, %w(
nginx.conf
application.yml
database.yml
unicorn.rb
unicorn_init.sh
))
# which config files should be made executable after copying
# by deploy:setup_config
set(:executable_config_files, %w(
unicorn_init.sh
))
# files which need to be symlinked to other parts of the
# filesystem. For example nginx virtualhosts, log rotation
# init scripts etc. The full_app_name variable isn't
# available at this point so we use a custom template {{}}
# tag and then add it at run time.
set(:symlinks, [
{
source: "nginx.conf",
link: "/etc/nginx/sites-enabled/{{full_app_name}}"
},
{
source: "unicorn_init.sh",
link: "/etc/init.d/unicorn_{{full_app_name}}"
},
{
source: "log_rotation",
link: "/etc/logrotate.d/{{full_app_name}}"
}
])
namespace :deploy do
# compile assets locally then rsync
after :finishing, 'deploy:cleanup'
end
All of the answers I found didn't have a solution or were for Capistrano 2, so I am wondering if the options have changed. Any help would be greatly appreciated!
EDIT
I've made some progress, but it's still not reading my local repo. Here's the error message:
SSHKit::Command::Failed: git exit status: 128 git stdout: Nothing
written git stderr: fatal: '/C:/Users/me/Documents/repo/myappname.git'
does not appear to be a git repository fatal: Could not read from
remote repository.
Please make sure you have the correct access rights and the repository
exists.
I've tried all different path combinations for my repo. My git repo is at the following path: C:/Users/me/Documents/repo/myappname. Is there a specific way to reference my local repo?
Unfortunately, this is not how Capistrano is designed to work. The basic assumption Capistrano makes is that your project resides in a repository that the server can access (almost always this is a Git repo hosted at e.g. Bitbucket or GitHub).
Capistrano pulls your source code by running git commands on the server. The server has no way to see your local repository, which is why it doesn't work.
There are some plugins that try to change Capistrano's behavior to allow for the push style deployment you are looking for. Search GitHub for "capistrano copy" and try them out. This one could be what you're looking for:
https://github.com/ydkn/capistrano-git-copy
I have been using capistrano-scm-copy to do my deploys via SCP upload from my dev box to AWS. Note of caution - this is like running with scissors. It's nice to be able to do a quick hotfix deploy, verily it in production and the do git commit. But you need to be really careful to not forget the commit part.

How to properly set up Capistrano 3 with Rails 4?

It's 2 days what I am trying to install Capistrano 3 for a Rails 4 app, my hairs already turned grey...
The problem is that I am unable to deploy the code to server (Ubuntu 14, nginx, running on DigitalOcean).
Here's my config:
Gemfile:
gem 'capistrano', '~> 3.1.0'
gem 'capistrano-rails', '~> 1.1.0'
gem 'capistrano-bundler'
gem 'unicorn'
Capfile:
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
# Load custom tasks from `lib/capistrano/tasks' if you have any defined
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
Dir.glob('lib/capistrano/**/*.rb').each { |r| import r }
deploy.rb:
set :application, 'project'
set :deploy_user, 'deployer'
set :scm, :git
set :repo_url, 'git#bitbucket.org:username/project.git"'
set :pty, true
set :use_sudo, false
set :keep_releases, 5
set :linked_files, %w{config/database.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
set(:symlinks, [
{
source: "nginx.conf",
link: "/etc/nginx/sites-enabled/#{fetch(:full_app_name)}"
},
{
source: "unicorn_init.sh",
link: "/etc/init.d/unicorn_#{fetch(:full_app_name)}"
},
{
source: "log_rotation",
link: "/etc/logrotate.d/#{fetch(:full_app_name)}"
},
{
source: "monit",
link: "/etc/monit/conf.d/#{fetch(:full_app_name)}.conf"
}
])
namespace :deploy do
before :deploy, "deploy:check_revision"
before :deploy, "deploy:run_tests"
#after 'deploy:symlink:shared', 'deploy:compile_assets_locally'
after :finishing, 'deploy:cleanup'
before 'deploy:setup_config', 'nginx:remove_default_vhost'
after 'deploy:setup_config', 'nginx:reload'
after 'deploy:setup_config', 'monit:restart'
after 'deploy:publishing', 'deploy:restart'
end
and config/deploy/production.rb:
set :stage, :production
set :branch, "master"
set :full_app_name, "#{fetch(:application)}_#{fetch(:stage)}"
set :server_name, "IP"
server 'IP', user: 'deployer', roles: %w{web app db}, primary: true
set :deploy_to, "/home/#{fetch(:deploy_user)}/apps/#{fetch(:full_app_name)}"
set :rails_env, :production
set :unicorn_worker_count, 5
set :enable_ssl, false
When I am trying to set up capistrano and run cap production deploy:setup_config, I get this output:
/Users/adam/.rvm/gems/ruby-2.0.0-p481/gems/bundler-1.6.5/lib/bundler.rb:301: warning: Insecure world writable dir /usr/local/mysql-5.6.13-osx10.7-x86_64 in PATH, mode 040777
DEBUG [d940e414] Running /usr/bin/env [ -f /etc/nginx/sites-enabled/default ] as deployer#IP
DEBUG [d940e414] Command: [ -f /etc/nginx/sites-enabled/default ]
Text will be echoed in the clear. Please install the HighLine or Termios libraries to suppress echoed text.
deployer#188.166.53.247's password: # HERE I PUT MY PASSWORD, BUT WHEN I TYPE IT, I SEE WHAT I TYPE (THE PASSWORD IS NOT HIDDEN)
DEBUG [d940e414] Finished in 28.324 seconds with exit status 0 (successful).
INFO [cba64b02] Running /usr/bin/env sudo rm /etc/nginx/sites-enabled/default as deployer#IP
DEBUG [cba64b02] Command: /usr/bin/env sudo rm /etc/nginx/sites-enabled/default
DEBUG [cba64b02] [sudo] password for deployer:
And here it stuck - nothing happened. No matter what I do (if I type something/password) -- it stuck here for over 30 minutes.
Could I ask you to help me out with this issue, guys?
Thank you very much in advance, I am not sure how to continue here.
It appears the nginx:remove_default_vhost task you have configured to run before deploy:setup_config is trying to execute rm with sudo. Capistrano 3 requires passwordless sudo to be setup, otherwise you get the symptom you have described. See the authorization section of the documentation.
Setting up the deployer user to execute rm with sudo without a password should get things moving, but before you do that I think it's worth asking: do you really want your deployer user to be able to remove arbitrary files as root without a password? It's not clear to me what the origin of that task is, but IMHO that is more a part of privisioning than of deployment and there are other tools more suited for provisioning than capistrano (chef, puppet, etc.). Or just SSH to your server and remove it. It only needs to be done once.
If you do decide to let your deployer user execute rm with sudo without a password, remember to use visudo and do not edit /etc/sudoers directly.

capistrano not using rails environment with bundler properly

I'm trying to set up Capistrano deployment for the first time and I wanted to test it on my development directory before attempting it on production. Normally I wouldn't even bother with Capistrano in the dev environment, but I'm having issues when deploying. It seems that Capistrano wants to:
A) run the bundle command: bundle --without development test
and
B) run rake assets:precompile in the development environment. I don't want that. Why would I? Maybe in the 'staging' environment if I ever wanted to do that, but certainly not in development mode.
The biggest hurdle at the moment is the fact that it bundles thinking it's in production mode and thus skips over gems which are required when it DOES correctly use the development environment when precompiling assets.
EDIT: Here's a sample of two scripts which are run - the first scripts run bundler as if we're in the production environment, and the last runs it in development environment (RAILS_ENV=development). We of course get the error because BetterErrors is a gem that's loaded only in the development environment and so it can't find BetterErrors because the call to bundle was in the production environment.
INFO [9797fc64] Running ~/.rvm/bin/rvm default do bundle install --binstubs /home/vps_user/rails_deployments/dev.www/shared/bin --path /home/vps_user/rails_deployments/dev.www/shared/bundle --without development test --deployment --quiet on localhost
DEBUG [9797fc64] Command: cd /home/vps_user/rails_deployments/dev.www/releases/20140217224858 && ~/.rvm/bin/rvm default do bundle install --binstubs /home/vps_user/rails_deployments/dev.www/shared/bin --path /home/vps_user/rails_deployments/dev.www/shared/bundle --without development test --deployment --quiet
INFO [9797fc64] Finished in 1.883 seconds with exit status 0 (successful).
DEBUG [da905ff7] Running /usr/bin/env if test ! -d /home/vps_user/rails_deployments/dev.www/releases/20140217224858; then echo "Directory does not exist '/home/vps_user/rails_deployments/dev.www/releases/20140217224858'" 1>&2; false; fi on localhost
DEBUG [da905ff7] Command: if test ! -d /home/sprvps_userucewo/rails_deployments/dev.www/releases/20140217224858; then echo "Directory does not exist '/home/vps_user/rails_deployments/dev.www/releases/20140217224858'" 1>&2; false; fi
DEBUG [da905ff7] Finished in 0.044 seconds with exit status 0 (successful).
INFO [0562438c] Running ~/.rvm/bin/rvm default do bundle exec rake assets:precompile on localhost
DEBUG [0562438c] Command: cd /home/vps_user/rails_deployments/dev.www/releases/20140217224858 && ( RAILS_ENV=development ~/.rvm/bin/rvm default do bundle exec rake assets:precompile )
DEBUG [0562438c] rake aborted!
DEBUG [0562438c] uninitialized constant BetterErrors
Is there something wrong with my setup? I'm using Capistrano v3+, with Ruby v2.1.0 inside rvm.
Gemfile:
if RUBY_PLATFORM !~ /mingw/
gem 'capistrano-rails'
gem 'capistrano-rvm'
gem 'capistrano-bundler'
end
Capfile:
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
require 'capistrano/rails'
require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
# require 'capistrano/rails/assets'
# require 'capistrano/rails/migrations'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
deploy.rb:
# config valid only for Capistrano 3.1
lock '3.1.0'
set :application, 'website'
set :repo_url, 'git#bitbucket.org:MyUserName/website.git'
set :user, 'vps_user'
set :tmp_dir, '/home/vps_user/tmp'
# Default value for keep_releases is 5
set :keep_releases, 3
SSHKit.config.command_map[:rake] = "bundle exec rake"
SSHKit.config.command_map[:rails] = "bundle exec rails"
# Common directories (usually assets)
set :linked_dirs, %w{ public/assets/emails public/assets/events public/assets/photographs public/assets/updates public/assets/video public/assets/wines }
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Your restart mechanism here, for example:
execute :touch, release_path.join('tmp/restart.txt')
end
end
after :publishing, :restart
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
end
deploy/development.rb
set :branch, :develop
set :stage, :development
set :rails_env, 'development'
set :deploy_to, '/home/vps_user/rails_deployments/dev.www'
server 'localhost', user: 'vps_user', roles: %w{web app}
deploy/production.rb
set :branch, :master
set :stage, :production
set :rails_env, 'production'
set :deploy_to, '/home/vps_user/rails_deployments/www'
server 'localhost', user: 'vps_user', roles: %w{web app}
And I run the deploy command as such: bundle exec cap development deploy
OK so looking at Capistrano::Bundler under 'Usage' I saw an option in there called :bundle_without and it looked promising. So I put set :bundle_without, 'production' inside of my development.rb deploy script and it worked!
This doesn't solve the issue that Capistrano keeps trying to generate precompiled assets but I'm sure there's a solution out there like overriding the rake task or something.

Deploying with RVM on Linode Ubuntu 10.4 Does not install RVM

I'm trying to deploy with Capistrano and RVM and even though when running cap bundler:install_bundler which is supposed to install bundler, and succeeds. After, when running cap deploy it fails with an error that bundler is not installed.
** [out :: victorstan.com] ERROR: Gem bundler is not installed, run `gem install bundler` first.
Any ideas why it installs bundler, but then can't find it, or installs it in the wrong place (i guess?). Thanks!
here is part of my deploy.rb script:
set :application, "dinner"
set :domain, "victorstan.com"
set :repository, "ssh://#{domain}/~/#{application}.git"
set :use_sudo, false
set :user, "victorstan" # The server's user for deploys
set :scm, :git
set :scm_username, "passenger"
set :deploy_to, "/srv/www/#{application}"
set :keep_releases, 2
set :branch, "master"
set :deploy_via, :copy # won't make cap prompt for password when deploying
set :scm_verbose, true
set :rvm_ruby_string, 'ruby-2.0.0-p195#dinner'
set :rvm_type, :user
set :rvm_install_type, :stable
set :whenever_command, "bundle exec whenever"
require "bundler/capistrano"
require "rvm/capistrano"
require "whenever/capistrano"
If I try to use cap to install bundler, it works:
cap bundler:install_bundler
* 2013-06-08 15:33:54 executing `bundler:install_bundler'
* executing "gem install bundler"
servers: ["victorstan.com"]
[victorstan.com] executing command
** [out :: victorstan.com] Successfully installed bundler-1.3.5
** [out :: victorstan.com] 1 gem installed
command finished in 1373ms
And here is the output when running cap deploy:
Switched to a new branch 'deploy'
command finished in 984ms
* Compressing /var/folders/w4/_6g_9lqd491_6cmhzb0kcmzh0000gn/T/20130608192600 to /var/folders/w4/_6g_9lqd491_6cmhzb0kcmzh0000gn/T/20130608192600.tar.gz
executing locally: tar czf 20130608192600.tar.gz 20130608192600
command finished in 53ms
servers: ["victorstan.com"]
** sftp upload /var/folders/w4/_6g_9lqd491_6cmhzb0kcmzh0000gn/T/20130608192600.tar.gz -> /tmp/20130608192600.tar.gz
[victorstan.com] /tmp/20130608192600.tar.gz
[victorstan.com] done
* sftp upload complete
* executing "cd /srv/www/dinner/releases && tar xzf /tmp/20130608192600.tar.gz && rm /tmp/20130608192600.tar.gz"
servers: ["victorstan.com"]
[victorstan.com] executing command
command finished in 467ms
* 2013-06-08 15:26:05 executing `deploy:finalize_update'
triggering before callbacks for `deploy:finalize_update'
* 2013-06-08 15:26:05 executing `bundle:install'
* executing "cd /srv/www/dinner/releases/20130608192600 && bundle install --gemfile /srv/www/dinner/releases/20130608192600/Gemfile --path /srv/www/dinner/shared/bundle --deployment --quiet --without development test"
servers: ["victorstan.com"]
[victorstan.com] executing command
** [out :: victorstan.com] ERROR: Gem bundler is not installed, run `gem install bundler` first.
command finished in 598ms
*** [deploy:update_code] rolling back
* executing "rm -rf /srv/www/dinner/releases/20130608192600; true"
servers: ["victorstan.com"]
[victorstan.com] executing command
command finished in 513ms
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell 'ruby-2.0.0-p195#dinner' -c 'cd /srv/www/dinner/releases/20130608192600 && bundle install --gemfile /srv/www/dinner/releases/20130608192600/Gemfile --path /srv/www/dinner/shared/bundle --deployment --quiet --without development test'" on victorstan.com
is ruby-2.0.0-p195#dinner installed / created on the server?
you can ensure it is with adding:
before 'deploy:setup', 'rvm:install_ruby'
more details on using rvm-capistrano can be found here: https://github.com/wayneeseguin/rvm-capistrano#readme
I have read some more examples on setting up deploy script and i've re-arranged the order of elements of my deploy script, as well as ena
set :application, "dinner"
set :domain, "victorstan.com"
set :repository, "ssh://#{domain}/~/#{application}.git"
set :use_sudo, false
set :user, "victorstan" # The server's user for deploys
set :scm, :git
set :scm_username, "passenger"
set :scm_passphrase, "*********" # The deploy user's password
set :deploy_to, "/srv/www/#{application}"
set :keep_releases, 2
set :branch, "master"
set :deploy_via, :copy # won't make cap prompt for password when deploying
set :scm_verbose, true
set :rvm_ruby_string, :local
set :rvm_type, :user
set :rvm_install_type, :stable
set :default_shell, :bash
set :whenever_command, "bundle exec whenever"
default_run_options[:pty] = true
# before 'deploy', 'rvm:install_ruby'
before 'deploy:setup', 'rvm:install_ruby'
require "rvm/capistrano"
require "bundler/capistrano"
require "whenever/capistrano"
role :web, domain # Your HTTP server, Apache/etc
role :app, domain # This may be the same as your `Web` server
role :db, domain, :primary => true # This is where Rails migrations will run
Some notable elements that have changed:
set :rvm_ruby_string set to :local instead of explicitly naming it: 'ruby-2.0.0-p195#dinner', not sure if this has any implication on the issue though, seems unlikely.
set :default_shell, :bash was another parameter I added.
And, as I mentioned, the ordering or the different DSL types might make a difference: set comes first, then before hooks, then require and then role after which comes the rest of the deploy script. Perhaps this can help someone in a similar situation.
Note, when I first tested this script I had before 'deploy', 'rvm:install_ruby' enabled, but I have since disabled it and the script continues to work...

Resources