Vagrantã¯ãä»®æ³åã·ã¹ãã ããŸãã¯å¿ èŠã«å¿ããŠDSLã®äžçš®ã®ã©ãããŒã§ãã ã»ãšãã©ã®å Žåã圌ãã¯VirtualBoxã䜿çšããŸãããVmWareããã³Amazon EC2ã®ãã©ã€ããŒããããŸãã ãã詳现ãªæ å ±ãããã³ãããã€ã³ã¹ããŒã«ããŠéå§ããæ¹æ³ã¯ãå ¬åŒãŠã§ããµã€ã-www.vagrantup.comã§èŠã€ããããšãã§ããŸãã
Vagrantããã³ç°å¢ã®ãã¹ã
RabbitMQãã¹ãä»ããŠäºãã«éä¿¡ããMongoDBãMySQLãªã©ã䜿çšããç¬èªã®ã¢ããªã±ãŒã·ã§ã³ãããã€ããããŸãã å®éã®ç°å¢ããé ãé¢ããåæç°å¢ã§å®è¡ãããŠããåã ã®ã¢ããªã±ãŒã·ã§ã³ã®ãã¹ãã§ã¯ã1ã€ã®èŠçŽ ãæŽæ°ãããšãã®å®éã®ç°å¢ã§ã®ã¢ããªã±ãŒã·ã§ã³ãã³ãã«ã®åäœã¯ç€ºãããŸããã§ããã ãŸããç°å¢ã®å€åã¯ãŸã£ããèŠãããŸããã§ãããQAãšã¹ããŒãžã³ã°ç°å¢ãçŸå®ãšã¯ã»ã©é ãããã§ãã ãã¡ãããããã¯ãŠããããã¹ããè¡ãå¿ èŠæ§ããç§ãã¡ãæããŸããã
Vagrantã§ãã®åé¡ã解決ããŠã¿ãŸãããã
æ確ã«ããããã«ã次ã®ã¹ããŒã ã瀺ããŸãã
Worldflowã®èª¬æïŒ
- éçºè ã¯ãªããžããªå ã®ç°å¢ã«å€æŽãå ããã¬ãã¥ãŒã³ãŒããä»ã®éçºè ã«éä¿¡ããŸãã
- TeamCityã¯å€æŽãååŸããåäœãã¹ããå®è¡ããŸãã
- TeamCityã¯BuildAgentã§Vagrantãå®è¡ããŸããããã«ãããè€æ°ã®ä»®æ³ãã·ã³ã®èµ·åãšPuppetãšãŒãžã§ã³ãã®èµ·åãéå§ãããŸãã
- ãã¹ããããã¢ããªã±ãŒã·ã§ã³ã®å€æŽãããç°å¢ãšå®å®ããããŒãžã§ã³ã¯ãä»®æ³ãã·ã³ã«ããŒã«ãããŸãã
- ãã¹ããå®è¡ãããããQAãã¢ããªã±ãŒã·ã§ã³ããã§ãã¯ããŸãã
ããã¯ã補åã«éä¿¡ããåã«ç°å¢ã®å€æŽãæ€èšŒããã®ã«åœ¹ç«ã¡ãŸãïŒãµãŒãããŒãã£ã¢ããªã±ãŒã·ã§ã³ã®æ°ããããŒãžã§ã³ã®æäœãPuppetãããã§ã¹ããã«ã¹ã¿ã ã¹ã¯ãªãããã¢ããªã±ãŒã·ã§ã³éä¿¡ã®åªå€±ããµãŒãã¹ã¯ã©ãã·ã¥ãããžãã¹ããã»ã¹ãšãã¥ã¬ãŒã·ã§ã³ãªã©ã ãããŠããããããµãŒããŒã«ããã±ãŒãžã眮ãã®ãå¿ããŠããããŸãã¯ãããããããŠãAPIãå€æŽãããã¢ããªã±ãŒã·ã§ã³ãçžäºã«æ©èœããªããªã£ãããšããç¶æ³ã«é¥ãããšã¯çµ¶å¯Ÿã«ãããŸããã ããŠããã®ã¹ããŒã ã§ã¯ãPuppet Standaloneã®ä»£ããã«Puppet Masterã䜿çšãããå®éã®ç°å¢ãç¹°ãè¿ãããšã«æ³šæãã䟡å€ããããŸãã
ç§ãã¡ã®å Žåãã¿ã¹ã¯ã®è€éãã¯ãAmazon EC2ãOpenstackããŸãã¯VmWare ESXiã䜿çšã§ããããšã§ãããããããããã«é¢é£ãããã°ãç¶æ³ããã£ããããã®ã«åœ¹ç«ã¡ãŸããã ãã®ç¶æ³ã§å¯äžã®è§£æ±ºçã¯ããã®ãã¹ãŠã®ãã³ãã«ã䜿çšããããšã§ãããVirtualBox以å€ã®ãããã€ããŒã䜿çšããããšã§ãã ãããŠãããã«ã¯å°ããªãã€ãã¹ç¹ããããŸã-Vagrantãä»ã®ãããã€ããŒãšé£æºãããããšã¯å¿ ãããäºçŽ°ãªäœæ¥ã§ã¯ãããŸããã ããã§ãããã«ããšãŒãžã§ã³ãçšã®ãã·ã³ãåžžã«åäœããããã§ã¯ãããŸãããåäœããããã«å€ãã®ãªãœãŒã¹ãå¿ èŠãšããã¢ããªã±ãŒã·ã§ã³ãåããNåã®ä»®æ³ãã·ã³ããããŸãã
ãããŠãå šäœã®é åã¯ããªããžããªã«ãããžã§ã¯ãããããã¬ãã¥ãŒãããå€æŽã®å±¥æŽããããwimãã€ã³ã¹ããŒã«ãããŸã§ã®ãã¹ãŠã®å€æŽãå®çšŒåã«å ¥ãåã«ãã¹ãããããšããäºå®ã«ãããŸãã ãŸããå€éšãªãœãŒã¹ããã§ãã¯ããããããŒã¿ããŒã¹ããã¹ãnode.jsäžã®ããããçš®é¡ã®ããã³ããšã³ããæŽæ°ãããããã®ã«ã誰ãåãããã«æ°ã«ããŸããã ããã¯ãã¹ãŠæ³ååãšæ¬²æ±ã«äŸåããŸãã
ãã®èšäºã®åŸåã§ãVagrantã䜿çšããŠäžèšã®ã¹ããŒã ãå®è£ ããæ¹æ³ã«ã€ããŠèª¬æããŸãã
ã·ã³ãã«ãªãµãŒãã¹ãéå§ãã
Vagrantã®éåžžã®ãŠãŒã¹ã±ãŒã¹ã¯ããµãŒãã¹ãšç°å¢ãäžãããã®ç°å¢ã§ç§ã®ã³ãŒããã©ã®ããã«æ©èœãããã確èªããããšã§ãã ç¹ã«ãããçš®ã®ãã©ãããã©ãŒã äŸåã®ãã®ãèŠããå Žåã ããã«ãVagrantã䜿çšãããšã皌åäžã®ãã·ã³ã§åç©åã飌è²ããããããŸããŸãªããŒãºããããžã§ã¯ãã«åãããŠç°ãªãããŒãžã§ã³ã®ãœãããŠã§ã¢ããµãŒãã¹ã®ããã¯ãåæã«ä¿ç®¡ãããããããšã¯ã§ããŸããã
ç§ã«ãšã£ãŠæã楜ããæ©èœã®1ã€ã¯ããã¹ã¿ãŒã¢ãŒããšã¹ã¿ã³ãã¢ãã³ã¢ãŒãã®äž¡æ¹ã§ã®Puppetã®ãµããŒãã§ãã ãã¡ãããVagrantã¯Chefãå®è¡ã§ããŸãããåœç€Ÿã§ã¯Puppetã䜿çšããŠããããããã®éžæã¯ç§ã«ã¯æããã§ãã Puppet Standaloneã䜿çšããããåã«ãããããé©çšããŸãã
ãŸãããããžã§ã¯ããã£ã¬ã¯ããªã«ç§»åããvagrant initãå®è¡ããŸãããã®çµæãä»®æ³ãã·ã³ã®èª¬æãå«ãVagrantfileãã¡ã€ã«ãååŸããŸãã äžåºŠæ§æãããã¡ã€ã«ã䜿çšããŠããããžã§ã¯ããããããžã§ã¯ãã«ã³ããŒããå¿ èŠãªã»ã¯ã·ã§ã³ãšæ§æãå€æŽããããšã奜ã¿ãŸãã 以äžã®ãã¡ã€ã«ã«ã¯ãåäžã®VMã®VagrantfileããããŸãã ããšãã°ãRabbitMQãæ§æããOracle Javaãã€ã³ã¹ããŒã«ããŸãã
VagrantfileïŒ
# -*- mode: ruby -*- # vi: set ft=ruby : # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # All Vagrant configuration is done here. The most common configuration # options are documented and commented below. For a complete reference, # please see the online documentation at vagrantup.com. # Every Vagrant virtual environment requires a box to build off of. config.vm.box = "precise64" # The url from where the 'config.vm.box' box will be fetched if it # doesn't already exist on the user's system. # config.vm.box_url = "http://domain.com/path/to/above.box" config.vm.box_url = "http://files.vagrantup.com/precise64.box" # Create a forwarded port mapping which allows access to a specific port # within the machine from a port on the host machine. In the example below, # accessing "localhost:8080" will access port 80 on the guest machine. # config.vm.network :forwarded_port, guest: 3000, host: 3000 # Create a private network, which allows host-only access to the machine # using a specific IP. # config.vm.network :private_network, ip: "192.168.33.10" # Create a public network, which generally matched to bridged network. # Bridged networks make the machine appear as another physical device on # your network. # config.vm.network :public_network # If true, then any SSH connections made will enable agent forwarding. # Default value: false config.ssh.forward_agent = true ### Define VM for RabbitMQ config.vm.define "rmq", primary: true do |rmq| # Provider-specific configuration so you can fine-tune various # backing providers for Vagrant. These expose provider-specific options. # Example for VirtualBox: # rmq.vm.provider :virtualbox do |vb| # Don't boot with headless mode vb.gui = false # Use VBoxManage to customize the VM. For example to change memory: vb.customize ["modifyvm", :id, "--memory", "1024"] end # Networking options rmq.vm.network :private_network, ip: "192.168.100.5" rmq.vm.hostname = "rmq.example.com" end end
ãã®æ§æãã¡ã€ã«ã¯ããµãŒãã¹ãããã°ã©ã ãã€ã³ã¹ããŒã«ããã«ãéåžžã®Ubuntu 12.04 LTSã§ãã·ã³ãèµ·åããã®ã«ååã§ãã ããããç§ã¯æ ãè ã§ãããæ¯åæã§ä»®æ³ãã·ã³ã«ãœãããŠã§ã¢ãã€ã³ã¹ããŒã«ããŠæ§æãããã¯ãããŸããããæéãç¡é§ã«ããŠããã«ã³ãŒããè¿œãããããããã¹ããå®è¡ãããããããããŸããã
Vagrantfileã®ããŒãã®èª¬æã«ã»ã¯ã·ã§ã³ãè¿œå ããŸãã
rmq.vm.provision :puppet do |puppet| puppet.manifests_path = "./vagrant.d/manifests" puppet.manifest_file = "site-rmq.pp" puppet.module_path = "./vagrant.d/modules" puppet.options = "--fileserver=/vagrant/vagrant.d/fileserver.conf --verbose --debug" end
ãããŠãããã«å¿ããŠãã/ vagrant.d / modulesãã/ vagrant.d / manifestsãã/ vagrant.d / filesããã³./vagrant.d/manifests/site-rmq.ppãäœæããå¿ èŠããããŸãã ./vagrant.d/fileserver.confã
modulesãã£ã¬ã¯ããªã«ã¯ã䜿çšããã¢ãžã¥ãŒã«ãã¡ã€ã«ãå«ãŸããŠããŸãã ãããã§ã¹ããã£ã¬ã¯ããªã«ã¯ãä»®æ³ãã·ã³ã®ãããã§ã¹ãsite-rmq.pp Puppetãå«ãŸããŠããŸãã files-ãã¡ã€ã«ãµãŒããŒã«ãã£ãŠç®¡çããããã¡ã€ã«ãå«ããã£ã¬ã¯ããªã fileserver.conf-fileserverã䜿çšããä»®æ³ãã·ã³ã«ç¹å®ã®ãã¡ã€ã«ãæ·»ä»ããããã®ãã¡ã€ã«ã
ãã ããPuppetã«ãµãŒãããŒãã£ã¢ãžã¥ãŒã«ã䜿çšããå Žåã¯ãpuppet applyãå®è¡ããåã«ããããã€ã³ã¹ããŒã«ããå¿ èŠããããŸãã ãã®ãããã¹ã¯ãªããã䜿çšãããããè¯ããã®ã¯æãã€ããŸããã§ããã ã¢ãžã¥ãŒã«ã®é 眮æ¹æ³ãæããŠãããPuppetã®ã¿ã䜿çšããŠãããã§ã¹ãã§äœ¿çšããè·äººãããå Žåã¯ãæè¬ããŸãã =ïŒ
ã·ã§ã«ã¹ã¯ãªããã䜿çšããŠä»®æ³ãã·ã³ãããããžã§ãã³ã°ããã»ã¯ã·ã§ã³ãè¿œå ããŸãã
# Enable shell provisioning config.vm.provision "shell", path: "./vagrant.d/pre-puppet.sh"
./vagrant.dãã£ã¬ã¯ããªã«ã¹ã¯ãªãããäœæããŸãã
pre-puppet.shïŒ
#!/bin/bash # This script installs modules for puppet standalone echo "[Info] Running pre-puppet.sh for install modules" if [ "x$(dpkg -l | grep -E '^ii\s+git\s')" == "x" ] then echo "[Info] Installing git" apt-get -y install git || (echo "[Error] Cant install git" && exit 0) else echo "[Info] git already is installed, skipping" fi if [ "x$(gem list librarian-puppet|grep -v LOCAL)" == "x" ] then echo "[Info] Installing librarian-puppet" gem install librarian-puppet || (echo "[Error] Cant install librarian-puppet" && exit 0) else echo "[Info] librarian-puppet already is installed, skipping" fi if [ ! -e Puppetfile ] then cat > Puppetfile << EOF #!/usr/bin/env ruby #^syntax detection # Warning! # Do not edit this file, check pre-puppet.sh script! # forge "http://forge.puppetlabs.com" # use dependencies defined in Modulefile #modulefile mod 'puppetlabs/rabbitmq' mod 'saz/timezone' mod 'saz/locales' mod 'jpuppet/java-git', :git => "git://github.com/jpuppet/java.git" mod 'jfryman/nginx' EOF fi mkdir -p /vagrant/vagrant.d/modules echo "[Info] Installing puppet modules" librarian-puppet install --path=/vagrant/vagrant.d/modules/ || (echo "[Error] Cant install modules" && exit) rm Puppetfile* # Ugly hack for java cp -r /vagrant/vagrant.d/modules/java-git/modules/java /vagrant/vagrant.d/modules exit 0
ãªããžããªããã®ã¹ã¯ãªããã§ã¯ãgitãšlibrarian-puppetãã€ã³ã¹ããŒã«ãããlibrarian-puppetã®å©ããåããŠå¿ èŠãªã¢ãžã¥ãŒã«ãã€ã³ã¹ããŒã«ãããŸãã librarian-puppetæ©èœã®è©³çŽ°ã«ã€ããŠã¯ãgithubã§èŠã€ããããšãã§ããŸãïŒ github.com/rodjek/librarian-puppet gitãäºåã«ã€ã³ã¹ããŒã«ããããšãéèŠã§ãã ãŸããJavaãã€ã³ã¹ããŒã«ããããã®ã¢ãžã¥ãŒã«ãã³ããŒããå°ããªããã¯ãäœæããå¿ èŠããããŸããããã®ãªããžããªå ã«ã¯ãã¢ãžã¥ãŒã«èªäœã®æšæºã§ã¯ãªãå Žæãå°ããããŸãã ããããlibrarian-puppet github.com/mhahn/vagrant-librarian-puppetã® Vagrantãã©ã°ã€ã³ã䜿çšããããšãã§ããŸã
Vagrantfileã®æçµãã¥ãŒïŒ
# -*- mode: ruby -*- # vi: set ft=ruby : # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # All Vagrant configuration is done here. The most common configuration # options are documented and commented below. For a complete reference, # please see the online documentation at vagrantup.com. # Every Vagrant virtual environment requires a box to build off of. config.vm.box = "precise64" # The url from where the 'config.vm.box' box will be fetched if it # doesn't already exist on the user's system. # config.vm.box_url = "http://domain.com/path/to/above.box" config.vm.box_url = "http://files.vagrantup.com/precise64.box" # Create a forwarded port mapping which allows access to a specific port # within the machine from a port on the host machine. In the example below, # accessing "localhost:8080" will access port 80 on the guest machine. # config.vm.network :forwarded_port, guest: 3000, host: 3000 # Create a private network, which allows host-only access to the machine # using a specific IP. # config.vm.network :private_network, ip: "192.168.33.10" # Create a public network, which generally matched to bridged network. # Bridged networks make the machine appear as another physical device on # your network. # config.vm.network :public_network # If true, then any SSH connections made will enable agent forwarding. # Default value: false config.ssh.forward_agent = true # Enable shell provisioning config.vm.provision "shell", path: "./vagrant.d/pre-puppet.sh" ### Define VM for RabbitMQ config.vm.define "rmq", primary: true do |rmq| # Provider-specific configuration so you can fine-tune various # backing providers for Vagrant. These expose provider-specific options. # Example for VirtualBox: # rmq.vm.provider :virtualbox do |vb| # Don't boot with headless mode vb.gui = false # Use VBoxManage to customize the VM. For example to change memory: vb.customize ["modifyvm", :id, "--memory", "1024"] end # Networking options rmq.vm.network :private_network, ip: "192.168.100.5" rmq.vm.hostname = "rmq.example.com" # Enable provisioning with Puppet stand alone. Puppet manifests # are contained in a directory path relative to this Vagrantfile. # You will need to create the manifests directory and a manifest in # the file base.pp in the manifests_path directory. # rmq.vm.provision :puppet do |puppet| puppet.manifests_path = "./vagrant.d/manifests" puppet.manifest_file = "site-rmq.pp" puppet.module_path = "./vagrant.d/modules" puppet.options = "--fileserver=/vagrant/vagrant.d/fileserver.conf --verbose --debug" end end end
ããã§ããããã§ã¹ãã§ããŒãã説æã§ããŸãã
site-rmq.ppïŒ
# # This manifest describes development environment # RabbitMQ-server # class { 'timezone': timezone => 'Europe/Moscow', } class { 'locales': locales => ['ru_RU.UTF-8 UTF-8'], } # apt-get update # --------------------------------------- class apt_install { exec {'update': command => 'apt-get update', path => '/usr/bin', timeout => 0, } -> package {[ 'vim', ]: ensure => installed, } } # RabbitMQ service class rabbitmq_install { class { '::rabbitmq': service_manage => false, port => '5672', delete_guest_user => true, } rabbitmq_user { 'developer': admin => true, password => 'Password', } rabbitmq_vhost { 'habr': ensure => present, } rabbitmq_user_permissions { 'developer@habr': configure_permission => '.*', read_permission => '.*', write_permission => '.*', } rabbitmq_plugin {'rabbitmq_management': ensure => present, } } class java_install { class { "java": version => "1.7", jdk => true, jre => true, sources => false, javadoc => false, set_as_default => true, export_path => false, vendor => "oracle", } } # Include classes include apt_install include timezone include locales include rabbitmq_install include java_install
ãããžã§ã¯ãã®ã«ã¿ãã°ã§è¡ãã ãã§ååã§ãã
vagrant up
ã€ã³ã¿ãŒãããæ¥ç¶ã®é床ã«å¿ããŠæ°ååŸ ã¡ãŸãã ïŒæåã®èµ·åæã«ãUbuntuã€ã¡ãŒãžã¯åçž®ãããŸãïŒ
ããã§ãä»®æ³ãã·ã³ã«ã¢ã¯ã»ã¹ã§ããŸãã
vagrant ssh
ãããŠãããšãã°ãã€ã³ã¹ããŒã«ãããŠããJavaã確èªããŸãã
> vagrant ssh Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64) * Documentation: https://help.ubuntu.com/ Welcome to your Vagrant-built virtual machine. Last login: Sat May 17 12:28:08 2014 from 10.0.2.2 vagrant@rmq:~$ java -version java version "1.7.0_55" Java(TM) SE Runtime Environment (build 1.7.0_55-b13) Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)
ãŸããWebUI RabbitMQãµãŒãã¹ãéãããšãã§ããŸãã
ãã¡ãããå¿ èŠãªã¢ãžã¥ãŒã«ãæ€çŽ¢ããPuppetã䜿çšããŠãããªãã®å¿ãæããã®ãã€ã³ã¹ããŒã«ã§ããŸãã Puppetã³ãã¥ããã£ã®ã¡ãªããã¯éåžžã«æŽ»çºã§å€§ããªãã®ã§ãã ãŸããç®çã®ã¢ãžã¥ãŒã«ãèªåã§èšè¿°ããŠäœ¿çšããããšãã§ããŸãã äžèšã¯ã1ã€ã®ãµãŒãã¹ãš1ã€ã®ãã·ã³ã®åãªãäŸã§ãã 圌ãã¯ç¡æ°ã«ãªãããšãã§ããŸãã
æ zyãªäººã®ããã«ãããŒãã¹ãšããŠã github.github.com / wl4n / vagrant-skelã«ãã¡ã€ã«ãã¢ããããŒãããŸãã
ãã®èšäºããã³ãŒãã®ç°å¢ãã»ããã¢ããããã®ã§ã¯ãªããã³ãŒãã®å€æŽã«ããå€ãã®æéãè²»ãããæ¬çªç°å¢ã®éæ³ã®ãã°ãä¿®æ£ããã³åçŸããå¿ èŠæ§ãæé€ããã®ã«åœ¹ç«ã€ããšãé¡ã£ãŠããŸãã
åæ§ã®èšäºãžã®ãªã³ã¯ã§ãããChef Soloã䜿çšããŠããŸãïŒã³ã¡ã³ãããïŒïŒ habrahabr.ru/post/140714