Search code examples
ruby-on-railscapistranospreerailstutorial.orgdigital-ocean

Error with cap deploy:cold in Digital Ocean for Rails app


I really want to deploy an app and had been following railstutorial by Michael Hartl. Now, I'm about to deploy my first app in Digital Ocean but I keep on running on to a lot of problems. Anyway, most of it was already done except on this big one.

I followed the this blog by Hoang Pham and a tutorial by [Andrew Gertig][3].

Anyways, this is my first entry here. Let me say my thanks in advance.Everytime I do, $ cap deploy:cold, on my local machine I always get this error.

failed: "rvm_path=$HOME/.rvm $HOME/.rvm/bin/rvm-shell 'default' -c 'cd /home/deployer/apps/tiangge/releases/20150123165947 && bundle install --gemfile /home/deployer/apps/tiangge/releases/20150123165947/Gemfile --path /home/deployer/apps/tiangge/shared/bundle --deployment --quiet --without development test'" on 128.199.74.8

And I also notice this one, that's why I did gem uninstall bundler and gem install bundler again in the VPS

[128.199.74.8] executing command  ** [out :: 128.199.74.8] Unfortunately, a fatal error has occurred. Please see the Bundler  **

[out :: 128.199.74.8] ** [out :: 128.199.74.8] troubleshooting

