Could not find rake-10.0.3 in any of the sources - ruby-on-rails

I successfully installed a Rails (3.2.10) app on an Ubuntu 12.04 server on Rackspace following Railscasts 335 deploying to a vps. Nginx, Unicorn, rbenv and Capistrano.
Then, when I try to install a second rails website I get the error "Could not find rake-10.0.3 in any of the sources" during cap:deploy. cap:setup and cap:check were successful. Additionally, there is no current directory under my application folder.
If I cd into the releases directory and run bundle install it is using rake-10.0.3. The only difference between the two apps is that the new app I am trying to install uses the assets pipeline.
Here is my deploy file which is identical for both apps, except for the set :application directive.
set :user, 'mark'
set :scm_passphrase, 'xxxx'
set :domain, '99.99.99.99'
set :application, "my_app"
set :repository, "#{user}##{domain}:git/#{application}.git"
ssh_options[:forward_agent] = true
set :deploy_to, "/var/www/#{application}"
role :app, domain
role :web, domain
role :db, domain, :primary => true
default_run_options[:pty] = true
set :deploy_via, :remote_cache
set :scm, 'git'
set :branch, 'master'
set :scm_verbose, true
set :use_sudo, false
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.yml"), "#{shared_path}/config/database.yml"
puts "Now edit the config files in #{shared_path}."
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

Remove all the versions of Rake ==> gem uninstall rake
Remove Gemfile.lock ==> rm Gemfile.lock
Run bundle install ==> bundle install
gem install rake --version=10.0.2
if you still get the error then put this into your gemfile.
gem 'rake', '0.8.7'

bundle update rake
worked for me. I've had similar problem.

If your still looking for a fix... For me it was a matter of using sudo bundle install instead of just bundle install.

I had this same cryptic error message .... turns out I had created a 'cloned' release inside the release folder which causes sprockets to want to do things there .... I think cap uses the create date as it traverses the release tree so somehow this messed things up .... be sure there are no additional 'hand made' folders in your /releases/ folder and you should get past this bug

I had the same problem. The cause for my problem was that Rake was also found in /usr/bin/local/ in addition to being in the shims directory in rbenv. To check if this is the problem first uninstall rake gem uninstall rake then run which rake. If you get back a path that is different than /Users/username/.rbenv/shims/rake then just remove that binary using sudo rm /path/to/file.
Note that in my case at least, which gem was using a shimed executable that was managed by rbenv, while rake wasn't. So everything worked find until I tried to invoke rake command from the terminal.
Also see: After installing rbenv and changing Ruby version, Rake no longer runs

For rails version from 4.3, let try with bundle exec rails app:update. It worked for me.
Hope it's useful for you.

Related

Capistrano + whenever + db database.yml not found

I'm trying to run Capistrano 2.15.5 with Whenever 0.8.4 and Ruby 2.0.0
I've added
set :whenever_command, "bundle exec whenever"
require "whenever/capistrano"
to the end of my deploy.rb file and it always run:
/releases/20150910075216 && bundle exec whenever --update-crontab
app_name --set environment=production --roles db
and fails wth
No such file or directory -
/releases/20150910075216/config/database.yml
because database.yml is in folder /shared/ anyways I don't need the db -
how to get rid of --roles db in the capistrano command?
I have
server("my_server", :app, :web, :db, :primary => true)
because I need the :db for other scripts.
Thanks for help!
David
You should set linked_files Symlink linked files database.yml as following in deploy.rb for capistrano 3
set :linked_files, fetch(:linked_files, []).push('config/database.yml')
Or you can do Symlink manually for older version.
desc "Make symlink for database yml"
task :symlink do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end

Capistrano deploy using remote_cache - Permission denied

