ã¿ãªããããã«ã¡ã¯ã ä»æ¥ãç§ã¯çŽ æŽãããå±éèœåãæã€ã«ãã¹ãã©ãŒãã«ã€ããŠããäžåºŠã話ããããšæããŸãã
Capistranoã¯ãäž»ã«Webã¢ããªã±ãŒã·ã§ã³ã«äœ¿çšãããè€æ°ã®ãµãŒããŒã§ã¹ã¯ãªãããå®è¡ããããã®ãªãŒãã³ãœãŒã¹ããŒã«ã§ããããšãæãåºããŠãã ããã 1ã€ä»¥äžã®WebãµãŒããŒã«æ°ããããŒãžã§ã³ãå±éããããã»ã¹ãèªååã§ããããŒã¿ããŒã¹ã®å€æŽãªã©ã®ã¿ã¹ã¯ã®ãµããŒããå«ãŸããŸãã
Capistranoã¯Rubyã§æžãããŠãããRuby on Railsãã¬ãŒã ã¯ãŒã¯ã®ãã¢ãžã¥ãŒã«ãïŒãŸãã¯ã³ã³ããŒãã³ããã©ã¡ããåªããŠãããããããŸããïŒã§ãã
ãã®ãããã¯ã®å€§éšåã¯ããããžã§ã¯ãããŒãžããgithubãžã®
ãã¥ãŒããªã¢ã«ã®ç¿»èš³ã§ãããããã€ãã®è¿œå ãå€æŽãããã³phpïŒãŸãã¯ãnot RoRãïŒã«åºæã®ç¥èªãè¿œå ãããŠããŸãã è€æ°ã®ãµãŒããŒãšããŒã¿ããŒã¹ã䜿çšããå Žåã®åé¡ã¯æ±ããŸãããããã¯åå¿è
åãã®å°ããªã¬ã€ãã§ãã
ãããã£ãŠãããŒã«ã«ã³ã³ãã¥ãŒã¿ãŒã®/ path / deploy /ããã±ãŒãžã«ãphpã§èšè¿°ãããã¢ããªã±ãŒã·ã§ã³ããããšããŸãã ãã®ã¢ããªã±ãŒã·ã§ã³ã«ã¯ãçŸåšã®ã³ãŒããšãšãã«example.net/project.gitã«ããgitãªããžããªããããŸãã example.comã«ã¯ãsshã¢ã¯ã»ã¹ãšããã¡ã€ã«ãã¢ããããŒããããã©ã«ããŒãžã®/ path / deploy /ã®ãã¹ãã£ã³ã°ããããŸãã ftpã¯ã©ã€ã¢ã³ããåžžã«æ··ä¹±ãããããªãã®ã§ãcapistranoãããã€ã€ãç解ããããã«æ°æéãè²»ããããšã«ããŸããã å§ããŸãããã
èšçœ®
ã€ã³ã¹ããŒã«ããå§ããŸãããã ã³ã³ãœãŒã«ãéãã次ãå
¥åããŸãã
$ sudo apt-get install ruby rubygems $ sudo gem install capistrano
RoRã®æ§æãã¡ã€ã«ã¯configãã©ã«ããŒã«ãããããcapistranoã¯ããããããšæ³å®ããŸãã ååšããªãå Žåã¯ãäœæããå¿
èŠããããŸãã
$ mkdir /path/deploy/from/config
configãã£ã¬ã¯ããªãäœæãããã£ã¬ã¯ããªããµãŒããŒã®ã«ãŒããã£ã¬ã¯ããªã§ãããå ŽåãApacheã®.htaccessãã¡ã€ã«ãé
眮ããããšãå¿ããªãã§ãã ãããããã«ããããã®ãã£ã¬ã¯ããªã®ãã¡ã€ã«ã®è¡šç€ºãçŠæ¢ãããããä»ã®WebãµãŒããŒã®èšå®ã§ãã®ãã£ã¬ã¯ããªãžã®ã¢ã¯ã»ã¹ãå¶éãããŸãã
Capification
capistranoãã€ã³ã¹ããŒã«ããåŸã«æåã«ãã¹ãããšã¯ãã¢ããªã±ãŒã·ã§ã³ããcapify-nuteãããããšã§ãã ãCapfactionãã¯ãã¢ããªã±ãŒã·ã§ã³ããããã€ããããã«capistranoãæ§æããããã»ã¹ã§ãã ããã¯éåžžã«ç°¡åã§ãããããžã§ã¯ãã®ã«ãŒããã£ã¬ã¯ããªã«ããããšã確èªãã次ã®ããã«å
¥åããŸãã
$ cd /path/deploy/from $ capify .
ãã®ã³ãã³ãã¯ã2ã€ã®ãã¡ã€ã«ãäœæããŸãã
Capfile
ã¯ãcapistranoãå¿
èŠãšããã¡ã€ã³ãã¡ã€ã«ã§ãã makeãMakefileã䜿çšããrakeãrakefileã䜿çšããããã«ãCapistranoã¯ããã©ã«ãã§Capfileãæ€çŽ¢ããŠããŠã³ããŒãããŸãã æåã«çæãããCapfileã¯éåžžã«åçŽã§ãããconfig / deploy.rbããããŒãããã ãã§ã...
config/deploy.rb
ã¢ããªã±ãŒã·ã§ã³ã®ãèšå®ããå«ããã¡ã€ã«ã
äžè¬çã«ãCapfileããã®ãŸãŸã«ããŠãconfig / deploy.rbãã¡ã€ã«ã«å¯æ¥ã«åãçµãå¿
èŠããããŸãã æåã¯ã次ã®ããã«ãªããŸãã
set :application, "set your application name here" set :repository, "set your repository location here" set :scm, :subversion
ãã®èšå®ã¯ç§ãã¡ã«åããªãã®ã§ãæžãçŽããŸãã
æ§æ
æåã«ãã¢ããªã±ãŒã·ã§ã³ã«ååãä»ããå¿
èŠããããŸãã ãç§ã®phpã¢ããªã±ãŒã·ã§ã³ããšåŒã³ãŸãããã
set :application, "my php application"
次ã«ãã³ãŒãã眮ãããŠãããªããžããªãæå®ããå¿
èŠããããŸãã ãã®ãªããžããªã¯ãããŒã«ã«ãã·ã³ãšãããžã§ã¯ãããããã€ãããã¹ãã£ã³ã°ã®äž¡æ¹ããã¢ã¯ã»ã¹ã§ããå¿
èŠããããŸãã ãªããžããªãèšå®ããŸãã
set :repository, "ssh://git@example.net/project.git"
ããŒã«ã«ãã·ã³ãšãµãŒããŒãããªããžããªã«ã¢ã¯ã»ã¹ããããã®URLãç°ãªãå ŽåïŒããšãã°ãsshã®å€éšããŒããç°ãªãå ŽåïŒãäž¡æ¹ã®ã¢ãã¬ã¹ãæå®ããå¿
èŠããããŸãã
set :repository, "ssh://git@example.com:22100/project.git" set :local_repository, "ssh://git@example:project.git"
ããã©ã«ãã§å²ãåœãŠãããŠããSubversion以å€ã®ããŒãžã§ã³ç®¡çã·ã¹ãã ã䜿çšããŠããããã次ã®è¡ãå
¥åããå¿
èŠããããŸãã
set :scm, :git
ããã§ããããžã§ã¯ããå±éãããµãŒããŒäžã®ãã©ã«ããŒã«Capistranoãæå®ããå¿
èŠããããŸãã ãããäœãæå³ããã®ããç解ããã«ã¯ãCapistranoãã¢ããªã±ãŒã·ã§ã³ã®å±éã«äœ¿çšãããã£ã¬ã¯ããªæ§é ãèæ
®ããå¿
èŠããããŸãã
ãã£ã¬ã¯ããªæ§é Capistrano
Capistranoã§æ£åžžã«ãããã€ããããããžã§ã¯ãã¯ã次ã®ãããªæ§é ã«ãªããŸãïŒ[deploy_to]ã¯ãããžã§ã¯ãããããã€ãããã£ã¬ã¯ããªã§ãïŒã
[deploy_to] [deploy_to]/releases [deploy_to]/releases/20080819001122 [deploy_to]/releases/... [deploy_to]/shared [deploy_to]/shared/log [deploy_to]/shared/pids [deploy_to]/shared/system [deploy_to]/current -> [deploy_to]/releases/20100819001122
ãããžã§ã¯ãããããã€ãããã³ã«ããreleasesããã©ã«ããŒã«æ°ãããã£ã¬ã¯ããªãäœæãããããã«ææ°ããŒãžã§ã³ãã³ããŒãããŸãã ãã®åŸãã·ã³ããªãã¯ãªã³ã¯ãcurrentããæŽæ°ãããæ°ãããã£ã¬ã¯ããªããã€ã³ãããŸãã ã¢ããªã±ãŒã·ã§ã³ã®æ§é ãããããžã§ã¯ãã«ãŒããšWebãã£ã¬ã¯ããªãç°ãªãRoRãŸãã¯å¥ã®ã¢ããªã±ãŒã·ã§ã³ã®æ§é ã«é¡äŒŒããŠããå ŽåããµãŒããŒããã®ãã£ã¬ã¯ããªã«æ§æãããŠããããšã確èªããå¿
èŠããããŸãïŒRoRã§ã¯ãããã¯[deploy_to] / current / publicã§ãïŒã
æ§æã«æ»ã
ãããã£ãŠãã¢ããªã±ãŒã·ã§ã³ããããã€ãããµãŒããŒäžã®å Žæãæå®ããå¿
èŠããããŸãã ããã©ã«ãã§ã¯ãããã¯ãã©ã«ããŒã/ u / apps /ïŒ{application}ãã§ãïŒïŒ{application}ã¯ãå€æ°ãïŒapplicationãã§äžã§æå®ããååã§ãïŒã ãã£ã¬ã¯ããªã¯ããã©ã«ãã®ãã£ã¬ã¯ããªãšã¯ç°ãªããããæ瀺çã«æå®ããŸãã
set :deploy_to "/path/deploy/to"
次ã«ããµãŒããŒã®å Žæãæå®ããå¿
èŠããããŸãã äžè¬çã«ãCapistranoã¯ããã©ã«ãã§ãRailsã¢ããªã±ãŒã·ã§ã³ããããã€ããããã«ãwebãappãdbã®3ã€ã®ããŒã«ã䜿çšããŸãã ãããã®åœ¹å²ã®è©³çŽ°ãªèª¬æã¯ãå
ã®èšäºã«èšèŒãããŠããŸãã ãµãŒããŒã¯1ã€ãããªããããŒã«æ©èœã¯å¿
èŠãªãããã次ã®æ§æã䜿çšã§ããŸãã
server "example.com"
詳现èšå®
ããã§ã圹ã«ç«ã€ãããããªãè¿œå ã®å€æ°ãèŠãŠã¿ãŸãããã
set :user, "foo"
ããŒã«ã«ã³ã³ãã¥ãŒã¿ãŒã«ãã°ã€ã³ããŠããåå以å€ã®ååã§ãµãŒããŒã«æ¥ç¶ããå ŽåãsshãŸãã¯ftpã¢ã¯ã»ã¹ã®ãŠãŒã¶ãŒåãæå®ããŸãã
set :password, "password"
ãµãŒããŒã«æ¥ç¶ããããã®ãã¹ã¯ãŒããèšå®ããŸãã æšå¥šãããŸããã
set :scm_username, "foo"
ããŒã«ã«ã³ã³ãã¥ãŒã¿ãŒã«ãã°ãªã³ããŠããåå以å€ã®ååã§ãªããžããªã«æ¥ç¶ããå Žåããªããžããªã«ã¢ã¯ã»ã¹ããããã®ãŠãŒã¶ãŒåãæå®ããŸãã ãã¹ãŠã®vcããã®ãªãã·ã§ã³ããµããŒãããŠããããã§ã¯ãããŸããã ããŒãžã§ã³ç®¡çã·ã¹ãã ããµããŒãããŠããªãå Žåãäžèšã®ããã«ããïŒãªããžããªããã©ã¡ãŒã¿ãŒã§ãã®ååãæå®ããå¿
èŠããããŸãã
set :use_sudo, false
ããã©ã«ãã§å²ãåœãŠãããŸãã Capistranoã«ä»»æã®æäœãå®è¡ããããã®sudoã¢ã¯ã»ã¹ãèš±å¯ããå Žåã¯ã true
ã«èšå®ãtrue
set :via, "scp"
ããŒã¿ãã³ããŒãããããã³ã«ãèšå®ããŸãã
set :branch, "master"
ã³ãŒãã®ååŸå
ã®ãããžã§ã¯ããã©ã³ãã瀺ããŸãã
set :deploy_via, :remote_cache
ãµãŒããŒã«ææ°ããŒãžã§ã³ã®ãã£ãã·ã¥ãä¿åããæ°ããå±éã§ã¯æŽæ°ã®ã¿ãããŠã³ããŒãããŸãã ãã£ãšãã®ãã©ã¡ãŒã¿ãŒãèšå®ããããªãã§ãããã
ã«ãã¹ãã©ãŒãããŒã
ã¬ã·ããæžããåŸãã«ãã¹ãã©ãŒãã«ããã€ã質åãããããšãã§ããŸãã
ã»ããã¢ãã
capistranoã䜿çšããŠãµãŒããŒãšããåãããŠã¿ãŸãããã æåã«ããã£ã¬ã¯ããªã®åºæ¬æ§é ãäœæããå¿
èŠããããŸãã
$ cap deploy:setup
ãã®ã³ãã³ããèµ·åããããšãcapistranoã¯ãµãŒããŒã«æ¥ç¶ããäžé£ã®ãmkdirãã³ãã³ããå®è¡ããŸãã ãããžã§ã¯ããå±éãããã£ã¬ã¯ããªãžã®ã¢ã¯ã»ã¹æš©ãæã€ãã¹ãŠã®ãã®ãé çªã«æã£ãŠããããšãäºåã«ç¢ºèªããŠãã ããã
äŸåæ§ãã§ãã¯
ãã¬ãŒã ã¯ãŒã¯ãã§ããã®ã§ããããžã§ã¯ãã®éçºãç¶ç¶ããããã«å¿
èŠãªãã®ããã¹ãŠæã£ãŠãããã©ãããcapistranoã«å°ããããšãã§ããŸãã
$ cap deploy:check
Kapistranoã¯ãããŒã«ã«ããã³ãªã¢ãŒããµãŒããŒã§å¿
èŠãªãã®ããã§ãã¯ããŸãã äœããæ¬ èœããŠããå Žåãããšãã°ãæäœã«å¯Ÿããæš©éããªããgitããµãŒããŒã«ã€ã³ã¹ããŒã«ãããŠããªãããªã©ã®ãšã©ãŒã¡ãã»ãŒãžã衚瀺ãããŸãã
ãµãŒããŒãžã®ã³ãŒãã®éä¿¡
ããããæ¬æ Œçãªå±éãå®è¡ããã®ã§ã¯ãªããã³ãŒãããµãŒããŒã«ã¢ããããŒãããŠããã®æ®µéã§ãã¹ãŠãæ£åžžã§ããããšã確èªããŠãã ããã
$ cap deploy:update
ãã®ã³ãã³ãã¯ããªããžããªãããµãŒããŒã«ã³ãŒããããŠã³ããŒãããçŸåšã®ãªã³ã¯ãæŽæ°ããŸãã
å±éãã
æåŸã«ããããã€ã¡ã³ãã«çŽæ¥å°éããŸããã å®éãdeployã³ãã³ãã¯ãä»ã®ããã€ãã®ã³ãã³ãã®åãªãã©ãããŒã§ãããåçŽã«ããããé 次å®è¡ããŸãã 次ã®å³ã§ãããã©ã®ããã«èŠãããšãã§ããŸããïŒ
deployïŒupdateããã³deployïŒfinalize_updateã³ãã³ãã¯ruby on railsã¢ããªã±ãŒã·ã§ã³ã«åºæã§ãããããããããåå®çŸ©ããå¿
èŠããããŸãã ãããã®2ã€ã®ã³ãã³ãã«å ããŠãRoRçšã«ã·ã£ãŒãåãããå®è¡ããããšãšã©ãŒã«ã€ãªããå¯èœæ§ããããããdeployïŒstartããã³deployïŒstopã³ãã³ããåå®çŸ©ããããšããå§ãããŸãïŒå®éãä»ã®ç¹å®ã®ã³ãã³ãããããŸãããæãåºæ¬çãªã³ãã³ãã®ã¿ãåå®çŸ©ããŸãïŒïŒ
namespace :deploy do task :start do end task :stop do end task :restart do end task :finalize_update do end end
åºæ¬çã«ãä»ã§ã¯deployã³ãã³ãã¯deployïŒupdateã³ãã³ããšå€ãããŸããããå¿
èŠãªã¿ã¹ã¯ã§ã¢ããªã±ãŒã·ã§ã³åºæã®ã¢ã¯ã·ã§ã³ãèšè¿°ããããšã§ãããå€æŽã§ããŸãã
ããã§ãããã€ã€ã®æºåãæŽããŸããã 説æããæ©èœã§ã¯äžååãªå Žåã¯ããããžã§ã¯ã
wikiããŒãžã®DSLããã¥ã¡ã³ãã»ã¯ã·ã§ã³ãããç解ããåæšæºã¿ã¹ã¯ã®cap -eã³ãã³ãã®åºåã泚ææ·±ãèªãããšããå§ãããŸãã ããããèªãã åŸããã®çš®ã®æ§é ãç°¡åã«æžãããšãã§ããŸãïŒ
after "deploy", "deploy:cleanup"
ãã®ãããªè¡ãã¬ã·ãã«è¿œå ãããšãåå±éåŸã«/ path / deploy / to / releasesãã£ã¬ã¯ããªã
èªåçã«åé€ãããŸãïŒããã©ã«ãã§ã¯ãæåŸã®5ã€ãé€ããã¹ãŠã®ãªãªãŒã¹ãåé€ãããŸãïŒã
å€æ®µ
éçºã§ã¯ãcapistrano-extæ¡åŒµæ©èœã䜿çšããŸããããã«ããããããããã«ãã¹ããŒãžãå®è¡ã§ããŸãã ãã¹ããµãŒããŒãšéçšãµãŒããŒããããšããŸãã ããããã«åå¥ã®æ§æãèšè¿°ããç®çã®ãµãŒããŒã«å¯ŸããŠã®ã¿deployãå®è¡ã§ããŸãã
ã³ãã³ãã©ã€ã³ã§æ¡åŒµæ©èœãã€ã³ã¹ããŒã«ããã«ã¯ã次ã®ããã«å
¥åããŸãã
$ gem install capistrano-ext
次ã«ããã©ã«ã/ãã¹/ deploy / from / config /ã«æ°ãããã£ã¬ã¯ããªãäœæããŸãã
$ mkdir /path/deploy/from/config/deploy
ãããŠããã®äžã«ã¬ã·ããå
¥ããŸãïŒäŸãã°production.rbãšstaging.rbã æ§æã«å¿
èŠãªã®ã¯ã
/ path / deploy / from / config / deploy.rbãã¡ã€ã«ã«2è¡ãæžã蟌ãããš
ã ãã§ãã
set :stages, %w(staging production) require 'capistrano/ext/multistage'
ããã§ããcap production deployãã³ãã³ããšãcap staging deployãã³ãã³ãã䜿çšããŠãããã€ã§ããŸãã å¥ã®èšå®ãå¿
èŠãªå Žåã¯ãé
眮ãã£ã¬ã¯ããªã«é
眮ããå€æ°ã«ååãè¿œå ããŸã
:stages
ïŒ
set :stages, %w(staging production develop)
ãcap deployãã³ãã³ããå®è¡ããããšãããšãcapistranoã¯ããããã€ãå®è¡ããå¿
èŠãããã¬ã·ããæå®ããå¿
èŠãããããšãèŠåããäœæ¥ãäžæããŸãã ããã©ã«ãã®ã¬ã·ãã䜿çšããã«ã¯ãå€æ°ãdefault_stageããå®çŸ©ã§ããŸãã
set :stages, %w(staging production develop) set :default_stage, "develop" require 'capistrano/ext/multistage'
cap deployã³ãã³ãã¯cap deploy deployã³ãã³ããšåçã«ãªããŸãã
ããã ãã§ãããæž
èŽããããšãããããŸããã
PSïŒãã¥ãŒããªã¢ã«ã®åå以äžã§ãããããç§ã¯åºçç©ã®ååã翻蚳ã«å€ããŸããã§ããã å€ãã®ããšã¯ä»ã®èšäºãå人çãªçµéšããåãããŠããŸãã
ãªãªãžãã«ã®ãã¥ãŒããªã¢ã«
å€æ®µã«é¢ããèšäº
help.github.com/capistrano