complete log:

    triggering load callbacks
  * 2015-01-23 20:59:18 executing `deploy:cold'
  * 2015-01-23 20:59:18 executing `deploy:update'
 ** transaction: start
  * 2015-01-23 20:59:18 executing `deploy:update_code'
    triggering before callbacks for `deploy:update_code'
  * 2015-01-23 20:59:18 executing `sidekiq:quiet'
  * executing "if [ -d /home/deployer/apps/tiangge/current ] && [ -f /home/deployer/apps/tiangge/shared/pids/sidekiq.pid ] && kill -0 `cat /home/deployer/apps/tiangge/shared/pids/sidekiq.pid`> /dev/null 2>&1; then cd /home/deployer/apps/tiangge/current && bundle exec sidekiqctl quiet /home/deployer/apps/tiangge/shared/pids/sidekiq.pid ; else echo 'Sidekiq is not running'; fi"
    servers: ["128.199.74.8"]
deployer@128.199.74.8's password: 
    [128.199.74.8] executing command
 ** [out :: 128.199.74.8] Sidekiq is not running
 ** [out :: 128.199.74.8] 
    command finished in 1328ms
    updating the cached checkout on all servers
    executing locally: "git ls-remote git@bitbucket.org:bryanbenjamin/tiangge.git master"
    command finished in 4069ms
  * executing "if [ -d /home/deployer/apps/tiangge/shared/cached-copy ]; then cd /home/deployer/apps/tiangge/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard d87bdfba0860752edddcf6e8c021c1468367aa03 && git clean -q -d -x -f; else git clone -q -b master git@bitbucket.org:bryanbenjamin/tiangge.git /home/deployer/apps/tiangge/shared/cached-copy && cd /home/deployer/apps/tiangge/shared/cached-copy && git checkout -q -b deploy d87bdfba0860752edddcf6e8c021c1468367aa03; fi"
    servers: ["128.199.74.8"]
    [128.199.74.8] executing command
    command finished in 10461ms
    copying the cached version to /home/deployer/apps/tiangge/releases/20150123165947
  * executing "cp -RPp /home/deployer/apps/tiangge/shared/cached-copy /home/deployer/apps/tiangge/releases/20150123165947 && (echo d87bdfba0860752edddcf6e8c021c1468367aa03 > /home/deployer/apps/tiangge/releases/20150123165947/REVISION)"
    servers: ["128.199.74.8"]
    [128.199.74.8] executing command
    command finished in 1416ms
  * 2015-01-23 20:59:49 executing `deploy:finalize_update'
    triggering before callbacks for `deploy:finalize_update'
  * 2015-01-23 20:59:49 executing `deploy:assets:symlink'
  * executing "rm -rf /home/deployer/apps/tiangge/releases/20150123165947/public/assets && mkdir -p /home/deployer/apps/tiangge/releases/20150123165947/public && mkdir -p /home/deployer/apps/tiangge/shared/assets && ln -s /home/deployer/apps/tiangge/shared/assets /home/deployer/apps/tiangge/releases/20150123165947/public/assets"
    servers: ["128.199.74.8"]
    [128.199.74.8] executing command
    command finished in 1290ms
  * 2015-01-23 20:59:50 executing `bundle:install'
  * executing "cd /home/deployer/apps/tiangge/releases/20150123165947 && bundle install --gemfile /home/deployer/apps/tiangge/releases/20150123165947/Gemfile --path /home/deployer/apps/tiangge/shared/bundle --deployment --quiet --without development test"
    servers: ["128.199.74.8"]
    [128.199.74.8] executing command
 ** [out :: 128.199.74.8] Unfortunately, a fatal error has occurred. Please see the Bundler
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] troubleshooting documentation at http://bit.ly/bundler-issues. Thanks!
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/source/git/git_proxy.rb:114:in ``'
 ** [out :: 128.199.74.8] :
 ** [out :: 128.199.74.8] Cannot allocate memory - git clone 'git://github.com/spree/spree_auth_devise.git' "/home/deployer/apps/tiangge/shared/bundle/ruby/2.1.0/cache/bundler/git/spree_auth_devise-68351354588ecb7fa5d7bc278ebd86436a50d33d" --bare --no-hardlinks --quiet
 ** [out :: 128.199.74.8] (
 ** [out :: 128.199.74.8] Errno::ENOMEM
 ** [out :: 128.199.74.8] )
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/source/git/git_proxy.rb:114:in `block in git'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/shared_helpers.rb:62:in `call'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/shared_helpers.rb:62:in `with_clean_git_env'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/source/git/git_proxy.rb:114:in `git'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/source/git/git_proxy.rb:108:in `block in git_retry'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/retry.rb:38:in `call'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/retry.rb:38:in `run'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/retry.rb:28:in `attempt'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/source/git/git_proxy.rb:107:in `git_retry'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/source/git/git_proxy.rb:73:in `checkout'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/source/git.rb:149:in `specs'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/lazy_specification.rb:53:in `__materialize__'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/spec_set.rb:88:in `block in materialize'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/spec_set.rb:85:in `map!'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/spec_set.rb:85:in `materialize'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/definition.rb:132:in `specs'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/definition.rb:121:in `resolve_remotely!'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/installer.rb:79:in `run'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/installer.rb:18:in `install'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/cli/install.rb:79:in `run'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/cli.rb:145:in `install'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/vendor/thor/command.rb:27:in `run'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/vendor/thor/invocation.rb:121:in `invoke_command'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/vendor/thor.rb:363:in `dispatch'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/vendor/thor/base.rb:440:in `start'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/cli.rb:9:in `start'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/bin/bundle:20:in `block in <top (required)>'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/lib/bundler/friendly_errors.rb:5:in `with_friendly_errors'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/gems/bundler-1.7.12/bin/bundle:18:in `<top (required)>'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/bin/bundle:23:in `load'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/bin/bundle:23:in `<main>'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/bin/ruby_executable_hooks:15:in `eval'
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] 
 ** [out :: 128.199.74.8] from /home/deployer/.rvm/gems/ruby-2.1.3/bin/ruby_executable_hooks:15:in `<main>'
 ** [out :: 128.199.74.8] 
    command finished in 56236ms
*** [deploy:update_code] rolling back
  * executing "rm -rf /home/deployer/apps/tiangge/releases/20150123165947; true"
    servers: ["128.199.74.8"]
    [128.199.74.8] executing command
    command finished in 1335ms
failed: "rvm_path=$HOME/.rvm $HOME/.rvm/bin/rvm-shell 'default' -c 'cd /home/deployer/apps/tiangge/releases/20150123165947 && bundle install --gemfile /home/deployer/apps/tiangge/releases/20150123165947/Gemfile --path /home/deployer/apps/tiangge/shared/bundle --deployment --quiet --without development test'" on 128.199.74.8

deploy.rb

require "bundler/capistrano"
require "rvm/capistrano"
require 'capistrano/sidekiq'


server "128.199.74.8", :web, :app, :db, primary: true

set :application, "tiangge"
set :user, "deployer"
set :port, 6000
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false

set :scm, "git"
set :repository, "git@bitbucket.org:bryanbenjamin/tiangge.git"
set :branch, "master"

default_run_options[:pty] = true
ssh_options[:forward_agent] = true

after "deploy", "deploy:cleanup" # keep only the last 5 releases

namespace :deploy do
  %w[start stop restart].each do |command|
    desc "#{command} unicorn server"
    task command, roles: :app, except: {no_release: true} do
      run "/etc/init.d/unicorn_#{application} #{command}"
    end
  end

  task :setup_config, roles: :app do
    sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
    sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
    run "mkdir -p #{shared_path}/config"
    put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
    puts "Now edit #{shared_path}/config/database.yml and add your username and password"
  end
  after "deploy:setup", "deploy:setup_config"

  task :symlink_config, roles: :app do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  end
  after "deploy:finalize_update", "deploy:symlink_config"

  desc "Make sure local git is in sync with remote."
  task :check_revision, roles: :web do
    unless `git rev-parse HEAD` == `git rev-parse origin/master`
      puts "WARNING: HEAD is not the same as origin/master"
      puts "Run `git push` to sync changes."
      exit
    end
  end
  before "deploy", "deploy:check_revision"
end

Steps that I've done:

-reinstalled bundler and -tried set :rvm_bin_path, "/usr/share/ruby-rvm/bin" in deploy.rb

and some few things

Gemfile:

source 'https://rubygems.org'
ruby '2.1.3'

gem 'rails', '4.1.8'
gem 'sqlite3'
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0',          group: :doc

gem 'spring',        group: :development

gem 'unicorn'
gem 'capistrano'
gem 'rvm-capistrano'
gem 'dotenv-rails'
gem 'capistrano-sidekiq'


gem 'spree', '2.4.2'
gem 'spree_gateway', github: 'spree/spree_gateway', branch: '2-4-stable'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-4-stable'

Solution

  • You've got a Cannot allocate memory error. That means not enough RAM for bundler on your deploying machine.

    You can add swap partition to do this, or create a DO droplet with bigger RAM space.

    Good tutorial about adding a swap to DO droplet https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-12-04