Daniel Nolan
Daniel Nolan

Reputation: 41

Deploying the same codebase w/ slight variances to multiple servers with capistrano and git

We have a codebase that we sell to multiple clients. We use git for version control and Capistrano for automated deployments.

There are slight variances between the deployments such as design layouts, css files, logos, and config files like CAKEPHP's front controller which has the paths to the app and cakephp directories in it.

We currently have main master/staging branches for the project. We develop in topic branches, once the topic branch is ready to be merged into the codebase, we merge the topic branch into staging and deploy to our main staging server.

Once the code has been tested on staging and we are ready to release we merge staging into master. Then we have to deploy to the different client servers. We have a staging and production server for each client.

Currently we have a staging and production branch for each client and we deploy to each server from each separate branch. This is becoming painful as we have to merge our main project branch into the staging/production branches for each client and the run cap deploy for each server.

How can we just deploy to the clients servers from one branch, but include the different files needed for each clients server to work and look proper?

Upvotes: 4

Views: 581

Answers (1)

Reuben
Reuben

Reputation: 4266

I used capistrano/ext/multistage to do something similar.

When delivering to production, I can use cap prod deploy, and when delivering to test, I can use cap test deploy.

My Capfile looks like

require 'rubygems'
require 'railsless-deploy'
require 'capistrano/ext/multistage'

set :stages, %w(staging)

load 'config/deploy' 

In config/deploy.rb is my main deploy script.

In config/deploy I have a script for each environment. i.e. prod.rb and test.rb.

These environment specific scripts contain variables specific to those environments. Usually, I specify things like branch, user, app, deploy_to, copy_remote_dir, copy_exclude and any other variables that I need to use in the main config/deploy.rb that might be different between environments.

Some variables may not appear in all environment specific scripts, so deploy.rb checks for their existence before using them. i.e.

# Link upload area
if exists?(:uploads)
    run "rm -rf #{current_release}#{uploads}"
    run "ln -s #{shared_path}#{uploads} #{current_release}#{uploads}"
end

Sometimes, I'll copy an environment specific config, using the staging name

# Copy config
run "cp #{current_release}/config/#{stage}/app/config.php #{current_release}/src/app"

I should mention I use git and a copy strategy for my deploy_via. As a result, all configs get uploaded to the servers in out of the way directories, and then copied in to place. Your mileage may vary.

Find out more about the multistage extension for capirstrano here : http://weblog.jamisbuck.org/2007/7/23/capistrano-multistage

Upvotes: 1

Related Questions