capistrano 中的logger, set-before (capistrano basic usages)

访问量: 1930

Capistrano 灰常好用。 不过有几个常用的用法还是要留意一下: 参考这个文章:

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

这里是一个完整的deploy.rb :

https://github.com/beijing-rubyist/bjrubyist/blob/master/config/deploy.rb

使用 输入:  set(:user) { Capistrano::CLI.ui.ask("User name: ") }

1. 总览:
$ cap --help

2. 使用logger,特别是在其他语言调用CAP时,非常有用(例如被fabric 调用): 
$ cap setup --logger STDOUT

3. 使用变量, 要记得: 使用@. . 例如,我们要设置 "deploy_type" 这个变量: 
$ cap say_hi --set-before deploy_type=staging

然后在 config/deploy.rb 中这样使用:

DEFAULT_TYPE = "stable" 

# deploy_type 仅仅在 begin 这个区域中生效, 在rescue, ensure中都不行。
begin
deploy_type
puts "deploy_type was set successfully"
@deploy_type = deploy_type
rescue Exception => e
puts "deploy_type not set, use default: #{DEFAULT_TYPE}"
deploy_type = DEFAULT_TYPE
@deploy_type = deploy_type
end

task :say_hi do
puts "hihihi, var_deploy_type: #{@deploy_type}"
end

输出: 
deploy_type was set successfully 
============= DEPLOY_PATH: /rails_apps/babble_portal/cutting_edge
* executing `say_hi'
hihihi, var_deploy_type: 444

最后,使用copy方式:

set :scm, :none
set :repository, "."
set :deploy_via, :copy

订阅/RSS Feed

Subscribe

分类/category