Sample Capistrano Deployment Script
For now, this script is based on SVN conventions
The primary purpose of this script, besides automating deployment is:
- Automated tagging of releases
- Deployment of tests to testing servers (for A/B testing)
- Deployment of latest release to staging environment
- Notification with commit comments, diffs, etc. for each new release
I've recently began setting up automated deployment for my various PHP apps to testing, staging & development servers. Namely, sites such as WhiteFence.com, ElectricityTexas.com and several other client sites.
I'm moving all of my projects to Git, so this script will be modified accordingly.
How it works
There are 3 files involved with deployment:
Defines the repositores, servers, and notification email, as well as how logging is handled.
Class that actually performs the deployment. This is highly based on convention.
expectscript that performed many of the SVN operations. This is because various SVN commands sent false EOF signals to Python (most likely because of child processes spawning) and had to be caught via
How to use it
Setup SVN Project Structure
Many of the commands from the script are based on folder structure, which should be as follows:
my-project/ trunk/ branches/ tags/ tests/
# deploy my-project
Deploy to staging environment
# deploy --stage my-project
Deploy tests to testing tier
# deploy --tests my-project
Deploy tests to staging tier
# deploy --tests --stage my-project
What's going on behind the scenes?
When deploying to production/stage
- Script checks latest revision of
trunk, and latest
- If the
trunkhas been modified since last
tag, a new
tagis made at that revision.
- Script decides testing tier based on the presence of
- Capistrano script is created for deploying the latest
tagto the proper tier.
- Capistrano script is ran:
- Remote deployment folder is initialized.
- Old releases are cleaned up.
- New release is exported to
/releases& symlinked to
/currentfolder on tier.
- If there is an error, Capistrano performs a
When deploying tests...
The process is the same as above, except that:
- Tests in the
/testsfolder are not tagged, and are simply deployed as-is.
- Tests are spread across the testing tier. For example, if there are 2 tests and 4 servers,
Test Awill be placed on servers 1 & 2, while
Test Bwill be placed on servers 3 & 4.