I am modifying a functional Capistrano script trying to speed it up since my home internet upload speed is horrendous. I have a git server (not github), and a ubuntu dev server, when I run cap deploy it currently grabs the latest from my git repo and makes a local copy then uploads that to my ubuntu server and restarts passenger without an issue. My capistrano code contains...
set :deploy_via, :copy
But if I try to use this instead...
set :deploy_via, :remote_cache
I get this error...
** transaction: start
* ←[32m2014-03-13 08:43:36 executing `deploy:update_code'←[0m
updating the cached checkout on all servers
←[33mexecuting locally: "git ls-remote ssh://gitadmin#sub.example.com/opt/git/hub/app.git master"←[0m
gitadmin#sub.example.com's password:
←[2;37mcommand finished in 6880ms←[0m
* ←[33mexecuting "if [ -d /srv/www/app/shared/cached-copy ]; then cd /srv/www/app/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset
-q --hard efe4a94f5a4f1354edb0f4b516e9ea1d627e5101 && git clean -q -d -x -f; else git clone -q -b master ssh://gitadmin#sub.example.com/opt/git/hub/app.git /s
rv/www/app/shared/cached-copy && cd /srv/www/app/shared/cached-copy && git checkout -q -b deploy efe4a94f5a4f1354edb0f4b516e9ea1d627e5101; fi"←[0m
servers: ["12.34.56.78"]
[12.34.56.78] executing command
** ←[31m[12.34.56.78 :: err] Permission denied, please try again.←[0m
** ←[31m[12.34.56.78 :: err] Permission denied, please try again.←[0m
** ←[31m[12.34.56.78 :: err] Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).←[0m
** [12.34.56.78 :: err] fatal: The remote end hung up unexpectedly
It prompts for the git password - gitadmin#sub.example.com's password:
which I enter and it proceeds ok, then it seems to error out on the next command above. I'm guessing I need to setup some ssh keys somehow? Again this is not hosted on github, the repo and dev server are two separate boxes on my company servers. Locally I am running windows 7. If I try adding...
set :ssh_options, { :forward_agent => true }
default_run_options[:pty] = true
I get the same distance but this time instead of automatically saying permission denied, it prompts for the gitadmin password, I enter it correctly and it says "permission denied".
It would help if you posted your full capistrano scipt (minus any passwords, ip addresses) but I suspect that you need to introduce your server to the remote repository.
You don't need deploy_via option at all
To introduce your server to your repo ssh into your server and from there ssh into the repository service, there should be documentation on the url to use for this. You would get a access denied message but the point is that this process adds ssh public key to your server
It might also be worth watching Ryan Bates Railscast on deploying, he uses github but the process is pretty similar for any remote repo
http://railscasts.com/episodes/335-deploying-to-a-vps
Pay attention to how he introduces his server to github, like I say, your service should provide you with instructions for similar introduction
There is a revised (pro) cast that you would need a subscription for but Ryan is on an extended break (possibly indefinitely right now) so a subscription would be extremely good value right now and well worth thinking about.
The revised (pro) cast on capstrano, how to set variables etc... is here http://railscasts.com/episodes/133-capistrano-tasks-revised
This is a working script for one of my apps just replace xxx and paths as you see fit, I assume you have all the start and restart stuff already set up but this should point you to at least the minimum settings needed. I say this because you possibly have other setting that you don't need, but as you haven't posted your script it is impossible to tell.
require "bundler/capistrano"
server "146.185.182.228", :web, :app, :db, primary: true
set :application, "xxx"
set :user, "xxxx"
# adjust if you are using RVM, remove if you are not
set :rvm_type, :user
set :rvm_ruby_string, 'ruby-2.0.0-p353'
set :ssh_options, {:forward_agent => true}
default_run_options[:pty] = true
# file paths
set :repository, "git#bitbucket.org:xxxx.git"
set :deploy_to, "/home/#{user}/apps/#{application}"
# set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
set :scm, :git
set :use_sudo, false
set :rails_env, :production
set :password, "xxxxxxx"
#role :web, "your web-server here" # Your HTTP server, Apache/etc
#role :app, "your app-server here" # This may be the same as your `Web` server
#role :db, "your primary db-server here", :primary => true # This is where Rails migrations will run
#role :db, "your slave db-server here"
# if you want to clean up old releases on each deploy uncomment this:
after "deploy:restart", "deploy:cleanup"
# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
%w[start stop restart].each do |command|
desc "#{command} unicorn server"
task command, roles: :app, except: {no_release: true} do
run "cd #{release_path} && bundle install"
run "/etc/init.d/unicorn_#{application} #{command}"
run "#{sudo} service nginx #{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/init_unicorn.sh /etc/init.d/unicorn_#{application}"
sudo "ln -nfs #{current_path}/config/sidekiq.conf /etc/init/sidekiq.conf"
run "mkdir -p #{shared_path}/config"
end
after "deploy:setup", "deploy:setup_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"
after "deploy:update_code", "deploy:symlink_shared"
end

Missing current folder Capistrano Rails 3.2

I need to understand why capistrano doesn't create the folder current. I'm using the following command : cap deploy:setup, cap deploy:check, cap deploy
But when i check in my app directory, i don't current folder.
This my deploy.rb
# Execute "bundle install" after deploy, but only when really needed
require 'bundler/capistrano'
# Automatically precompile assets
load "deploy/assets"
# RVM integration
require "rvm/capistrano"
# Application name
set :application, "app"
# Application environment
set :rails_env, :production
# Deploy username and sudo username
set :user, "ubuntu"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
#We don't want to use sudo (root) - for security reasons
set :use_sudo, false
#Target ruby version
set :rvm_ruby_string, '1.9.3-p374'
#System-wide RVM installation
set :rvm_type, :user
#We use sudo (root) for system-wide RVM installation
set :rvm_install_with_sudo, true
#git is our SCM
set :scm, :git
#Use github repository
set :repository, "git#github.com:.../CM.git"
#master is our default git branch
set :branch, "master"
#Deploy via github
set :deploy_to, "/var/www/app/#{application}"
set :deploy_via, :remote_cache
#We have all components of the app on the same server
server "125.156.125.125", :app, :web, :db, :primary => true
namespace :deploy do
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
task :symlink_shared do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
run "ln -nfs #{shared_path}/assets #{release_path}/public/assets"
end
task :assets do
system "rsync -vr --exclude='.DS_Store' public/assets #{user}##{application}:# {shared_path}/"
end
end
after 'deploy:update_code', 'deploy:symlink_shared'
I don't understand where is the error, if someone can i help me ?
Thanks you
It could fail due to folder permissions also.
If the option
set :use_sudo, false
was not present when the first time cap was deployed, the current folder have sudo as the owner. When the user is changed, it might not have sufficient permissions to update the link.
I deleted the symbolic link and ran
cap deploy:create_symlink
This updated the symbolic link for me.
Capistrano creates a current symlink (not directory) as one of the last steps in it's deployment cycle, generally right before the application server gets sent a start/restart command. It cannot create that symlink before deploying as there is nothing to symlink to (no checkouts in /releases).
If it's still not creating the symlink, check your capistrano deploy logs for an error, it won't create the symlink if it has an error before making it to that point. And if there is an error, please post it in your question.

Whenever Gem Fails to Run "bundle exec" Correctly in Capistrano

I'm having problems deploying the Whenever gem to my production environment using Capistrano.
The problem is stemming from a bundle exec whenever command that's triggering some 'missing gem' issues (yet running bundle install from the shell shows that everything is in fact there!).
My feeling is that one of two things is happening: that Bundler isn't fully loading before bundle exec is being called, or that somehow there's a path issue that's running it in the wrong place.
Here's what's going on:
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
executing locally: "git ls-remote git#my-source-repository:mysource.git HEAD"
command finished in 1847ms
* executing "git clone -q git#my-source-repository:mysource.git /domains/myapp/releases/20130124211036 && cd /domains/myapp/releases/20130124211036 && git checkout -q -b deploy 90238bbcb993e3e7df2374ffaa13e7ed701c202e && (echo 90238bbcb993e3e7df2374ffaa13e7ed701c202e > /domains/myapp/releases/20130124211036/REVISION)"
servers: ["myip"]
[myip] executing command
** [myip :: out] Enter passphrase for key '/home/deploy/.ssh/id_rsa':
** [myip :: out]
command finished in 9294ms
* executing `deploy:finalize_update'
triggering before callbacks for `deploy:finalize_update'
* executing `whenever:update_crontab'
* executing "cd /domains/myapp/releases/20130124211036 && bundle exec whenever --update-crontab My App --set environment=production --roles db"
servers: ["myip"]
[myip] executing command
** [out :: myip] Could not find carrierwave-0.5.8 in any of the sources
** [out :: myip] Run `bundle install` to install missing gems.
command finished in 1967ms
*** [deploy:update_code] rolling back
* executing "rm -rf /domains/myapp/releases/20130124211036; true"
servers: ["myip"]
[myip] executing command
command finished in 998ms
failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell '1.9.3' -c 'cd /domains/myapp/releases/20130124211036 && bundle exec whenever --update-crontab My App --set environment=production --roles db'" on myip
You can see that the failure is coming from this line:
bundle exec whenever --update-crontab
Which is in turn being run by my Capistrano deploy.rb.
# Your Application's "Name"
set :application, [My App]
# The URL to your application's repository
set :repository, [repo]
set :scm, :git
set :scm_passphrase, [password]
# The user you are using to deploy with (This user should have SSH access to your server)
set :user, "deploy"
# We want to deploy everything under your user, and we don't want to use sudo
set :use_sudo, false
# Where to deploy your application to.
set :deploy_to, "/domains/myapp/"
# Load RVM's capistrano plugin.
require "rvm/capistrano"
set :rvm_ruby_string, '1.9.3'
set :rvm_type, :system # use system-wide RVM
# Require that we use bundler to install necessary gem dependencies
require "bundler/capistrano"
set :whenever_command, "bundle exec whenever"
require "whenever/capistrano"
# -------------------------------- Server Definitions --------------------------------
# Define the hostname of your server. If you have multiple servers for multiple purposes, we can define those below as well.
set :server_name, [server]
# We're assuming you're using a single server for your site, but if you have a seperate asset server or database server, you can specify that here.
role :app, server_name
role :web, server_name
role :db, server_name, :primary => true
# -------------------------------- Final Config --------------------------------
# This configuration option is helpful when using svn+ssh but doesn't hurt anything to leave it enabled always.
default_run_options[:pty] = true
namespace :deploy do
desc "Tell Passenger to restart the app."
task :restart do
run "touch #{deploy_to}current/tmp/restart.txt"
end
task :start do
run "cd #{deploy_to} && ln -s current/public public_html"
run "touch #{deploy_to}current/tmp/restart.txt"
end
task :symlink do
run "cd #{deploy_to} && rm current ; ln -s releases/#{release_name} current"
end
task :stop do
run "rm #{deploy_to}public_html"
end
namespace :web do
task :disable do
run "cd #{deploy_to} && rm public_html && ln -s static_site public_html"
end
task :enable do
run "cd #{deploy_to} && rm public_html && ln -s current/public public_html"
end
end
desc "Symlink shared configs and folders on each release."
task :symlink_shared do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
run "ln -nfs #{shared_path}/assets #{release_path}/public/assets"
# create symlink to uploads folder for Carrierwave resources (i.e., book cover images)
run "ln -nfs #{shared_path}/uploads #{release_path}/public/uploads"
end
desc "Sync the public/assets directory."
task :assets do
system "rsync -vr --exclude='.DS_Store' public/assets #{user}##{application}:#{shared_path}/"
end
end
after "deploy", "deploy:migrate"
after 'deploy:update_code', 'deploy:symlink_shared'
after(:setup) do
run "rm -rf #{deploy_to}public_html"
run "mkdir #{deploy_to}static_site"
end
Now, the error that I'm getting about CarrierWave is bogus - I've been using CarrierWave for ages - and the issue clearly stems (as you can see by the command that triggers the error) from either Whenever itself or Bundler.
And I'm thinking that it actually may have something to do with paths related to RVM. At any rate, the bundle exec whenever isn't working.
Any ideas?
It turns out there were a couple problems, both of which needed addressing:
Whenever ~> 0.8 introduced a bug with Capistrano roles
The Whenever cap task was firing before bundle:install (this is confirmed in your code above)
See issues here: https://github.com/javan/whenever/issues/275 and here: https://github.com/javan/whenever/issues/269
To fix the problem, you most likely need to
Update bundler on your server (-v 1.2.3)
Update bundler locally
Update to the newest Whenever (-v 0.8.2)
#ideaoforder's answer helped me too, previously though I had the same trouble caused by require 'whenever/capistrano' being on the top of the config/deploy.rb followed by require 'bundler/capistrano'. Swapping those two helped.
I have require 'bundler/capistrano' always on top of the deploy script as a rule.

Bundle install error when deploying via capistrano (& rvm)

Now I must admit that I'm stumbling around in the dark a little bit as far as this deployment lark is concerned. I'll try and explain the situation best I can; I have set up a test deployment server and am trying to deploy my app to it with capistrano, however, I am encountering some difficulties surrounding my gems and their dependencies, as the error below shoes.
[mike-test] executing command
[mike-test] rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell '1.9.3' -c 'cd /home/deploy/myapp/releases/20120910081544 && bundle install --gemfile /home/deploy/myapp/releases/20120910081544/Gemfile --path /home/depoy/myapp/shared/bundle --deployment --quiet --without development test'
** [out :: mike-test] Some gems seem to be missing from your vendor/cache directory.
** [out :: mike-test] Could not find log4r-1.1.10 in any of the sources
command finished in 9134ms
*** [deploy:update_code] rolling back
log4r isn't in my gemfile so I can only assume it's a (perhaps production only?) dependency of another gem. I don't know why bundler isn't downloading the gem and installing it if it can't find it? I put the gem in my gemfile, ran bundle install locally, and then committed and deployed again and got the same error but with a different gem this time (spreadsheet), so that appeared to solve the error in that case only, but doesn't identify the problem.
Something else to muddy the water, I'm trying to use RVM on the production server and despite reading a lot about it I'm still not 100% sure I get how it works, so that might be a factor.
My deploy.rb:
require "bundler/capistrano"
require "rvm/capistrano"
# SCM Settings
set :rvm_ruby_string, '1.9.3'
set :use_sudo, false
ssh_options[:forward_agent] = true
default_run_options[:pty] = true
set :branch, :mikedev
set :deploy_via, :remote_cache
set :copy_cache, true
set :git_enable_submodules, 0
set :repository, "our_git_repo.git"
set :scm, :git
set :user, :deploy
set :keep_releases, 1
set :application, "myapp"
set :deploy_to, "/home/deploy/myapp"
set :branch, "mikedev"
role :web, "mike-test"
role :app, "mike-test"
role :db, "mike-test", :primary => true
namespace :deploy do
desc "Restarting mod_rails with restart.txt"
task :restart, :roles => :app, :except => { :no_release => true } do
run "touch #{current_path}/tmp/restart.txt"
end
[:start, :stop].each do |t|
desc "#{t} task is a no-op with mod_rails"
task t, :roles => :app do ; end
end
end
Any guidance would be much appreciated.
bundle install --deployment ... will not download any gems if vendor/cache is present. It'll look for gems just there. There are two options:
remove vendor/cache directory (even if it's already empty) from your VCS
or run bundle package and add all new files under vendor/cache to your VCS
The latter seems to be better option. In this way you protect your deployment from outages of rubygems servers.

Resources