Deploying Mint with Capistrano
Posted by Pat Nakajima on May 16, 2007 in Ruby or Rails.Requirements
- A legally obtained Mint license
- A Ruby on Rails app
- Capistrano 2 preview 2 (Read more about it on Jamis Buck’s blog)
- Knowledge of the command line
# Capistrano recipe for deploying Mint. Based on code from Geoffrey Grosenbach's
# post on the Mint forums: http://haveamint.com/forum/after_dinner/666/deploy_mint_with_capistrano#post_4108
# Slight modifications by Pat Nakajima.
require 'capistrano/recipes/deploy/strategy'
namespace :deploy do
namespace :mint do
# Set your svn user here
set :user, "deploy"
# This should be the path to your app's shared folder. You need to keep a copy
# of Mint's db.php configuration file in the config/ directory. This will be
# copied to your Mint deployment so as to avoid transmitting that material.
set :app_shared, "/var/www/apps/#{application}/shared"
# Where is Mint? Set the location of Mint in your repository.
set :mint_repository, "http://your_repository/mint"
# Where do you want Mint? I put mine in a separate mints folder.
# Your mileage may vary.
set :mint_deploy_to, "/var/www/mints/#{application}"
# This can be commented out after the first deployment if you wish to use another
# strategy for deployment.
set :mint_deploy_via, :checkout
before "deploy:mint:update_code", "deploy:mint:set_vars"
# Sets variables to traditional names
task :set_vars do
set :repository, mint_repository
set :deploy_to, mint_deploy_to
set :deploy_via, mint_deploy_via
end
# TODO Refactor to not rewrite default deployment task
desc "Deploy Mint stats tracking."
task :default do
update_code
symlink
end
task :update_code, :except => { :no_release => true } do
on_rollback { run "rm -rf #{release_path}; true" }
strategy.deploy!
finalize_update
end
# Overridden since PHP doesn't have some of the Rails directories
task :finalize_update, :except => { :no_release => true } do
# Make directories writeable by the deployment user's group
run "chmod -R g+w #{release_path}" if fetch(:group_writable, true)
end
# Symlinks
task :symlink, :except => { :no_release => true } do
on_rollback { run "rm -f #{current_path}; ln -s #{previous_release} #{current_path}; true" }
run "rm -f #{current_path} && ln -s #{release_path} #{current_path}"
end
task :restart, :roles => :app do
# Do nothing
end
# Copy db files
after "deploy:mint:update_code", "deploy:mint:copy_db_config"
task :copy_db_config, :roles => :app do
run "cp #{app_shared}/config/db.php #{release_path}/config/db.php"
run "chmod -R 775 #{release_path}/config/db.php"
end
# Post-deploy cleanup
task :after_default, :roles => :app do
# Keep last 5 releases
deploy.cleanup
end
end
end
Usage
Once you add it to your Capfile, you can run the following command to deploy:cap deploy:mint
Notes
There are a few “gotchas” for this recipe:- Apache configuration is up to you for the time being. Setting up a virtualhost should be as easy as adding one to your apache cong/apps directory. I’ll write more on this later.
- You need to have a copy of Mint’s db.php file in your Rails app’s shared/config folder. This is intended to limit the number of times you have to send that kind of info.
- You might have to finagle the permissions for your deploy folder.
In the Rails development community, you often hear the notion of opinionated software. Well this recipe, for now at least, is probably the most close-minded thing you’ve seen in a while. Still, I’ve been using it to deploy Mint for this blog, so I know it works, albeit with above stipulations.

Subscribe to devthatweb!
Sorry, but comments are closed on this blog after 30 days.