SlideShare a Scribd company logo
Capistrano実践Tips集2009/09/07高倉 利明
目次これだけは入れとけ!便利なgemこう記述しろ!設定ファイル意外と知らない?注意点
1.これだけは入れとけ!  便利なgem・capistrano_colors・capistrano-ext※インストール方法は割愛。 ググれ!
capistrano_colors何ができる?->capistranoの実行コマンド、 コメントなどを色づけしてくれる。 地味だけど便利。使用後使用前
capistrano-ext何ができる?->環境に応じたcapistrano 設定を差分ファイルで 上書きする事が可能になる。
capistrano-extフォルダ構成Root└ /config   └ deploy.rb (共通設定)   └/deploy   └staging.rb(staging差分)   └production.rb(production差分)
capistrano-ext環境ごとの「user」を置き換えたいなら。。。#config/deploy.rbset:user,     “hogehoge“#config/deploy/staging.rbset:user,     “fugafuga“#config/deploy/production.rbset:user,     “piyopiyo“
capistrano-extステージング環境へデプロイ本番環境へデプロイ$ cap staging deploy$ cap production deploy
2.こう記述しろ!設定ファイル(1) deploy.rbデフォルト記述(2) Passengerとの連携設定(3) パスワードなどの動的入力(4) プッシュ式デプロイ
(1) deploy.rbデフォルト記述Q.deploy.rbファイル書くの面倒だよ!  何かいい手ない?A.APサーバで以下のデフォルトルールに従えば~Railsの実行ユーザは「app」アプリ設置場所は「/u/apps」「app」ユーザに「/u/apps」以下のファイル作成・削除権限を与えるサーバに公開鍵などでの パスワード無しsshログイン可能
(1) deploy.rbデフォルト記述7行で済みます。#config/deploy.rbset :application,      “test “set :scm,                  “subversion“set :scm_user,         “hogehoge“set :scm_password, “fugafuga“role :web, “web.test.com“role :app,  “app.test.com“role :db,    “db.test.com “
(2) Passengerとの連携設定Q.CapistranoをPassengerと 連携させたいんだけど、 何か記述しておいた方が良い?A.Passengerは「tmp/restart.txt 」 にファイルがあると、自動的に そのアプリのみ再読み込みするので~
(2) Passengerとの連携設定以下のように再起動タスクを記述しておくと便利。#config/deploy.rbnamespace :deploy do  task :restart, :roles => :app do    run "touch #{current_release}/tmp/restart.txt”end# 以下タスクはApache自体の起動/停止に使用。複数アプリを# 単一Apacheで公開している場合は使用しない方が良い task :start, :roles => :appdo   run "sudo /etc/rc.d/init.dhttpd start "end task :stop, :roles => :app do    run "sudo /etc/rc.d/init.dhttpd stop "endend
(3) パスワードなどの動的入力Q.capistranoでセキュリティ要件が厳しいとき、 以下のような要望が出てくる。 さあどうしよう?セキュリティ要件でパスワードを設定ファイル上にベタ書きするのはNGSubversionサーバのパスワードをデプロイ担当者ごとに使い分けたいAPサーバのパスワードをデプロイ担当者ごとに使い分けたい...etc
(3) パスワードなどの動的入力A.Capistrano::CLIを使用すれば 動的入力できる!#config/deploy.rb# 入力(エコーバックあり)set :scm_userdo  Capistrano::CLI.ui.ask (“scm user:”)end# パスワード (エコーバックなし)set :scm_passworddo  Capistrano::CLI.password_prompt(“scm pass:”)end
(4)プッシュ式デプロイQ.セキュリティ上APサーバからSubversionリポジトリに アクセス出来ないんだって! これではデプロイできない。。。助けて!APサーバSubversionサーバCapistrano実行サーバ
(4)プッシュ式デプロイA. 「deploy_via, :copy」オプションを 使うことで、プッシュ式デプロイを行いましょう。#config/deploy.rbset :deploy_via, :copy
(4)プッシュ式デプロイdeploy_via:copyを設定すると 1. capistrano実行サーバにチェックアウト 2. APサーバにgzip圧縮してscpアップロード 3. APサーバ上で展開して配置という流れでデプロイを行う事ができます。APサーバ③②①Capistrano実行サーバSubversionサーバ
3.意外と知らない?注意点・role:dbの意味・ユーザのアップロード画像などは どこに置くべき?
role:dbの意味Q. role :dbに指定するサーバは、DBサーバで良いんだよね?A. いいえ。 ×:DBサーバ ○:Migrationを実行するサーバ (ほとんどの場合APサーバと同じで良い)
ユーザのアップロード画像置き場所Q.ユーザがアップロードした画像とか docファイルとかって、 どこに配置しておくのが良いのかな?
ユーザのアップロード画像置き場所A.shared/system以下にに置き、capistranoで public以下へシンボリックリンクを 張りましょう。myapp └ current └ releases---20091122010101(最新アプリ) └ shared                 └log   └ log                   └public   └ system                  └ user_img        └ user_imgシンボリックリンクシンボリックリンクシンボリックリンク
ユーザのアップロード画像置き場所シンボリックリンクを張る例:#config/deploy.rbafter “deploy”, “deploy:link_images”namespace(:deploy) do task :link_imagesdo   run <<-CMDcd #{release_path} &&ln –nfs #{shared_path}/user_images       #{release_path}/public/user_images    CMDendend
ご静聴ありがとうございました。

