&tag(Capistrano);
*目次 [#j8aad278]
#contents
*参考情報 [#j24c1780]
-[[Rails]]
-[[Rails3]]

*インストール [#i4eb383d]
-gemでインストール
 gem install capistrano capistrano_colors

*デプロイ用の設定ファイルの作成 [#v883c334]
-自分のRailsアプリのフォルダに移動しcapifyコマンドを実行する。
 cd ~/myapp
 capify .

-config/deploy.rbというファイルが作成される。
*設定ファイルの編集 [#v03db165]
-deploy.rbを編集。
-deploy.rbを編集。以下のようなテンプレートが書きだされている。
#pre{{
set :application, "set your application name here"
set :repository,  "set your repository location here"

# set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based o\
n known version control directory names
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`

role :web, "your web-server here"                          # Your HTTP server, Apache/etc
role :app, "your app-server here"                          # This may be the same as your `Web` ser\
ver
role :db,  "your primary db-server here", :primary => true # This is where Rails migrations will ru\
n
role :db,  "your slave db-server here"

}}
-:application アプリケーション名。
-:repository SCMのリポジトリ。

**lsタスクの作成 [#s15ac9e4]
-[[Capistranoを使ったデプロイ | アライドアーキテクツ エンジニアブログ:http://tech.aainc.co.jp/archives/3773]]にあるように、まずは、サーバー上でlsを実行するサンプルを作るのがわかりやすいかも。
-deploy.rbを編集
#pre{{
# sshのユーザー名
set :user, "demouser"
# ssh公開鍵設定
set :ssh_options, :port=>11111 :forward_agent=>false, :keys=>"~/.ssh/id_rsa_demo", :passphrase => "demopassphrase"
# sudoするかどうか(sudoしないほうが普通らしい)
set :use_sudo, false
# デプロイサーバ定義
role :web, "demohost"

# lsコマンド実行タスク
task :list  do
    run "ls"
end
}}
-以下のコマンドで実行。
 cap list
-rubyのNet::SSHというライブラリを使い、ssh経由でログインしてlsを実行するイメージ。パスフレーズを直書きすることになるのが気になる場合、毎回パスフレーズを入力する / ssh-agentを使う(起動ごとに1回は入力必要) / パスフレーズなしのキーを使うなどの回避方法がある。調べた限り、Macのキーチェインを使う方法はなさそうだった。


**デプロイ実行 [#ie76c58d]
-deploy.rbに設定を追加する
#pre{{
set :user, "demouser"
# ssh公開鍵設定
set :ssh_options, :port=>11111 :forward_agent=>false, :keys=>"~/.ssh/id_rsa_demo", :passphrase => "demopassphrase"
# sudoするかどうか(sudoしないほうが普通らしい)
set :use_sudo, false

# アプリケーション名
set :application, "demoapp"
# scmの指定
set :scm ,:git
# gitリポジトリ
set :repository, "git@gitserver:demoapp.git"
# gitブランチ名
set :branch, :master
# デプロイ方式。:copyの場合手元でソースを最新にしてからコピーする。
# :checkoutの場合サーバー上でgitリポジトリに接続して更新するらしい。
set :deploy_via , :copy
# deploy先ディレクトリ(サーバーのディレクトリ)
set :deploy_to,  "/var/www/html/demo"

# デプロイサーバ定義
role :web, "demohost"

# lsコマンド実行タスク
task :list  do
    run "ls"
end
}}
-デプロイ実行の準備(初回やデプロイ先がかわるなどのごとに実行する必要あり)。
 cap deploy:setup
-デプロイ実行
 cap deploy
-サーバー上にファイルがあるかどうか確認する。


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS