-->
./
<!-- フラ&#65533;ュが見れな&#65533;のためにここに何か書&#65533; --> フラ&#65533;ュがインス&#65533;&#65533;ルされて&#65533;&#65533;たいで&#65533;&#65533;&#65533;

2010年01月14日

capistranoを使ったRailsアプリのデプロイ

実行環境はUbuntu9.10。デプロイ先は、さくらインターネットのサーバ(FreeBSD 7.1-RELEASE-p8 (SAKURA11S))。

 以前にも挑戦したことがあったのですが、うまくいかず。1月11日にようやくうまく出来ました。gitを使っています。理解がややこしかったのですが、gitを実行するのはリモート環境になるみたいです。

インストール:
sudo gem install capistrano --include-dependencies

管理除外ファイルの指定:.gitignoreの作成と編集
RAILS_ROOT/.gitignoreの内容
log/*.log
tmp/**/*



対象アプリのトップディレクトリ(RAILS_ROOT)で、
capify .
を実行。

生成された、./config/deploy.rbを編集。(別途sshの設定が必要)
set :application, "アプリ名"
set :user, 'hirono-hideki-01'
set :domain, 'hirono-hideki-01.sakura.ne.jp'
set :repository,  "#{user}@#{domain}:git/#{application}.git"
set :deploy_to, "/home/#{user}/rails-deploy/#{application}"

# distribute your applications across servers (the instructions below put them
# all on the same server, defined above as 'domain', adjust as necessary)    
role :app, domain                                                            
role :web, domain                                                            
role :db, domain, :primary => true                                           

# you might need to set this if you aren't seeing password prompts
# default_run_options[:pty] = true                               

# As Capistrano executes in a non-interactive mode and therefore doesn't cause
# any of your shell profile scripts to be run, the following might be needed 
# if (for example) you have locally installed gems or applications.  Note:
# this needs to contain the full values for the variables set, not simply
# the deltas.
#default_environment['PATH']='/usr/local/bin:/usr/bin:/bin'
#default_environment['GEM_PATH']='/usr/lib/ruby/gems/1.8'

# miscellaneous options
set :deploy_via, :remote_cache
set :scm, 'git'
set :branch, 'master'
set :scm_verbose, true
set :use_sudo, false

# task which causes Passenger to initiate a restart
namespace :deploy do
  task :restart do
    run "touch #{current_path}/tmp/restart.txt"
  end
end

セットアップ:
cap deploy:setup

初回デプロイ:
cap deploy:cold

二回目以降のデプロイ:
cap deploy

 うまくいけば、デプロイ先はこんな感じになります。
rails-deploy                 
`-- kokuhatu                 
    |-- current -> /home/hirono-hideki-01/rails-deploy/kokuhatu/releases/20100114081510
    |-- releases                                                                      
    |   |-- 20100111064007                                                            
    |   |   |-- Capfile                                                               
    |   |   |-- README                                                                
    |   |   |-- REVISION                                                              
    |   |   |-- Rakefile                                                              
    |   |   |-- app                                                                   
    |   |   |   |-- controllers                                                       
    |   |   |   |   |-- application.rb                                                
    |   |   |   |   |-- application_controller.rb                                     
    |   |   |   |   |-- db1s_controller.rb                                            
    |   |   |   |   `-- ex1_controller.rb                                             
    |   |   |   |-- helpers                                                           
    |   |   |   |   |-- application_helper.rb                                         
    |   |   |   |   |-- db1s_helper.rb                                                
    |   |   |   |   `-- ex1_helper.rb                                                 
    |   |   |   |-- models                                                            
    |   |   |   |   `-- db1.rb                                                        
    |   |   |   `-- views                                                             
    |   |   |       |-- db1s                                                          
    |   |   |       |   |-- edit.html.erb                                             
    |   |   |       |   |-- index.html.erb                                            
    |   |   |       |   |-- new.html.erb                                              
    |   |   |       |   `-- show.html.erb                                             
    |   |   |       |-- ex1                                                           
    |   |   |       |   |-- index.html.erb                                            
    |   |   |       |   `-- view.html.erb                                             
    |   |   |       `-- layouts                                                       
    |   |   |           `-- db1s.html.erb                                             
    |   |   |-- config                                                                
    |   |   |   |-- boot.rb                                                           
    |   |   |   |-- database.yml                                                      
    |   |   |   |-- deploy.rb                                                         
    |   |   |   |-- environment.rb                                                    
    |   |   |   |-- environments                                                      
    |   |   |   |   |-- development.rb                                                
    |   |   |   |   |-- production.rb                                                 
    |   |   |   |   `-- test.rb                                                       
    |   |   |   |-- initializers                                                      
    |   |   |   |   |-- backtrace_silencers.rb                                        
    |   |   |   |   |-- inflections.rb                                                
    |   |   |   |   |-- mime_types.rb                                                 
    |   |   |   |   |-- new_rails_defaults.rb                                         
    |   |   |   |   `-- session_store.rb                                              
    |   |   |   |-- locales                                                           
    |   |   |   |   `-- en.yml                                                        
    |   |   |   `-- routes.rb                                                         
    |   |   |-- db                                                                    
    |   |   |   |-- development.sqlite3                                               
    |   |   |   |-- migrate                                                           
    |   |   |   |   `-- 20100111015409_create_db1s.rb                                 
    |   |   |   |-- schema.rb                                                         
    |   |   |   `-- seeds.rb                                                          
    |   |   |-- deploy.rb.back                                                        
    |   |   |-- doc                                                                   
    |   |   |   `-- README_FOR_APP                                                    
    |   |   |-- log -> /home/hirono-hideki-01/rails-deploy/kokuhatu/shared/log        
    |   |   |-- public                                                                
    |   |   |   |-- 404.html                                                          
    |   |   |   |-- 422.html                                                          
    |   |   |   |-- 500.html                                                          
    |   |   |   |-- dispatch.cgi                                                      
    |   |   |   |-- dispatch.fcgi                                                     
    |   |   |   |-- dispatch.rb                                                       
    |   |   |   |-- favicon.ico                                                       
    |   |   |   |-- images                                                            
    |   |   |   |   `-- rails.png                                                     
    |   |   |   |-- index.html                                                        
    |   |   |   |-- javascripts                                                       
    |   |   |   |   |-- application.js                                                
    |   |   |   |   |-- controls.js                                                   
    |   |   |   |   |-- dragdrop.js                                                   
    |   |   |   |   |-- effects.js                                                    
    |   |   |   |   `-- prototype.js                                                  
    |   |   |   |-- robots.txt                                                        
    |   |   |   |-- stylesheets                                                       
    |   |   |   |   `-- scaffold.css                                                  
    |   |   |   `-- system -> /home/hirono-hideki-01/rails-deploy/kokuhatu/shared/system
(以下省略)

[sakura ~] % ls rails-deploy/kokuhatu/releases/
20100111064007 20100111064904 20100111065638 20100111081150 20100114080819
20100111064627 20100111065248 20100111071405 20100114080439 20100114081510

 currentが最新版へのシンボリックリンクになっているみたいです。なお、リビジョンが日付と時刻で名前付けされていますが、世界標準時間になっているみたいです。日本時間は+9時間だと思います。




Powered by ScribeFire.

posted by hirono at 18:02| Comment(0) | TrackBack(0) | Rails
この記事へのコメント
コメントを書く
お名前:

メールアドレス:

ホームページアドレス:

コメント:

この記事へのトラックバックURL
http://blog.sakura.ne.jp/tb/34740894

この記事へのトラックバック