More Related Content

PDF
080718 Liberty Alliance Technical Seminar
Hiroki Itoh
 
PDF
田町deナイト 質問集
Yoji Kanno
 
PPT
03 Getting Started
Makoto Ohnami
 
PDF
Road To Major(?)
Takeshi Kakeda
 
PPTX
[Regional Scrum Gathering Tokyo 2021] Scrum with OODA loop
Woohyeok Kim
 
PPTX
セキュリティとアジャイル開発のいい関係について考える
Makoto Iguchi
 
PDF
CSS Nite In Ginza, Vol.36
Nobuya Sato
 
PPTX
How to balance between Security and Agile Development
Makoto Iguchi
 
080718 Liberty Alliance Technical Seminar
Hiroki Itoh
 
田町deナイト 質問集
Yoji Kanno
 
03 Getting Started
Makoto Ohnami
 
Road To Major(?)
Takeshi Kakeda
 
[Regional Scrum Gathering Tokyo 2021] Scrum with OODA loop
Woohyeok Kim
 
セキュリティとアジャイル開発のいい関係について考える
Makoto Iguchi
 
CSS Nite In Ginza, Vol.36
Nobuya Sato
 
How to balance between Security and Agile Development
Makoto Iguchi
 

Viewers also liked (20)

PDF
Redmineチケットによるプロジェクト火消し戦略!
TrinityT _
 
PDF
ChefとCapistranoの境界線 (Chef Casual Talks Vol.1) #eytokyo #opschef_ja
Masahiro NAKAYAMA
 
PDF
Goとテスト
Takuya Ueda
 
PDF
Vagrant + Puppet
Gustavo Chaves
 
PDF
Go入門
Takuya Ueda
 
PDF
意識の低い自動化
greenasparagus
 
PPTX
[社内勉強会]ELBとALBと数万スパイク負荷テスト
Takahiro Moteki
 
PPT
The Wisdom Of The Cross
John Gonzalez
 
PPT
Ogt 2006
ham97
 
PPTX
Diete e Social Network: analisi delle conversazioni on line
Reputation Manager
 
PPTX
La cruz del cambio
John Gonzalez
 
PPTX
Digital Design Trends
Louise McGregor
 
PDF
Russia Chapter for Getting the Deal Through Real Estate 2010 edition
Andrey Zelenin
 
PPT
The cold war heats up
ham97
 
PPTX
2. De trabajador a colaborador
Universidad Autónoma de Ica
 
PPTX
Costruire la reputazione tra università e impresa
Reputation Manager
 
PPT
Giroidea - Our method
GIROIDEA Avanguardia Comunicativa
 
PDF
Elezioni sindaco 2016: la reputazione on line dei candidati di Milano e Roma ...
Reputation Manager
 
PPT
People in societies and history
ham97
 
Redmineチケットによるプロジェクト火消し戦略!
TrinityT _
 
ChefとCapistranoの境界線 (Chef Casual Talks Vol.1) #eytokyo #opschef_ja
Masahiro NAKAYAMA
 
Goとテスト
Takuya Ueda
 
Vagrant + Puppet
Gustavo Chaves
 
Go入門
Takuya Ueda
 
意識の低い自動化
greenasparagus
 
[社内勉強会]ELBとALBと数万スパイク負荷テスト
Takahiro Moteki
 
The Wisdom Of The Cross
John Gonzalez
 
Ogt 2006
ham97
 
Diete e Social Network: analisi delle conversazioni on line
Reputation Manager
 
La cruz del cambio
John Gonzalez
 
Digital Design Trends
Louise McGregor
 
Russia Chapter for Getting the Deal Through Real Estate 2010 edition
Andrey Zelenin
 
The cold war heats up
ham97
 
2. De trabajador a colaborador
Universidad Autónoma de Ica
 
Costruire la reputazione tra università e impresa
Reputation Manager
 
Giroidea - Our method
GIROIDEA Avanguardia Comunicativa
 
Elezioni sindaco 2016: la reputazione on line dei candidati di Milano e Roma ...
Reputation Manager
 
People in societies and history
ham97
 
Ad

Recently uploaded (20)

PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
The Future of Artificial Intelligence (AI)
Mukul
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
Ad

Capistrano 実践Tips集