éçºã¡ã¢#1 : Cinnamon ã«ãããããã¤
ãã®ããä½ã£ã¦ãããã®ãå¹¾ã¤ãããã®ã ãã©åå¿é²ä»£ããã«ãã®è¾ºã¯ãããã¦ããã¨ãããã¨ãæ¸ãã¦è¡ããããªã¨æãã¾ãã
ã¾ã㯠Perl ã«ããã¢ããªã±ã¼ã·ã§ã³ã®ãããã¤ã«ã¤ãã¦ãid:antipop 㨠id:shiba_yu36 ãéçºãã "Cinnamon" ã¨ãããããã ãªãããã¤ãã¼ã«ãå©ç¨ãã¦ãã¾ãã
- Cinnamon - A minimalistic deploy tool
ã·ã³ãã«ã§ä½¿ãããããããã¤ãã¼ã«ã§ãã
Capistrano?
ãããã¤ãã¼ã«ã®å®çªã¨ããã° Capistrano ã§ãæå㯠Capistrano ã使ã£ã¦ãã¾ããããã©ãä½ã£ã¦ãããã®ã¯ã»ã¼ Perl ã§æ¸ããã¦ããã®ã«ãããã¤ãã¼ã«ã ã Capistrano 㧠Ruby ã¨ããã®ããä¾ãã°ã¢ã¸ã¥ã¼ã«ã®ç®¡çã« Carton 㨠Bundler ãäºã¤ä½¿ã£ããã¨ããªãã ãæ°æã¡ããããã
æ°æã¡ãæªãã¨ããã ããªãã¨ããããå®éã®ã¨ãã Capistrano ããããå°ããããã ãªä»æ§ã®ãããã¤ãã¼ã«ã欲ããã£ãããããã¤ãã¨ããã¨å¤§ããã ããã©ãå人ã§ä½ã£ã¦ãããããªå°è¦æ¨¡ãªãã®ãªã®ã§ãssh ã㦠git fetch ãããç¨åº¦ã®ãã¨ãã§ããã°ããã§è¯ãããã§ãç·æ¥æã®åãæ»ãã¨ããããã㪠ops ãã¼ã«ã¨ã®åçãªé£æºã¨ãã£ãã¨ããã¾ã§ã¯å¿ è¦ã¨ãã¦ããªãã
Capistrano ã使ã£ã¦å± ã㨠Rails ãåæã¨ãã¦ããç®æã¨ããããã¯ã°ã©ã¦ã³ãã§ãããããã£ã¦ããã¨ãããèªåã®ç°å¢ã«åãããããã«ãããã work around ãå ¥ããå¿ è¦ããã£ã¦ãã©ãã«ããããã¹ãã¬ã¹ã§ããã
Cinnamon
・・・ã¨ãæã£ã¦ãããå ¨ãåããããªãã¨ãèãã¦ãããªãã¼ã«ãä½ã£ã¦ãã人ãããã詳ãã㯠シンプルなデプロイツールを書いているという話 - Kentaro Kuribayashi's blog ã«ãæ¸ããã¦ãããã©ã
ãããã¤ã®è©³ç´°ã«ã¤ãã¦ã¯ãããã¤ãã¼ã«ã¯é¢ç¥ããããã¼ã«å¤é¨ã®ãªãã¸ã§ã¯ãã«ããæä¾ãããæ¹ãããã¼ã«ã«ç¸ãããªãæè»æ§ã確ä¿ã§ããã
ã¨ããããªã·ã¼ãèªåã®æ±ãããã®ã«ã¨ã¦ãã¡ããã®ã§ãã£ãã
Capistrano 㧠ssh ããå¾ã«ãµã¼ãã¼ãµã¤ãã§ãããããã«ããã«ãã¨ããé¨åã Capistrano ã®ããã¯ã¨ã³ããDSL ã§æä¾ããããããã¤ã«ã¼ã«è¨è¿°ã®ãã¬ã¼ã ã¯ã¼ã¯ãè¤æ°ãã¹ãã¸ã®åæå®è¡å¦çå¨ããããã³ãã¨ã³ãã¨ããã¨ãCinnamon ã¯ãã®ããã³ãã¨ã³ãããæä¾ããªãã¨ãããã¼ã«ã§ãããµã¼ãã¼ã«å ¥ã£ã¦ããä½ããããã¯èªåã§ãcd /hoge && git fetch origin && git checkout -q origin/masterãã¨ãæ¸ãã
ãããå©ç¨ãã¦ãããã¨ãã話ããã¾ãã¦ã§ãä¸ã«ããªãã®ã§æ å ±ãå°ãªãã®ã ããã©ããã¼ã«ããããã ãªã®ã§ README ã«ç®ãéãã¦ãã£ã¨ã³ã¼ããæãèªã¿ããã°ã ãããä½ããã¦ãã¦ã©ãã¾ã§ãã¹ã³ã¼ããªã®ãã¯ææ¡ã§ããã
Cinnamon ã使ã
ã¤ã³ã¹ãã¼ã«ã¯ cpanm ã§ãperl ã¢ã¸ã¥ã¼ã«ã¨ãcinnamon ã³ãã³ããã¤ã³ã¹ãã¼ã«ãããã
% cpanm Cinnamon
cinnamon ã³ãã³ããçºè¡ãããã¹ããããããã¤å ã¸ã¯ ssh ãçéãã¦ãããã¨ãåæã«ãªã£ã¦ãããä»åèªåã®ãããã¤å 㯠Amazon EC2 ã®ã¤ã³ã¹ã¿ã³ã¹ã§å ¬ééµèªè¨¼ãªã®ã§ .ssh/config ã§éµãã¹ãæå®ãã¦ããã(Cinnamon ã®ä¸ã§ ssh key ãæå®ãããªãã·ã§ã³ããªãã£ãã®ã§)
# ~/.ssh/config Host *.ap-northeast-1 IdentityFile ~/.ssh/aws-naoyaskeys.pem
ãã¨ã¯ãµã¼ãã¼å´ã§ã® sudo å¨ãã¨ããå¿ è¦ã«å¿ãã¦è¨å®ãã¦ããã
ã¢ããªã±ã¼ã·ã§ã³ã®ã«ã¼ããã£ã¬ã¯ããªããè¦ã¦ config/deploy.pl ã«ãperl ã§ãããã¤ã«ã¼ã«ãæ¸ãã¦è¡ãããã®è¾ºã¯ Capistrano ã¨åããDSL ãæä¾ããä¸éãã®ã«ã¼ã«ã Capistrano ã«ããä¼¼ã¦ããã®ã§ãè¦ãã°ãããã
ããã§ã¯
- "cinnamon development deploy:setup" 㧠development ç°å¢ã« git ã§ã½ã¼ã¹ãé ç½®
- "cinnamon development deploy:update" 㧠development ç°å¢ã®ã½ã¼ã¹ãææ°å
- "cinnamon development server:start" 㧠development ç°å¢ã®ãµã¼ãã¼ã start
- "cinnamon development carton:install" 㧠development ç°å¢ã® perl ã¢ã¸ã¥ã¼ã«ããCarton ã§ã¤ã³ã¹ãã¼ã«
- â¦
ã¨ããæãã§ã¿ã¹ã¯ãå®ç¾©ãã¦ããã
# config/deploy.pl use strict; use warnings; use Cinnamon::DSL; set application => 'myapp'; set repository => '[email protected]:naoya/myapp.git'; set user => 'fiorung'; set password => ''; role development => ['myapp-development.ap-northeast-1'], { deploy_to => '/home/fiorung/apps/myapp', branch => 'master', }; task deploy => { setup => sub { my ($host, @args) = @_; my $repository = get('repository'); my $deploy_to = get('deploy_to'); my $branch = 'origin/' . get('branch'); remote { run "git clone $repository $deploy_to && git checkout -q $branch"; } $host; }, update => sub { my ($host, @args) = @_; my $deploy_to = get('deploy_to'); my $branch = 'origin/' . get('branch'); remote { run "cd $deploy_to && git fetch origin && git checkout -q $branch && git submodule update --init"; } $host; }, }; task server => { start => sub { my ($host, @args) = @_; remote { sudo "supervisorctl start myapp"; } $host; }, stop => sub { my ($host, @args) = @_; remote { sudo "supervisorctl stop myapp"; } $host; }, restart => sub { my ($host, @args) = @_; remote { run "kill -HUP `cat /tmp/myapp.pid`"; } $host; }, status => sub { my ($host, @args) = @_; remote { sudo "supervisorctl status"; } $host; }, }; task carton => { install => sub { my ($host, @args) = @_; my $deploy_to = get('deploy_to'); remote { run ". ~/perl5/perlbrew/etc/bashrc && cd $deploy_to && carton install"; } $host; }, };
- ãªã¢ã¼ãã¬ãã¸ããªã¯ github ã«ãã
- ãµã¼ãã¼å¨ã㯠Plack + Server::Starter ã§ããããåããã®ã« supervisor ã使ã£ã¦ããã®ã§ server ã¿ã¹ã¯ã¯ããã¨é£æºãããããªè¨è¿°ã«ãªã£ã¦ãã
- ãã®è¾ºã«é¢ãã¦ãå¾æ¥ç¶ãã¦æ¸ããã
- production ç°å¢ã追å ããã¨ãã¯ãrole production ã追å ããã°ãã
- ãã® deploy.pl ãã¬ãã¸ããªã«è¿½å ãã¦ãã
- EC2 ã¤ã³ã¹ã¿ã³ã¹ã® Puclic DNS ãå¤æ´ã«ãªãã®ã§ deploy.pl ã«è¨è¿°ã§ããªãã¨ããåé¡ã¯ãec2ssh (http://blog.mirakui.com/entry/20101205/1291551625) ãå©ç¨ãã¦è§£æ±ºãã¦ãã
- deploy.pl ãã API ãå©ãã¦ãã¹ãä¸è¦§ãåã£ã¦ãããã§ãè¯ãã§ããã
ããã§ãæå ã®ãã¹ããã
% cinnamon development deploy:update % cinnamon development server:restart
ã¨ããã¨ãéçºç¨ãµã¼ãã¼ã®ã½ã¼ã¹ãææ°ã«ãªã£ã¦ãServer::Starter ã«ãã hot deploy ãå®äºããããã§ããã
ææ³
ãµã¼ãã¼ã« ssh ãã°ã¤ã³ããå¾ãªã«ããã¦ããããã¹ã¦æ確ã«ãªã£ã¦ãããããã£ã¦ãããã¨ãå°ãªãã·ã³ãã«ãªã®ããæã«é¦´æãã§é常ã«è¯ãã§ãããã¼ã«ã®ããªã·ã¼éããã©ããªãã¼ã«ã使ã£ã¦ãããã«ã¯é¢ç¥ããªãã®ã§ãperlbrewãPlackãsupervisorãCarton ã¿ãããªç°å¢ã§ãä¸é½åã¯ããã¾ããã
ãããã¤ãã¼ã«ã¯èªååã«ãã£ã¦èªåã®æéã軽æ¸ãã¦ãããã¨ããã¨ããã大äºã§ãããå人çã«ã¯ãdeploy.rb ã deploy.pl ã®ä¸ã«ç°å¢ä¾åã®ãã®ããã¹ã¦æ¸ãã¦ãã¾ã£ã¦ããã«ããã scm ã§ç®¡çãããã¨ã§ãå¿å´ã«ããããã©ãããã解æ¶ãã¦ãããã¨ãããéè¦ã ãªã¨æã£ã¦ã¾ããå¾æ¥ããµã¼ãã¼ãã©ãã«ãã£ã¦ãã©ããããã£ã¬ã¯ããªã«ä½ãæ¾ãè¾¼ãã§ããããå¿ãã¦ãã¾ã£ã¦ãã¨ãããã "cinnamon deploy development:update" ããããã° ok ⦠ã¨ããã®ãä»å¾ãå®å¿ã§ãããå®éãããªãã¨å¿ããã®? ã¨æãã®ã§ããã10å¹´ãããåã«ä½ã£ãã¢ããªã±ã¼ã·ã§ã³ã ã¨è¦äºã«å¿ãã¾ããã¨ãããå¿ãã¦ãã¦ãé常ã«é¢åã§ããã
Cinnamon èªä½ã®å©ç¨è ãå¤ããªããã (ã¨ãããéçºã¡ã³ãã¼ä»¥å¤ã«ããªã・・・?) ã¨ããåå¹´ãããç¹ã«æ°ãã commit ã¯ãªããã¨ããã®ãè¥å¹²ä¸å®ã¨æãããåããããããã§ãããã¾ã perl ã ãä»æ§å°ãããä½ãå¿ è¦ãªã¨ã㯠pull request ããã°ããããã¨æã£ã¦ãã¾ãã