çµç·¯
- Capistrano3 å²ã¨ä½¿ã£ã¦ã¦ãç¹ã« asonas/capistrano3-puppet · GitHub ã¯ã®ã§ã¼ã ã§ããããªä½¿ã£ã¦ã
- ã§ããã®ã§ã¼ã ã§ä½¿ã£ã¦ãã®ã«èªåãã¹ãããªãã®ã§æ°æã¡ãæªããCapoistrano(3)ã®ãã©ã°ã¤ã³ã£ã¦ã»ã¨ãã©ãã¹ãæ¸ããã¦ãªãã®ã§ã¯...
- ä½ãåèã«åºæ¥ãªãã®ã§ãã©ãæ¸ãã°è¯ãã®ã...
- Docker使ãã°sshãã®ã³ãã¦ãã§ãã¯ã¢ã¦ããã¦å®éåä½ã§ç¢ºèªã§ããã®ã§ã¯
Cap 3 ããã¯ã¿ã¹ã¯ãã¿ãã® Rake Task ã«ãªã£ãã®ã§ãRake Taskã®ãã¹ããæ¸ãã®ã¨åãããã«ãã¹ãã§ãããããããªããã大éã® stubbing ãå¿ è¦ã«ãªãæããããã®ã§ä»å㯠e2e ãªæãã®ãã¹ããéã«æ¸ããã
以ä¸ãæµãã
SSH + Puppet ãã§ããã³ã³ãããä½ã Dockerfile ãç¨æãã
FROM rastasheep/ubuntu-sshd:14.04 MAINTAINER Uchio KONDO <[email protected]> ENV HOME /root RUN apt-get -y install puppet RUN apt-get -y install git ADD dot.gitconfig /root/.gitconfig ADD puppet_repo /var/repo/puppet RUN git init /var/repo/puppet RUN cd /var/repo/puppet && git add . && git commit -m 'sample commit' RUN mkdir /root/.ssh ADD id_dsa.pub /root/.ssh/authorized_keys RUN chmod 700 /root/.ssh RUN chmod 600 /root/.ssh/authorized_keys RUN mkdir /var/puppet
æçµçã«ãããªæãã«ãªã£ãã
ããã® sshd ã¯ç´ ç´ã«åããã®ã§ä½¿ã£ããç§å¯/å ¬ééµã¯å°ç¨ã®ãã®ããªãã¸ããªã«å ¥ãã¦ããããã«ADDã§ããããã«ãã¦ããã
ãã¨ããã¹ãç¨ã®ç°¡åãªpuppetããã¸ã§ã¯ããADDããã®ã¡ã³ã³ããå ã§gitãªãã¸ããªã«ãããããã¯ãCapistranoã®ãããã¤å¯¾è±¡ãåãã³ã³ããå ã®ãªãã¸ããªã«ãããã¨ã§é«éã«ãããã¨ãã¦ããããã¨ãã¹ãç¨ã®puppetããã¸ã§ã¯ããä¸ç·ã«ç®¡çã§ããã®ã§ä¾¿å©ã¨æãã
RSpec ã®ããã©ã¼ãã£ã«ã¿ã¼ã§å½è©²ã³ã³ãããç«ã¡ãããã
config.before :all do Dir.chdir './spec/misc' do run 'bundle install --path vendor/bundle' end run 'docker build -t cap3puppet/base spec/misc' run 'docker run -d -P --hostname \'cap3puppet.dev\' --name test_sshd cap3puppet/base' end config.after :all do run 'docker stop test_sshd' run 'docker rm test_sshd' end
ç´ ç´ã§ããã
run ã®å®ç¾©ã¯ä¸è¨ã®ãããªæããOpen3.capture3ã¨ããæé«ã®ã¡ã½ãããã©ãããã¦ããã便å©ã®ãããrunãrun_and_captureã«ä»»æã®ç°å¢å¤æ°ã渡ããããã«ããã
require 'open3' module CommandRunner def __env @__env ||= { 'PATH' => '/bin"/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin', } end def run(cmd, options={}) sout, *_ = run_and_capture cmd, options return sout end def run_and_capture(cmd, options={}) ext_env = options[:ext_env] || {} return Open3.capture3 __env.merge(ext_env), cmd end end RSpec.configure do |config| config.include CommandRunner end
å¾è¿°ããWerckerã®base boxãUbuntu saucyã£ã½ãã¦ãç´ ç´ã«ããã¨Rubyã1.9ç³»ã«... options={} ãç¡å¿µã£ã½ãã
RSpecã®ä¸ããcapãã¦åºåãæ¤æ»ãã
sshdãåä½ããdocker containerãèªåã®ãã®ã«ãªã£ãã®ã§ãããã«å¯¾ã㦠cap deployï¼ä»å㯠cap production provision ã¨ããã³ãã³ãã§ã¨ã¤ãªã¢ã¹ãã¦ããï¼ãå®è¡ãã¦ãã¹ãã«ããã
spec/misc ãã£ã¬ã¯ããªã®ä¸ã«å®å ¨ã«åã Capistrano3 project ãé ç½®ãã¦ããã®ä¸ã§å®è¡ããã®ããã¤ã³ããããã§ã®è¨å®ä¾ã¯ https://github.com/asonas/capistrano3-puppet/compare/8025d43...070e781#diff-939ca037997ba3d51fcaf6e9b2b07f8bR1 ã¨ã https://github.com/asonas/capistrano3-puppet/compare/8025d43...070e781#diff-7b8dd0f8c713ba0d737de06490b4bf89R1 ã®ããªã§ã
RSpecã®exampleã¯ä»¥ä¸ã®ããã«ã
describe 'cap basic tasks' do describe '$ cap -T' do it 'should contain provison task' do Dir.chdir './spec/misc' do stdout, stderr, exitinfo = run_and_capture('bundle exec cap -T') expect(stdout).to match(/^cap provision/) expect(stderr).to be_empty expect(exitinfo.exitstatus).to be 0 end end end describe '$ cap production provision' do let(:hostname) { have_boot2docker? ? run('boot2docker ip 2>/dev/null').chomp : 'localhost' } let(:port) { run('docker port test_sshd 22').split(':')[1].chomp rescue "22" } let(:ext_env) do { 'HOSTNAME' => hostname, 'PORT' => port } end it 'should run a provisioning successfully' do Dir.chdir './spec/misc' do stdout, stderr, exitinfo = run_and_capture("bundle exec cap production provision", ext_env: ext_env) expect(stdout).to include('Running /usr/bin/env puppet apply --modulepath=modules manifests/site.pp') expect(stdout).to include('Notice: Scope(Class[Sample]): hello, world!') expect(exitinfo.exitstatus).to be 0 end end end end
ä»åã¯ãcapã³ãã³ããåãåºããã°ãæå³ããããã«ãªã£ã¦ãããï¼ã¨ãã³ãã³ãèªä½ã®æ£å¸¸çµäºãã¨ããæ¤æ»ã ãã«ã¨ã©ãã¦ããããcapãå®è¡ããçµæãã¡ã¤ã«ã·ã¹ãã ãã©ããªã£ã¦ããããçã®ãã¹ããæ¸ãã¦ãããã¨æããCapistrano3ã«å梱ããã¦ãã capistrano/sshkit · GitHub ã¨ã使ããããServerspecã¨çµã¿åãããã¨ããã§ããã¨æããã©ããéãããª...ã
boot2dockerãå©ç¨ããéã®ããã¯
ã³ã¼ããè¦ãã°åããéãéæã«boot2dockerãç¨ããå ´åã§ã®åå²ãè¦ããããæ®éã«åããã¹ãã§dockerãåããã®ã¨éã£ã¦ã以ä¸ã®ï¼ç¹ã«æ°ã使ãå¿ è¦ãããã
- DOCKER_HOSTãã¡ããã¨è¨å®ããªãã¨dockerã³ãã³ããåããªã
- Capã®SSHã®ãã°ã¤ã³å ãlocalhostã§ãªãboot2docker ip 2>/dev/nullã®çµæã«ãªã
詳ããã¯å½è©²diffã§ãhave_boot2docker?ããC-fããã°åããã¨æãã
ããã¾ã§ã§ããã¨ã¯Rakefileãé©å½ã«æ¸ãã°ãæå 㧠rake spec ãåãã¨ããã¾ã§ã§ãã¦ããã
Wercker ã«ä»æããã
ãã¨ã¯Werckerã«ä»æããã ãã§ããã
Werckerã¯ãDockerãç¨ããCIã«å¯¾å¿ãã¦ããã
wercker-labs/docker ã¨ããbase boxããããã§ããã«ã«ãã¼ãå ¥ããã°rspecãèµ°ããã§ããããã±ã¼ã¸ã®bundlerã使ã£ãã1.9.3ã«ãªã£ã¦ãã¾ã...ãupdate-alternativesã¨ã使ãã°ãããããªï¼
box: wercker-labs/docker build: steps: - install-packages: packages: build-essential ruby2.0 ruby2.0-dev bundler - script: name: docker version code: | docker -v - script: name: bundle install code: | bundle install --path vendor/bundle - script: name: spec runner code: | bundle exec rake spec
ãã¨ã¯
Werckerã®Web UIããããã¸ã§ã¯ããç»é²ãããã«ãªã¯ã¨ã¹ããä½æããã°ä¾¿å©æé«ãçºçããã
ææ
ä»åCapistrano3ã ã£ããã©ãããããµã¼ãã«ã¢ã¬ãã¦ãã³ããç³»ã®ããã«ã¦ã§ã¢ãªããçµåãã¹ãã®èªååä¸è¬ã«ä½¿ããããããªãããªã¼ã¨æã£ã¦ãããApacheã®æ¡å¼µã¨ããApacheãèµ°ãã³ã³ããå é¨ã§ã³ã³ãã¤ã«ãã¦ãªã¯ã¨ã¹ããå½ã¦ã¦ç¢ºèªããã¨ãã§ãã¦è¯ãããããã㧠ryotarai/infrataster · GitHub ããã£ã¡ãæ´»èºãããã§ããã
ãã¨ãWerckerã¯æ®éã«Dockerã使ãã¦è¯ããä»ã®CIãµã¼ãã¹ã§ã対å¿ãé²ãã§ã»ããã