Vlad the Deployer, 比Capistrano更简单的自动化部署工具

全部转载自 午夜盧比人Midnight Blog
http://blog.pbg4.org/2007/11/6/vlad-the-deployer

Ruby on Rails對全世界最大的貢獻不在於產生多少容易維護的程式碼,而在於把簡潔易用的觀念深植人心。

因為程式員透過簡單易用的Ruby on Rails開發各種程式,於是創造出Twitter、Radiant、Mephisto等傑出的應用,而Vlad the Deployer則是另一個強調簡單易用的傑出工具。

相較於威力強大的Capistrano,Vlad the Deployer是一套極為簡單的自動化部署工具,特別是當您使用Mongrel, Apache, Subversion環境時,更是輕鬆愉快。

那麼,Vlad the Deployer可以幫助我們做什麼?

透過簡單的設定,所有Ruby on Rails的安裝部署工作只需打一行字,Vlad the Deployer就可以幫您把遠端機器上的production程式備份、從SVN拉下最新的程式、調整資料庫、重新啟動web server、重新啟動Mongrel cluster。Capistrano當然也可以達到相同的目的,但是他的設定實在太過麻煩。

Vlad the Deployer的安裝步驟如下:
第一、請在本地與遠端機器都裝上Vlad the Deployer:

sudo gem install vlad --include-dependencies

再來,請切換到本地的rails project目錄,修改Rails project的Rakefile,並加上這兩行字:

require 'vlad'
Vlad.load

接著,在config目錄下新增一個deploy.rb,做些環境設定:

set :user,        "my_admin" # your loggin username to production server.
set :domain,      "#{user}@my_production" # your production server.
set :deploy_to,   "/home_to_my_rails" # your home to rails production source
set :repository,  "http://svn.my_repository/svn/stable/" # your svn repository server

輸入以下指令幫您完成全部工作:

rake vlad:setup vlad:update vlad:migrate vlad:start

這樣就結束了嗎?理論上,遠端機器的環境跟本地開發環境的作業系統相同、PATH設定相同,而且資料庫帳號密碼都完全相同,這樣就結束了,很可惜地,往往是不相同的。

萬一您下rake vlad:setup指令之後,遇到command not found: mongrel_rails的錯誤訊息,那表示遠端機器跟您本地機器的作業系統或環境變數不同。那麼,請在遠端機器設幾個symbolic link,因為/usr/bin是大多數unix-base主機都有的執行路徑:

sudo ln -s /var/lib/gems/1.8/bin/mongrel_rails /usr/bin/mongrel_rails
sudo ln -s /var/lib/gems/1.8/bin/rake /usr/bin/rake

然後重新執行:

rake vlad:setup

如果資料庫帳號密碼不同的話,請修改遠端機器的設定檔config/database.yml。

第二、執行程式更新與資料庫更新,並啟動伺服器:

rake vlad:update vlad:migrate vlad:start

第三、沒有第三步了。

你可能感兴趣的:(SVN,capistrano,Ruby,subversion,Rails)