capistrano for Rails3 的步骤
访问量: 2242
最新的文章看这里: http://siwei.me/blog/posts/capistrano-basics
参考这个文章:
http://stackoverflow.com/questions/4294970/rails-3-capistrano-tutorial-to-deploy-to-server-using-git
http://www.aaginskiy.com/technology/2011/02/deploying-rails-3-apps-with-capistrano/
1. vim Gemfile, 增加:
gem 'capistrano'
2. $ bundle install
3. $ capify .
会生成两个文件: Capfile , config/deploy.rb
4. 编辑后者,然后 $ cap deploy.
5. $ cap deploy:setup 会建立必须的 文件夹
6. 编辑 $ shared/config/database.yml
7. 加入下面几行:
1 load 'deploy/assets'
2 set :rake, "bundle exec rake"
32 namespace :assets do
33 task :precompile do
34 run "cd #{release_path} && bundle exec rake RAILS_ENV=production RAILS_GROUPS=a
35 end
36 end
37
38 desc "Copy database.yml to release_path"
39 task :cp_database_yml do
40 puts "executing my customized command: "
41 puts "cp -r #{shared_path}/config/* #{release_path}/config/"
42 run "cp -r #{shared_path}/config/* #{release_path}/config/"
43 end
44
45 before "deploy:assets:symlink", :cp_database_yml
46
这里是一个完整的deploy.rb :
https://github.com/beijing-rubyist/bjrubyist/blob/master/config/deploy.rb
注意: capistrano , 部署时, 不要把 log, tmp都部署上去, 所以要:
(参考: http://weblog.jamisbuck.org/2008/5/2/capistrano-2-3-0.html )
set :deploy_via, :copy
set :copy_cache, true
set :copy_exclude, [".git", "materials"]