Friday, January 30, 2009

Dealing with Capistrano's cached-copy when switching the branch you're releasing from

Capistrano's default setup tries to deploy from a repository location you specify, and does so by updating a cached-copy on the remote servers using "svn up", and then recursively copying the updated cached checkout to a date-tagged copy under the releases directory.
e.g., when capistrano executes
~> cap deploy:update
it runs something like the following:
executing “if [ -d /deploy/myproject/shared/cached-copy ]; then svn update -q -r3131 /deploy/myproject/shared/cached-copy; else svn checkout -q -r3131 https://svn.example.com/svn/myreponame/tags/release-1.2.1/myproject /deploy/myproject/shared/cached-copy; fi”
This can cause some problems when you try to switch the repository branch you're deploying from, say, to roll back to a tag, or deploy from a radically different stable branch where svn up won't run properly because of deleted directories etc.

So, before you release from a tag, you have to remember to delete the cached copy checked out on the servers. Capistrano's invoke comes in handy for these situations:
~> cap invoke COMMAND="rm -rf /deploy/myproject/shared/cached-copy"
You might want to also remember to delete the cached-copy *after* you deploy too, in case the next person who comes along doesn't realize that you deployed from a strange location.

No comments:

Post a Comment