2011-02-06 6 views

答えて

7

カピストラーノのputコマンドは、文字列からファイルを書き込むことができます。

desc 'Generate a config yaml in shared path' 
    task :generate_yaml, :roles => :app do 
    sphinx_yaml = <<-EOF 
development: &base 
    morphology: stem_en 
    config_file: #{shared_path}/config/sphinx.conf 
test: 
    <<: *base 
production: 
    <<: *base 
EOF 
    run "mkdir -p #{shared_path}/config" 
    put sphinx_yaml, "#{shared_path}/config/sphinx.yml" 
    end 

注:Making Your Capistrano Recipe Book

putから持ち上げ例は、それが後半の答えだCapistrano gitub repo

+0

を働いカピストラーノ3

で動作する新しいファイルを作成し、「置く」となっていますか?そうでない場合:ファイルを上書きするか追加するか? – user1291365

+0

putについての説明はCapistrano docsを参照 – zetetic

+6

これはCapistrano v3の時点ではもう動作しません – rposborne

1

はい、あなたは例えば、次のRubyコマンドは.rvmrcするRVMの[email protected]を書き込みbashスクリプトを実行します、.rvmrcファイルを書き込むためにrakeタスクを書き込むことができます。

 
system "echo 'rvm [email protected]' > .rvmrc" 

.rvmrcファイルをgitリポジトリに保存しないこともお勧めします。このファイルは実際にはシステム固有のファイルで、別のシステム設定を使用する他の開発者には問題が発生する可能性があります。中央リポジトリから、自分自身の.rvmrcファイルを書き直す必要があります。ここに示されているよう

1

に記載されています受け入れられた答えによると、私は仕事をするにはrvm名前空間のタスクを作成しました。これは、新しいルビー・バージョンを使用しない:

after 'deploy:update_code', 'rvm:create_ruby_version' 

namespace :rvm do 
    task :create_ruby_version do 
    run "cd #{latest_release} && rvm rvmrc create #{rvm_ruby_string} --ruby-version" 
    end 
end 
+0

これは、Rubyのバージョンマネージャーと互換性のある.ruby-versionと.ruby-gemsetを作成します –

2

put方法は、もはやこのソリューションは、私にとって

task :generate_yml do 
    on roles(:app) do 
    set :db_username, ask("DB Server Username", nil) 
    set :db_password, ask("DB Server Password", nil) 
    db_config = <<-EOF 
development: 
    database: #{fetch(:application)}_development 
    adapter: mysql2 
    encoding: utf8 
    reconnect: false 
    pool: 5 
    username: #{fetch(:db_username)} 
    password: #{fetch(:db_password)}  
test: 
    database: #{fetch(:application)}_test 
    adapter: mysql2 
    encoding: utf8 
    reconnect: false 
    pool: 5 
    username: #{fetch(:db_username)} 
    password: #{fetch(:db_password)} 
production: 
    database: #{fetch(:application)}_production 
    adapter: mysql2 
    encoding: utf8 
    reconnect: false 
    pool: 5 
    username: #{fetch(:db_username)} 
    password: #{fetch(:db_password)} 
EOF 
    location = fetch(:template_dir, "config/deploy") + '/database.yml' 
    execute "mkdir -p #{shared_path}/config" 
    File.open(location,'w+') {|f| f.write db_config } 
    upload! "#{location}", "#{shared_path}/config/database.yml" 
end 
end