ã¯ããã«
ä»æ´ãªãã capistrano
ã«æåããã®ã§ã¤ã³ãã©ã¨ã³ã¸ã¤ãªãã®è¦ç¹ã§è§¦ã£ã¦ã¿ã¦ä½¿ãæ¹ãã¾ã¨ãã¦ã¿ãã
capistrano ã¨ã¯
以ä¸ã¯èªåãæ±ã capistrano
ã¸ã®ã¤ã¡ã¼ã¸ã
- è¤æ°ã®ãã¼ãã«å¯¾ãã¦ä¸¦åãã¦ã³ãã³ããå®è¡åºæ¥ãï¼ï¼ããããã¤ã³ãï¼
- ã³ãã³ãã
task
ã¨ããåä½ã§çºãã¦èªåååºæ¥ãï¼ï¼ããããã¤ã³ãï¼ - Ruby 製ã®ãããã¤ãã¼ã«ï¼ï¼ãããããããã¤ã³ã*1ï¼
ããã ããããããã¤ã³ãããããã°è¤æ°å°ã®ãµã¼ãã¼ã«ãã°ã¤ã³ãã¦è²ã ã¨ãããªãããããªãã¤ã³ãã©ã¨ã³ã¸ã¤ã使ããªãçç±ãç¡ãã§ããï¼ã¨ãããã¨ã§æ©é使ã£ã¦ã¿ãã¼ã
ã¡ãªã¿ã«ä»ã¾ã§ã¯ä»¥ä¸ã®ãããªã¤ã¡ã¼ã¸ã
ã¡ã³ããã³ã¹ä½æ¥çã« capistrano
ã常ç¨ããããã«ãªã£ã¦ããã®ã¤ã¡ã¼ã¸ã
ã¨ãããã¨ã§ãæ¬æ¥ã® capistrano
ã®å©ç¨ç®çã¨ã¯é¸ãã¦ãã¾ããããããªãããã¤ã³ãã©ã¨ã³ã¸ãã¤ã capistrano
ã使ããã¨ã§æ¥é ã®éç¨ãã¡ãã£ã¨ã§ã楽ã«åºæ¥ãããªã®ã§ä½¿ãæ¹ã«ã¤ãã¦çºãã¦ã¿ããã¨ã«ããã
åè
ç°å¢ãæ´ãã
Mac 㧠boxen ã使ã£ã¦ã¤ã³ã¹ãã¼ã«
Mac
ç°å¢ã«ãã㦠boxen
ã使ã£ã¦ç°å¢ãæ§ç¯ãã¦ããå ´åã«ã¯ /Users/${USER}/our-boxen/modules/people/manifests/${GITHUB_USER}.pp
ã«ä»¥ä¸ã追å ããã
ruby::gem { "capistrano for 2.0.0-p247": gem => 'capistrano', version => '2.15.4', ruby => '2.0.0-p247' } ruby::gem { "capistrano_colors for 2.0.0-p247": gem => 'capistrano_colors', ruby => '2.0.0-p247' }
追å ããã ./script/boxen --no-fde
ã§ã¤ã³ã¹ãã¼ã«ãããï¼â»æå
ã®ç°å¢ï¼OS X Mavericks
ï¼ã§ã¯ã¤ã³ã¹ãã¼ã«å¾ã« rbenv
㧠Ruby
ã®ãã¼ã¸ã§ã³ãæå®ããªããã° capistrano
ãå©ç¨ãããã¨ãåºæ¥ãªãã£ã...ããï¼ï¼
Ubuntu ã§ã¯
æå
ã® Ubuntu
ç°å¢ã§ã¯ä»¥ä¸ã®ããã« gem
ã§ã¤ã³ã¹ãã¼ã«ããã
sudo gem install capistrano --no-ri --no-rdoc -V -v '2.15.4' sudo gem install capistrano_colors --no-ri --no-rdoc -V
Docker ã使ã£ã¦ã¢ã¯ã»ã¹å ã®ãã¼ããæºåãã
以ä¸ã®ããã« Dockerfile
ãæ¸ã㦠capistrano
ã使ã£ã¦ã¢ã¯ã»ã¹ããçºã®ãã¼ããä½åãç¨æãã¦ããã
# FROM inokappa/wheezy-7.2-basic # MAINTAINER YOHEI KAWAHARA inokappa # RUN apt-get update RUN apt-get -y install puppet openssh-server # RUN mkdir -p /var/run/sshd RUN useradd -d /home/sandbox -m -s /bin/bash sandbox RUN echo sandbox:sandbox | chpasswd RUN echo 'sandbox ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
使ã£ã¦ã¿ã
åæå
é©å½ã«ãã£ã¬ã¯ããªããããã¦ãã capify
ã³ãã³ããå®è¡ã㦠capistrano
ã使ãç°å¢ãæºåããã
mkdir ${capistrano_dir} cd ${capistrano_dir} capify .
以ä¸ã®ããã«åºåãããã
[add] writing './Capfile' [add] making directory './config' [add] writing './config/deploy.rb' [done] capified!
ããã§æºåã¯å®äºã
cap -T
cap -T
ãå®è¡ãã㨠capistrano
ã§ããã©ã«ãã§ç»é²ããã¦ããã¿ã¹ã¯ã®ä¸è¦§ãåºåãããã
cap deploy # Deploys your project. cap deploy:check # Test deployment dependencies. cap deploy:cleanup # Clean up old releases. cap deploy:cold # Deploys and starts a `cold' application. cap deploy:create_symlink # Updates the symlink to the most recently deployed version. cap deploy:migrate # Run the migrate rake task. cap deploy:migrations # Deploy and run pending migrations. cap deploy:pending # Displays the commits since your last deploy. cap deploy:pending:diff # Displays the `diff' since your last deploy. cap deploy:restart # Blank task exists as a hook into which to install your own environ... cap deploy:rollback # Rolls back to a previous version and restarts. cap deploy:rollback:code # Rolls back to the previously deployed version. cap deploy:setup # Prepares one or more servers for deployment. cap deploy:start # Blank task exists as a hook into which to install your own environ... cap deploy:stop # Blank task exists as a hook into which to install your own environ... cap deploy:symlink # Deprecated API. cap deploy:update # Copies your project and updates the symlink. cap deploy:update_code # Copies your project to the remote servers. cap deploy:upload # Copy files to the currently deployed version. cap deploy:web:disable # Present a maintenance page to visitors. cap deploy:web:enable # Makes the application web-accessible again. cap invoke # Invoke a single command on the remote servers. cap shell # Begin an interactive Capistrano session.
ãã¡ãããã¿ã¹ã¯èªä½ã¯èªåã§è¿½å ãããã¨ãåºæ¥ãããã¾ãã¯ä¸çªä¸ã® cap shell
ã使ã£ã¦ã¿ãã
cap shell ã使ã£ã¦ãã¼ãã«ãã°ã¤ã³
以ä¸ã®ããã«ã㦠cap shell
ã«ç¶ã㦠HOSTS=
ãªãã·ã§ã³ã®å¾ã«ãã¼ãã®ãã¹ãåãå㯠IP ã¢ãã¬ã¹ãããã¦ãUSER=
ã®å¾ã«ãã¼ããä½æããéã«è¨å®ããã¦ã¼ã¶ã¼ï¼sandbox
ï¼ãç¶ããã
cap shell HOSTS=xxx.xxx.xxx.1 USER=sandbox
å®è¡ããã¨ä»¥ä¸ã®ããã«è¡¨ç¤ºãããã®ã§é©å½ã«ã³ãã³ãï¼pwd
ï¼ãå©ãã¦ã¿ããpassword
ã«ã¯ USER=
ã§æå®ããã¦ã¼ã¶ã¼ã®ãã¹ã¯ã¼ããå
¥åããã
ããããã¼ãä¸ã§ã³ãã³ããå®è¡ããã¦çµæãåºåããã...ããã§ããããã ã¨æ®éã« SSH
ã§ãã°ã¤ã³ããã®ã¨å¤ããã¬ã
ããã« cap shell ã使ã£ã¦è¤æ°ã®ãã¼ãã«ãã°ã¤ã³
åè¿°ã®éããcapistrano
ã®æ¨ã¿ã¯è¤æ°ã®ãã¼ãã«å¯¾ãã¦ä¸¦åãã¦ã³ãã³ããæãããã¨ãåºæ¥ãï¼ã ã£ãã®ã§è¤æ°ã®ãã¼ãã«å¯¾ãã¦ãcap shell
ãå®è¡ãã¦ã¿ããHOSTS=
ãªãã·ã§ã³ã®å¾ã«ãã¼ãã 2 ã¤ä¸¦ã¹ã¦æ¸ãã¦ã¿ãã
cap shell HOSTS="xxx.xxx.xxx.1","xxx.xxx.xxx.2" USER=sandbox
ãããäºã¤ã®ãã¼ã㧠pwd
ã³ãã³ãã®çµæãåºåãããï¼ããã便å©ã
cap shell
ã§ã¢ã¯ã»ã¹ãã¨ã㦠uptime
ãªããé©å½ãªééã§å©ãã¦ããã¨ããæãã§ããªã
ã¿ã¹ã¯ã追å ãã
cap shell
ã§è¤æ°ãã¼ãã«å¯¾ãã¦ä¸åº¦ã«ã³ãã³ããå®è¡ããåã³ãã²ã¨éãæããã¨ããã§ãcap shell
ã ã¨ä¸ã¤ã®ã³ãã³ãããå®è¡åºæ¥ãªã*2ãªãã¨æã£ãããªãã¯éããå®è¡ããããã³ãã³ããã²ã¨éã並ã¹ãã¿ã¹ã¯ã追å ãããã¨ã§ãã®çåãä¸æ°ã«è§£æ±ºã
config/deploy.rb ãä¿®æ£ãã
${capistrano_home}/config/deploy.rb
ã以ä¸ã®ããã«ä¿®æ£ããã
require "capistrano_colors" desc "test" namespace :deploy do task :hoge do run "pwd" run "echo \"Hello Servers!\"" end end
ä¿®æ£ããã以ä¸ã®ããã«å®è¡ããã
cap deploy:hoge HOSTS="xxx.xxx.xxx.1","xxx.xxx.xxx.2" USER=sandbox
以ä¸ã®ããã«åºåãããã
ãããããããã®ã³ãã³ãããã¼ãã§å®è¡ããã¦ããï¼
æ¥ç¶å ã®ãã¼ãã deploy.rb ã«æ¸ãã¦ã¿ã
äºã¤ãä¸ã¤ãããã®ãã¼ãã§ããã° HOSTS=
ã«ç¹ãã¦ããããããã以ä¸ã ã¨ã³ãã³ãã©ã¤ã³ã«ä¸¦ã¹ãå¦æã¯å´©å£ãã¦ãã¾ã*3ãã¨ãããã¨ã§ãã³ãã³ããå®è¡ãããããã¼ãã role
ã«æ¸ãã
require "capistrano_colors" role :ahoaho, "xxx.xxx.xxx.1","xxx.xxx.xxx.2" desc "test" namespace :deploy do task :hoge do run "pwd" run "echo \"Hello Servers!!\"" end end
ãããå®è¡ããã¨...
cap deploy:hoge USER=sandbox
以ä¸ã®ããã«åºåãããã
ã¾ããç°ãªã role
ãè¤æ°è¨è¼ãããã¨ãåºæ¥ããããã« task
ã«å¯¾ã㦠role
ãé¢é£ä»ãããã¨ãåºæ¥ãã
require "capistrano_colors" role :ahoaho, "xxx.xxx.xxx.1","xxx.xxx.xxx.2" role :unko, "xxx.xxx.xxx.3","xxx.xxx.xxx.4" desc "test" namespace :deploy do desc "test hoge" task :hoge , roles: => :ahoaho do run "pwd" run "echo \"Hello Servers!!\"" end desc "test huga" task :huga , roles: => :unko do run "uptime" end end
ä¸è¨ã®å ´åã«ã¯ role
ã® ahoaho
ã«ã¯ hoge
ã role
ã® unko
ã«ã¯ huga
ãå®è¡ãããã
ã¨ãããã¨ã§
capistrano
ã®ã»ãã®è§¦ãé¨åããæ¸ãã¦ããªããããã ãã§ãã¤ã³ãã©ã¨ã³ã¸ãã¤ã¯æå- 次å㯠è¤æ°ã®
EC2
ã¤ã³ã¹ã¿ã³ã¹ãã¼ãã«ã¢ã¯ã»ã¹ãã¦chef-solo
ãpuppet apply
çãçµã¿åããã¦ãã¼ãããããã¤æ¹æ³ãæ¸ãã¦ã¿ãã