Deploying Joomla using Capistrano 2.0
Written on August 14, 2007 by ceefour
Who said Capistrano is for Ruby on Rails only?
That’s probably the major tagline of the whole Capistrano 2.0 saga. You can use it to deploy PHP, Django, or not doing any deployment at all. Let me demonstrate, this time using Joomla:
Capistrano adalah library/tool yang digunakan untuk meng-online-kan aplikasi Ruby on Rails, tapi bisa juga digunakan untuk aplikasi PHP, misalnya Joomla:
ceefour@ojalanow:~/project/layout_mania/trunk$ cap deploy
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
* executing "svn checkout -q --username ceefour --no-auth-cache -r11 http://tools.assembla.com/svn/layout_mania/trunk /home/rainbow/apps/layout_mania/releases/20070814160555 && (echo 11 > /home/rainbow/apps/layout_mania/releases/20070814160555/REVISION)"
servers: ["rainbowpurple.com"]
[rainbowpurple.com] executing command
command finished
* executing `deploy:finalize_update'
* executing "chmod -R g+w /home/rainbow/apps/layout_mania/releases/20070814160555"
servers: ["rainbowpurple.com"]
[rainbowpurple.com] executing command
command finished
triggering after callbacks for `deploy:finalize_update'
* executing `deploy:symlink_secret'
* executing "ln -s /home/rainbow/apps/layout_mania/secret /home/rainbow/apps/layout_mania/releases/20070814160555/secret"
servers: ["rainbowpurple.com"]
[rainbowpurple.com] executing command
command finished
* executing `deploy:use_live_configuration'
* executing "cp -f /home/rainbow/apps/layout_mania/releases/20070814160555/joomla/configuration.php.live /home/rainbow/apps/layout_mania/releases/20070814160555/joomla/configuration.php"
servers: ["rainbowpurple.com"]
[rainbowpurple.com] executing command
command finished
* executing `deploy:symlink_cache'
* executing "rm -rf /home/rainbow/apps/layout_mania/releases/20070814160555/joomla/cache && ln -s /home/rainbow/apps/layout_mania/shared/cache /home/rainbow/apps/layout_mania/releases/20070814160555/joomla/cache"
servers: ["rainbowpurple.com"]
[rainbowpurple.com] executing command
command finished
* executing `deploy:symlink'
* executing "rm -f /home/rainbow/apps/layout_mania/current && ln -s /home/rainbow/apps/layout_mania/releases/20070814160555 /home/rainbow/apps/layout_mania/current"
servers: ["rainbowpurple.com"]
[rainbowpurple.com] executing command
command finished
** transaction: commit
* executing `deploy:restart'
The result? layout-mania.humblia.com. Below is the source code of deploy/config.rb used to deploy this Joomla app.
Hasilnya? layout-mania.humblia.com. Di bawah ini adalah source code dari file konfigurasi Capistrano deploy/config.rb yang digunakan untuk aplikasi ini.
set :application, "layout_mania"
set :repository, "http://tools.assembla.com/svn/layout_mania/trunk"
# If you aren't deploying to /u/apps/#{application} on the target
# servers (which is the default), you can specify the actual location
# via the :deploy_to variable:
set :deploy_to, "/home/rainbow/apps/#{application}"
set :user, "rainbow"
set :scm_username, 'ceefour'
set :use_sudo, false
set :cache_path, "#{shared_path}/cache"
set :media_path, "#{shared_path}/media"
# If you aren't using Subversion to manage your source code, specify
# your SCM below:
# set :scm, :subversion
role :app, "rainbowpurple.com"
role :web, "rainbowpurple.com"
role :db, "rainbowpurple.com", :primary => true
after 'deploy:finalize_update', 'deploy:symlink_secret'
after 'deploy:finalize_update', 'deploy:use_live_configuration'
after 'deploy:finalize_update', 'deploy:symlink_cache'
namespace :deploy do
# Overwritten to provide flexibility for people who aren't using Rails.
task :setup, :except => { :no_release => true } do
dirs = [deploy_to, releases_path, shared_path, cache_path, media_path]
dirs += %w(system).map { |d| File.join(shared_path, d) }
run "umask 02 && mkdir -p #{dirs.join(' ')}"
end
# Also overwritten to remove Rails-specific code.
task :finalize_update, :except => { :no_release => true } do
run "chmod -R g+w #{release_path}" if fetch(:group_writable, true)
end
# Each of the following tasks are Rails specific. They're removed.
task :migrate do
end
task :migrations do
end
task :cold do
end
task :start do
end
task :stop do
end
# Do nothing (To restart apache, run 'cap deploy:apache:restart')
task :restart do
end
task :use_live_configuration, :roles => :app do
run "cp -f #{release_path}/joomla/configuration.php.live #{release_path}/joomla/configuration.php"
end
task :symlink_cache, :roles => :app do
run "rm -rf #{release_path}/joomla/cache && ln -s #{cache_path} #{release_path}/joomla/cache"
end
task :symlink_secret, :roles => :app do
run "ln -s #{deploy_to}/secret #{release_path}/secret"
end
end
namespace :db do
desc "Overwrite the remote database with local database."
task :push_force, :roles => :db do
system "mysqldump --opt rainbow_layoutmania | bzip2 > /tmp/rainbow_layoutmania.sql.bz2"
system "rsync -vPa /tmp/rainbow_layoutmania.sql.bz2 rainbowpurple.com:tmp/"
run "bunzip2 -dc /home/rainbow/tmp/rainbow_layoutmania.sql.bz2 | mysql -u rainbow_layoutma -p`cat #{deploy_to}/secret/db_password` rainbow_layoutmania"
run "rm -f /home/rainbow/tmp/rainbow_layoutmania.sql.bz2"
system "rm -f /tmp/rainbow_layoutmania.sql.bz2"
end
desc "Optimize remote database."
task :optimize, :roles => :db do
run "mysqlcheck --analyze --repair --optimize --user=rainbow_layoutma --password=`cat #{deploy_to}/secret/db_password` rainbow_layoutmania"
end
end
Interested? Unfortunately this isn’t a tutorial. Look more on the resources below:
Tertarik? Sayang sekali ini bukan tutorial, coba cari informasi lebih lanjut di:
- Capistrano 2.0 official site
- Capistrano Wiki
- Deploy any project using Capistrano 2
- Automate the deployment of any PHP project using Capistrano 2.0
- Jamis Buck’s blog (creator, lead developer, and chief inventor of Capistrano
) - Capistrano and the Rails Application Lifecycle book from O’Reilly
Note: Sorry for dual-language posting, any better suggestion?


Add New Comment
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Add New Comment
Trackbacks
(Trackback URL)
August 22, 2007 at 3:38 am
[...] Capistrano-like Deployment Tool I’m sure you’ve heard a lot about capistrano. It’s a very cool and handy tool. But ...