ruby on rails3 capistrano rvm (revised)

Posted

以前在rvm下没有rvm-capistrano的时候,自己去写shell还是难过!

添加到Gemfile ```sh Gemfile group :development do gem 'capistrano', '2.9.0', :require => false gem 'rvm-capistrano', :require => false end


```sh
bundle install
$ capify .
[add] writing './Capfile'
[add] writing './config/deploy.rb'
[done] capified!

```ruby deploy.rb

require "rvm/capistrano" #https://rvm.io/integration/capistrano/

default_run_options[:pty] = true set :rvm_ruby_string, 'ruby-1.9.3-p362' set :rvm_type, :user

set :application, "new_xxx" set :repository, "git@github.com:xxx/new_xxx.git" set :branch, "master" set :scm, :git set :user, "john" set :use_sudo, false

set :deploy_to, "/home/john/deploy/#{application}" set :runner, "ruby"

set :deploy_via, :remote_cache

set :deploy_via, :remote_cache #set :git_shallow_clone, 1

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

role :web, "staging.xxx.com" # Your HTTP server, Apache/etc role :app, "staging.xxx.com" # This may be the same as your Web server role :db, "staging.xxx.com", :primary => true # This is where Rails migrations will run role :db, "staging.xxx.com"

namespace :deploy do task :start, :roles => :app do run ["cd #{deploy_to}/current/","RAILS_ENV=production bundle exec thin start -C config/thin.yml"].join(' && ') end

task :stop, :roles => :app do run ["cd #{deploy_to}/current/","RAILS_ENV=production bundle exec thin stop -C config/thin.yml"].join(' && ') end

desc "Restart Application" task :restart, :roles => :app do run ["cd #{deploy_to}/current/","RAILS_ENV=production bundle exec thin restart -C config/thin.yml"].join(' && ') end end

desc "tail log" task :log, :roles => :app do stream "tail -n100 -f #{deploy_to}/current/log/#{rails_env.downcase}.log" end

task :link_shared_files, :roles => :web do run "ln -sf #{deploy_to}/shared/Gemfile.lock #{deploy_to}/current/Gemfile.lock" run "ln -sf #{deploy_to}/shared/cache #{deploy_to}/current/vendor/cache" run "ln -sf #{deploy_to}/shared/mnt/uploads #{deploy_to}/current/public/uploads" end

desc 'compile_assets production' task :compile_assets, :roles => :web do run "cd #{deploy_to}/current/; RAILS_ENV=production bundle exec rake assets:precompile" end

desc 'init bundle env' task :init_bundle, :roles => :web do run "cd #{deploy_to}/current/; bundle install --without development test" end # after "deploy:finalize_update","deploy:symlink",:link_shared_files, :init_bundle, :compile_assets



初始化
```sh
cap deploy:setup

布署

$ cap deploy
  * 2013-01-22 14:34:59 executing `deploy'
  * 2013-01-22 14:34:59 executing `deploy:update'
 ** transaction: start
  * 2013-01-22 14:34:59 executing `deploy:update_code'
    executing locally: "git ls-remote git@github.com:xxx/xxx.git master"
    command finished in 6756ms
  * executing "git clone -q --depth 1 git@github.com:xxx/xxx.git /home/john/deploy/xxx/releases/20130122063506 && cd /home/john/deploy/xxx/releases/20130122063506 && git checkout -q -b deploy c7d9acbaaef3a9ff09ec3f751969a00544f90230 && (echo c7d9acbaaef3a9ff09ec3f751969a00544f90230 > /home/john/deploy/xxx/releases/20130122063506/REVISION)"
    servers: ["staging.xxxx.com"]
cap deploy:update_code#更新代码
cap deploy:start
cap deploy:stop
cap log #本地就是可以看服务器的production.log

ref: https://rvm.io/integration/capistrano/


此文章 短链接: http://dlj.bz/7TuJBD