Capistrano with a nested rails directory - ruby-on-rails-3

My Ruby on Rails application is not the root file of my git repository. Is there a variable that I can set so that Capistrano knows what directory to run rake when I ask it to run migrations?

I would do it by overriding the deploy:migrate recipe like this:
namespace :deploy do
task :migrate do
run "cd /path/to/rails/root; rake RAILS_ENV=#{rails_env} #{migrate_env} db:migrate"
end
end

Related

rake system command causes bundle error

I'm trying to run this rake task but it keeps on returning the following error:
Could not find libv8-3.3.10.4 in any of the sources
Run `bundle install` to install missing gems.
When I try and run bundle install bundler says everything is up to date.
I am running the task using this command:
bundle exec rake deploy:staging
Here's what my rake task looks like:
task :staging do
app = "heroku-app-name"
puts "Turn maintenance on"
system "heroku maintenance:on --app #{app}"
end
I was able to shell out to heroku commands from a rake task by wrapping the command in a Bundler.with_clean_env block like as follows:
Bundler.with_clean_env do
system "heroku maintenance:on --app #{app}"
end

The --deployment flag requires a Gemfile.lock

I have spent couple of hours but unable to solve this problem.
When I try to deploy my local rails app to production server using capistrano I get the below error:
The --deployment flag requires a Gemfile.lock. Please make sure you have checked your Gemfile.lock into version control before deploying.
Any idea on how to solve this?
My rails application folder is under version control using Git. I have pushed the local git repo to github and the Gemfile.lock is there on github. So it is under version control. However capistrano continues to give the same error.
Deploy.rb file: https://gist.github.com/brahmadpk/4748991
Remove BUNDLE_FROZEN: "true" from .bundle/config file and run bundle again.
Make sure there is nothing in the releases folder that is not a release. See this comment on a bundler issue for more details.
This blogpost titled Capistrano Deployment Trouble explains the same issue.
EDIT TO INCLUDE CONCLUSION FROM DISCUSSION IN COMMENTS
The deploy_to param was not set to an absolute path; hence capistrano wasn't able to find the folder to deploy, causing this error message.
I solve this with:
set :bundle_gemfile, "your_app_name/Gemfile"
in the deploy.rb
Run bundle and add your Gemfile.lock to your version control.
I had the same problem, even though I had no files or folders in the releases folder. Turned out it was a silly little thing: the gemfile.lock file in my repo was in lowercase for some reason, while capistrano needs Gemfile.lock with a capital G.
This is how I solved it:
Delete gemfile.lock
Delete gemfile.lock from you repo (git rm ...)
run bundle install
add the new Gemfile.lock file to your repo: git add Gemfile.lock
remove the folders from the server (don't know if this is really needed, did it anyway)
deploy
After adding bundle config unset deployment this line in the terminal, bundle install started working again for me.
I am getting exactly the same problem.
There is nothing in my releases folder (at all - my deploy cold keeps rolling back).
My gemfile.lock is checked in to Subversion.
I get:
** [out :: localhost] The --deployment flag requires a Gemfile.lock. Please make sure you have checked your Gemfile.lock into version control before deploying.
Is there any way to stop the rollback so that I can see what the releases folder looks like at the time it tries to run
cd /var/qlarity/releases/20130222003607 && bundle install --gemfile /var/qlarity/releases/20130222003607/Gemfile --path /var/qlarity/shared/bundle --deployment --quiet --without development test
Later....
I found that I could prevent the rollback by commenting out the code as shown from
gems\capistrano-2.14.1\lib\capistrano\recipes\deploy.rb
task :update_code, :except => { :no_release => true } do
# on_rollback { run "rm -rf #{release_path}; true" }
strategy.deploy!
finalize_update
end
This enabled me to examine my releases folder and sure enough, there was no Gemfile.lock in it. Turns out I have ended up with an unnecessary folder in my Rails project file structure so that instead of
myapp/trunk/app
myapp/trunk/config
...
myapp/trunk/Gemfile
I had
myapp/trunk/myapp/app
myapp/trunk/myapp/config
...
myapp/trunk/myapp/Gemfile
This meant I ended up with a folder containing my Gemfile
releases/nnnn/myapp
and bundle was looking for Gemfile in
releases/nnnn
When I changed my Capistrano config from
deploy.rb
set :repository, "file:///D:/_SVN//myapp/trunk"
to
deploy.rb
set :repository, "file:///D:/_SVN//myapp/trunk/myapp"
now all is good. Really should look at fixing the folder structure next!

Do I have to run rake assets:clean before rake assets:precompile?

I deploy code to my production server using git. This might include changes to JS and CSS files.
Do I have to run rake assets:clean at all before I run rake assets:precompile? I'm worried that not cleaning the previous precompiled assets might have side effects.
This is a little silly, but my google-fu didn't find any answers. My AWS instance runs rake assets:clean pretty slowly and I'm wondering if it's needed at all.
Also, can I replace the clean command with a simple rm -r public/assets?
No you do not need to run rake assets:clean before, just running rake assets:precompile will recompile your assets. It will recreate your cache busting digest and manifest.yml (which contains key/value mappings that match each asset name to its MD5 cache-busted name)
and yes you can just run rm -r public/assets

Rake aborted: Don't know how to build task 'jobs:work'

When I run bundle exec rake jobs:work I receive this error:
rake aborted!
Don't know how to build task 'jobs:work'
Anything wrong with the syntax?
Note: I installed delayed_jobs like this:
rails plugin install git://github.com/collectiveidea/delayed_job.git
rails generate migration create_delayed_jobs
[ Fill the migration from https://github.com/collectiveidea/delayed_job ]
bundle exec rake db:migrate
The solution was to install delayed_jobs as described here:
https://github.com/collectiveidea/delayed_job
After this, bundle exec rake jobs:work runs fine.

Is it possible to combine rake task and bundle install into one command?

I have several rake tasks combined into one rake command. Just wondering is it possible to have one command run the "bundle install" within a rake task ?
Or other way around ?
So when I deploy my rails app to a new server all I need to do is just run one command and it will grab all the dependencies and migrate databases settings.yaml files etc
you can chained your command with &&
For example :
rake my_task && bundle install
It's poor response but it's work ;-)
Obviously you can make your script
vi ./scripts/deploy.sh
#!/bin/sh
rake my_task && bundle install
I've seen this been done bundle install && bundle exec rake db:migrate