Daily Code Reading #19 – Capistrano recipes – deploy setup

Today I’m reading through Capistrano‘s deploy:setup recipe. This recipe is used to setup a new server for deployment by creating the directories Capistrano uses and checking permissions.

The Code

1
2
3
4
5
6
7
 
namespace :deploy do
  desc < { :no_release => true } do
    dirs = [deploy_to, releases_path, shared_path]
    dirs += shared_children.map { |d| File.join(shared_path, d) }
    run "#{try_sudo} mkdir -p #{dirs.join(' ')} && #{try_sudo} chmod g+w #{dirs.join(' ')}"
  end

Review

(If you are new to Capistrano, my post on Capistrano variables will help clear up what each variable means)

deploy:setup begins by building a list of directories to get created:

  • deploy_to path
  • releases path
  • shared path

Then it adds the shared children to these, which include:

  • shared/system
  • shared/log
  • shared/pids
1
run "#{try_sudo} mkdir -p #{dirs.join(' ')} && #{try_sudo} chmod g+w #{dirs.join(' ')}"

Finally, deploy:setup creates all of those directories (mkdir -p) and changes the permissions to be group writable (chmod g+w).

I’ve used deploy:setup and Capistrano for years now but I never realized how simple this recipe really was. Reading through the code has given me the understanding of what’s happening and the confidence to be able to change things that don’t suit my applications.