Let Capistrano Compile Ruby 1.9 For You
Posted: June 2nd, 2009 | Author: Jerod | Filed under: Debian | Tags: capistrano, ruby19 | Comments OffA Capistrano task to install Ruby 1.9.1 to “/opt/ruby-1.9.1” on Debian:
Read the rest of this entry »
A Capistrano task to install Ruby 1.9.1 to “/opt/ruby-1.9.1” on Debian:
Read the rest of this entry »
I’ve been playing with Capistrano a lot lately and loving it. Here is an example of how easy it is to write tasks and use them on multiple remote servers.
This task installs your SSH public key on the remote machine to allow key-based authentication:
set :key_file do Capistrano::CLI.ui.ask "enter public key to push: " end desc "configures key-based SSH administration" task :push_key, :roles => :all do key_location = File.expand_path(key_file) unless File.exist?(key_location) and key_file.match(/\.pub$/) puts "Couldn't locate public key. Try again" exit end key_file_name = File.basename(key_location) upload key_location, "/tmp/#{key_file_name}" run "if [ ! -e ~/.ssh ];then mkdir ~/.ssh; fi" run "cat /tmp/#{key_file_name} >> ~/.ssh/authorized_keys" run "rm /tmp/#{key_file_name}" run "chmod 600 ~/.ssh/authorized_keys" end
Silky smooth.
If you’re trying to configure git commands in a directory that isn’t pwd, you’ll have to deal with clone and pull a little differently. Clone works like this:
git clone [source location] [destination location]
An example clone into my application’s vendor directory:
git clone git://github.com/rails/rails.git ~/rails/myapp/vendor/rails
Pull works like this:
git --git-dir=/path/to/destination/.git pull
An example pull in the already initiated local rails repository:
git --git-dir=~/rails/myapp/vendor/rails/.git pull
Using these approaches, you can simplify your capistrano recipes. here is an example snippet:
set :rails_source, "git://github.com/rails/rails.git" desc "git the latest rails" task :git_rails do run "mkdir -p #{shared_path}/vendor" result = run_and_return "ls #{shared_path}/vendor" if result.match(/rails/) run "git --git-dir=#{shared_path}/vendor/rails/.git pull" else run "git clone #{rails_source} #{shared_path}/vendor/rails" end end
See man git-clone and man git-pull for more details.