Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make capistrano write a .rvmrc file when deploying?

My git repo has my local rvmrc file in it, and when I deploy I want to use a different rvm gemeset name etc.

Is there a way I can make capistrano create a .rvmrc file (or overrite it if present) whenever I deploy?

like image 674
Blankman Avatar asked Feb 06 '11 22:02

Blankman


2 Answers

Capistrano's put command can write a file from a string, as shown here:

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

Note: example lifted from Making Your Capistrano Recipe Book

put is documented in the Capistrano gitub repo

like image 155
zetetic Avatar answered Nov 12 '22 09:11

zetetic


put method no longer works in Capistrano 3

This solution worked for me

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
like image 22
anusha Avatar answered Nov 12 '22 09:11

anusha