Rake

Rake: a simple ruby build program with capabilities similar to make.


Articles on Rake

Hack: Deploying with git and rake-remote_task

This is an update to my previous post: Hack: Deploying with git, replacing the use of pure rake, for rake-remote_task.

Add the following to your Rakefile

require 'rake/remote_task'

set :domain,      ENV.fetch(PRODUCTION_HOST, "www.yourhost.com")
set :environment, ENV.fetch(RACK_ENV,        "production")

set :app_path,    "/path/to/app/install"

remote_task :deploy do
  run "set -x; cd #{app_path} && git pull && bundle"
end

remote_task :restart do
  run "set -x; cd #{app_path} && RACK_ENV=#{environment} bundle exec rake unicorn:restart --trace"
end

Then run

$ RACK_ENV=production PRODUCTION_HOST=www.foohost.com bundle exec rake deploy restart

or just

$ RACK_ENV=production PRODUCTION_HOST=www.foohost.com bundle exec rake deploy

Note -- This assumes the following:

  • You've checked out your repo on your remote host.
  • You've setup your app and it's running on your remote server.
  • You're using using Unicorn.
  • You're using Bundler.

Hack: Deploying with git

This has been updated, see: Hack: Deploying with git and rake-remote_remote

Add the following to your Rakefile

ENV['PRODUCTION_HOST'] ||= "www.yourhost.com"
task :deploy do
  system("ssh #{PRODUCTION_HOST} 'set -x; cd /path/to/app/install && git pull && bundle'")
end

desc "restart production" 
task :restart do
  system("ssh #{PRODUCTION_HOST} 'set -x; cd /path/to/app/install && RACK_ENV=#{ENV['RACK_ENV']} bundle exec rake unicorn:restart --trace'")
end

Then run

$ RACK_ENV=production PRODUCTION_HOST=www.foohost.com bundle exec rake deploy restart

or just

$ RACK_ENV=production PRODUCTION_HOST=www.foohost.com bundle exec rake deploy

Note -- This assumes the following:

  • You've checked out your repo on your remote host.
  • You've setup your app and it's running on your remote server.
  • You're using using Unicorn.
  • You're using Bundler.

Hack: Generating gh-pages

With rake

Add the following to your Rakefile

desc "generate and update gh-pages"
task :pages do
  system(" set -x; bundle exec rspec ") or abort
  system(" set -x; bundle exec yardoc --protected ./lib/**/*.rb ") or abort
  system(" set -x; mv -v ./doc /tmp ") or abort
  system(" set -x; mv -v ./coverage /tmp ") or abort
  system(" set -x; git checkout gh-pages ") or abort
  system(" set -x; rm -rf ./doc ./coverage ") or abort
  system(" set -x; mv -v /tmp/doc . ") or abort
  system(" set -x; mv -v /tmp/coverage . ") or abort
  system(" set -x; git add . ") or abort 
  system(" set -x; git commit --all -m 'updating doc and coverage' ") or abort
  system(" set -x; git checkout master ") or abort
  puts "don't forget to run: git push origin gh-pages"
end

Then run

$ bundle exec rake pages
$ git push gh-pages

Or less ugly, with bash...

Create scripts/pages

#!/usr/bin/env bash
set -xue 
bundle exec rspec 
bundle exec yardoc --protected ./lib/**/*.rb
mv -v ./doc /tmp 
mv -v ./coverage /tmp 
git checkout gh-pages
rm -rf ./doc ./coverage 
mv -v /tmp/doc .
mv -v /tmp/coverage . 
git add .
git commit --all -m 'updating doc and coverage'
git checkout master
echo "don't forget to run: git push origin gh-pages"

Then run

$ chmod 755 ./scripts/pages
$ ./scripts/pages

Note -- I opted for the rake method because I use rake in my projects.

vlad-push

Vlad is a simple Rake based deployment tool, similar to Capistrano, which allows for easily managing code deployments on multiple servers and various environments. I'm not going to take a deep dive in to Vlad here and now, but you can learn more about it here.