モダン開発環境20. VMハイパーバイザー
製品名 価格 Windows Mac
OracleVirtualBox Free Yes Yes
MicrosoftVirtualPC Free Yes
Microsoft Hyper-V 高い Yes
VMWare Workstation ¥30,000 Yes
VMWare Fusion ¥5,000 Yes
Parallels Desktop ¥8,000 Yes
VMWare vSphere 高い
37. 初期設定
$ vagrant box add ubuntu1204 https://s3.amazonaws.com/
gsc-vagrant-boxes/ubuntu-12.04.2-i386-chef-11-
omnibus.box
$ vagrant box add ubuntu1204 https://s3.amazonaws.com/
gsc-vagrant-boxes/ubuntu-12.04.2-server-amd64.box
VirtualBox
VMWare Fusion
44. VMを削除
$ du -sh .vagrant/
1.6G! .vagrant/
$ vagrant destroy
$ du -sh .vagrant/
0B! .vagrant/
49. # -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(“2”) do |config|
config.vm.box = “ubuntu1204”
end
Rubyで記述
51. Vagrant.configure(“2”) do |config|
config.vm.define :web do |web|
web.vm.box = “ubuntu1204”
web.vm.network :private_network, ip: “192.168.99.1”
end
config.vm.define :db do |db|
db.vm.box = “ubuntu1204”
db.vm.network :private_network, ip: “192.168.99.2”
end
end
Vagrantfile
57. • up 時に自動実行
• up 後にも任意で実行できる
• halt → up を手軽に実行
$ vagrant provision
$ vagrant reload
63. インストール
(chef + knife-solo)
$ gem install knife-solo
$ git clone git://github.com/matschaffer/knife-solo.git
$ cd knife-solo
$ bundle && bundle exec rake install
* http://shimotori.github.io/blog-it/2013/04/30/1-knife-solo-cautions/
Version 0.2.0
Version HEAD (0.3.0-pre3)
65. Cookbook作成
vm$ cd /vagrant
vm$ knife cookbook create myrecipe -o cookbooks
vm$ ls -F cookbooks/
myrecipe/
vm$ ls -F cookbooks/myrecipe/
CHANGELOG.md README.md attributes/ definitions/
files/ libraries/ metadata.rb providers/
recipes/ resources/ templates/
67. $ vagrant reload
...
[default] Running provisioner: chef_solo...
Generating chef JSON and uploading...
Running chef-solo...
[2013-05-17T11:07:27+00:00] INFO: *** Chef 11.4.0 ***
...
[2013-05-17T11:07:28+00:00] INFO: Chef Run complete in 0.017913367 seconds
...
動作確認
71. $ vagrant provision
...
[default] Running provisioner: chef_solo...
Generating chef JSON and uploading...
Running chef-solo...
...
[2013-05-17T11:24:54+00:00] INFO: Processing package[git] action install
(myrecipe::default line 10)
[2013-05-17T11:25:11+00:00] INFO: Chef Run complete in 17.741444756
seconds
...
実行
74. [“apache2-mpm-prefork”, “libapache2-mod-php5”].each do |pkg|
package pkg do
action :install
end
end
service "apache2" do
supports :status => true, :restart => true, :reload => true
action [ :enable, :start ]
end
template "apache2-site-dev" do
path "/etc/apache2/sites-available/dev"
source "apache2-site-dev.erb"
owner "root"
group "root"
mode 0644
notifies :reload, 'service[apache2]'
end
execute "apache2-sites-disable-default" do
only_if { File.exists?("/etc/apache2/sites-enabled/000-default") }
command "a2dissite default"
notifies :reload, 'service[apache2]'
end
execute "apache2-sites-enable-dev" do
not_if { File.exists?("/etc/apache2/sites-enabled/dev") }
command "a2ensite dev"
notifies :reload, 'service[apache2]'
end
75. <VirtualHost *:80>
DocumentRoot <%= node['apache2']['document_root'] %>
EnableMMAP off
EnableSendfile off
</VirtualHost>
cookbooks/myrecipe/templates/default/apache2-site-dev.erb
76. config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
chef.add_recipe "myrecipe"
chef.json = {
"apache2" => {
"document_root" => "/vagrant/web"
}
}
end
Vagrantfile