Weitere ähnliche Inhalte
Ähnlich wie 開発現場で活用するVagrant (20)
Mehr von Masashi Shinbara (13)
Kürzlich hochgeladen (10)
開発現場で活用するVagrant
- 11. (c) 2014 Masashi Shinbara @shin1x1
Vagrantと仮想環境
VirtualBox
仮想マシン構築
Vagrant VMイメージはCentOS
IPは、xxx.xxx.xxx.xxx
メモリは、XXXMB
- 12. (c) 2014 Masashi Shinbara @shin1x1
Vagrantと仮想環境
VirtualBox
仮想マシン構築
Vagrant
VBoxManage を実行
- 13. (c) 2014 Masashi Shinbara @shin1x1
Vagrantと仮想環境
EC2インスタンス構築
Vagrant
AWS API を実行
AWS
- 14. (c) 2014 Masashi Shinbara @shin1x1
Vagrantとプロビジョニング
プロビジョニング実行
Vagrant
chef-solo を実行
- 15. (c) 2014 Masashi Shinbara @shin1x1
プロビジョニング実行
Vagrant ansible-playbook を
実行
Vagrantとプロビジョニング
- 16. (c) 2014 Masashi Shinbara @shin1x1
VagrantとDocker
コンテナ構築
コンテナ実行
Vagrant docker コマンドを
実行
- 17. (c) 2014 Masashi Shinbara @shin1x1
VagrantとDocker
http://www.slideshare.net/shin1x1/lt-up-33437883
- 22. httpd サーバ
(c) 2014 Masashi Shinbara @shin1x1
• Apache
• yum でインストール
• document_root を /vagrant に
- 24. Vagrantfile編集
(c) 2014 Masashi Shinbara @shin1x1
•不要なコメントは削除
# -*- mode: ruby -*-!
# vi: set ft=ruby :!
!
VAGRANTFILE_API_VERSION = "2"!
!
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|!
config.vm.box = "opscode-centos65"!
config.vm.network :private_network, ip: "192.168.33.200"!
end
- 25. 仮想マシンの状態を確認
(c) 2014 Masashi Shinbara @shin1x1
$ vagrant status!
Current machine states:!
!
default not created (virtualbox)!
• vagrant status で確認
- 27. シェルスクリプト
(c) 2014 Masashi Shinbara @shin1x1
• config.vm.provision :shell を指定
• 仮想マシンで、root ユーザで実行
!
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|!
config.vm.provision :shell, inline: "whoami"!
end
- 29. 設定ファイル
(c) 2014 Masashi Shinbara @shin1x1
• 仮想マシンの設定ファイルを /vagrant にコピー
% cp /etc/httpd/conf/httpd.conf /vagrant/
provision
• ホストで設定ファイルを編集
$ vim provision/httpd.conf
- 30. 設定ファイル
(c) 2014 Masashi Shinbara @shin1x1
• ホストで設定を追加
<VirtualHost *:80>!
DocumentRoot /vagrant!
</VirtualHost>
• コンテンツを作成
$ vim index.html!
Hello JAWS-UG !!
- 31. プロビジョニング
(c) 2014 Masashi Shinbara @shin1x1
• yum でインストール
• 設定ファイルコピー
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|!
config.vm.box = "opscode-centos65"!
config.vm.network :private_network, ip: "192.168.33.200"!
!
config.vm.provision :shell, :inline => <<-EOT!
yum -y install httpd!
cp -a /vagrant/provision/httpd.conf /etc/httpd/conf/!
chkconfig httpd on!
service httpd restart!
EOT!
end
- 39. ディレクトリ構成
(c) 2014 Masashi Shinbara @shin1x1
.
├── .gitignore
├── Vagrantfile
├── provision/
└── src/
アプリケーション
Vagrant 関連
.vagrant を ignore
- 42. Ansible でプロビジョニング
(c) 2014 Masashi Shinbara @shin1x1
• Ansible プロビジョナは使わない
• シェルスクリプトで、ansible インストール
• 仮想マシンで、ansible-playbook を実行
provision = <<-EOT
rpm -ivh http://ftp.riken.jp/Linux/fedora/epel/6/i386/epel-release-6-8.noarch.rpm
yum -y install ansible libselinux-python
ansible-playbook /vagrant/provision/vagrant.yml --connection=local
EOT
- 44. Vagrant Share
(c) 2014 Masashi Shinbara @shin1x1
• 仮想マシンをインターネットで公開
• Vagrant Cloud でユーザ登録
• vagrant login
• vagrant share
- 49. AWSへデプロイ
(c) 2014 Masashi Shinbara @shin1x1
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define :vbox do |vbox|
config.vm.provider :virtualbox do |provider, override|
override.vm.box = "opscode-centos65"
end
end
!
config.vm.provision :shell, :inline => provision
config.vm.synced_folder "src", "/share", type: "nfs"
!
config.vm.define :aws do |aws|
config.vm.provider :aws do |provider, override|
(AWS関連の設定)
end
end
end
VirtualBox
AWS
共通
- 52. 開発環境を作る
(c) 2014 Masashi Shinbara @shin1x1
• Vagrant / VirtualBox(仮想環境)以外
をホスト環境に要求しない
• vagrant up のみで完結
• vagrant ssh して、とか…><
- 56. (c) 2014 Masashi Shinbara @shin1x1
Mac OS X 用
GUIアプリ
VagrantX
http://shin1x1.github.io/vagrantx/