Your SlideShare is downloading. ×
開発現場で活用するVagrant
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

開発現場で活用するVagrant

13,132
views

Published on

in JAWS-UG三都物語 2014

in JAWS-UG三都物語 2014

Published in: Technology

0 Comments
34 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
13,132
On Slideshare
0
From Embeds
0
Number of Embeds
15
Actions
Shares
0
Downloads
0
Comments
0
Likes
34
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 2014/07/05 shin1x1 夏の JAWS-UG 三都物語 2014 開発現場で活用する Vagrant
  • 2. Vagrant (c) 2014 Masashi Shinbara @shin1x1
  • 3. Vagrant (c) 2014 Masashi Shinbara @shin1x1
  • 4. Vagrant (c) 2014 Masashi Shinbara @shin1x1 軽量で、再現可能かつポータブルな 開発環境の構築、設定を行う
  • 5. Vagrant (c) 2014 Masashi Shinbara @shin1x1 Vagrant Ⅱ 開発環境を構築するツール
  • 6. (c) 2013 Masashi Shinbara @shin1x1 Vagrant については
  • 7. (c) 2014 Masashi Shinbara @shin1x1 Vagrantを 支えるツール
  • 8. (c) 2014 Masashi Shinbara @shin1x1 Vagrantと連携ツール Vagrant
  • 9. (c) 2014 Masashi Shinbara @shin1x1 Vagrantと連携ツール どれがなんやねん><
  • 10. Vagrantと連携ツール (c) 2014 Masashi Shinbara @shin1x1 • 仮想環境 • プロビジョニング • 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
  • 18. (c) 2014 Masashi Shinbara @shin1x1 Vagrantと連携ツール 仮想環境 プロビジョン
  • 19. https://github.com/shin1x1/vagrant-demo-20140705 今日のコード
  • 20. demo
  • 21. (c) 2013 Masashi Shinbara @shin1x1 仮想環境 プロビジョニング $ vagrant up シェル スクリプト
  • 22. httpd サーバ (c) 2014 Masashi Shinbara @shin1x1 • Apache • yum でインストール • document_root を /vagrant に
  • 23. Vagrantfile作成 (c) 2014 Masashi Shinbara @shin1x1 •chef/centos-6.5 を利用 $ vagrant init chef/centos-6.5
  • 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 で確認
  • 26. 仮想マシン起動 (c) 2014 Masashi Shinbara @shin1x1 $ vagrant up! (snip)! $ vagrant ssh • vagrant up で起動 • vagrant ssh でログイン
  • 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
  • 28. プロビジョニング実行 (c) 2014 Masashi Shinbara @shin1x1 • vagrant provision で実行
  • 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
  • 32. プロビジョニング実行 (c) 2014 Masashi Shinbara @shin1x1 • vagrant provision で実行
  • 33. Hello JAWS-UG!! (c) 2014 Masashi Shinbara @shin1x1
  • 34. 仮想マシン破棄 (c) 2014 Masashi Shinbara @shin1x1 $ vagrant destroy • vagrant destroy で破棄
  • 35. demo2
  • 36. (c) 2013 Masashi Shinbara @shin1x1 仮想環境 プロビジョニング $ vagrant up シェル スクリプト
  • 37. アプリケーション (c) 2014 Masashi Shinbara @shin1x1
  • 38. アプリケーションの構成 (c) 2014 Masashi Shinbara @shin1x1 • Linux(CentOS 6.5) • Apache • PHP • PostgreSQL
  • 39. ディレクトリ構成 (c) 2014 Masashi Shinbara @shin1x1 . ├── .gitignore ├── Vagrantfile ├── provision/ └── src/ アプリケーション Vagrant 関連 .vagrant を ignore
  • 40. demo3
  • 41. (c) 2013 Masashi Shinbara @shin1x1 仮想環境 プロビジョニング $ vagrant up
  • 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
  • 43. demo4
  • 44. Vagrant Share (c) 2014 Masashi Shinbara @shin1x1 • 仮想マシンをインターネットで公開 • Vagrant Cloud でユーザ登録 • vagrant login • vagrant share
  • 45. Vagrant Share (c) 2014 Masashi Shinbara @shin1x1
  • 46. demo5
  • 47. (c) 2013 Masashi Shinbara @shin1x1 仮想環境 プロビジョニング $ vagrant up
  • 48. AWSへデプロイ (c) 2014 Masashi Shinbara @shin1x1 • vagrant-aws プラグイン • config.vm.define で
 仮想マシンを分ける • EC2 の情報をVagrantfileに設定
  • 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 共通
  • 50. vagrant up
  • 51. 開発環境を作る (c) 2014 Masashi Shinbara @shin1x1 $ git clone REPO/project! $ cd project! $ vagrant up • 環境構築はこれだけ
  • 52. 開発環境を作る (c) 2014 Masashi Shinbara @shin1x1 • Vagrant / VirtualBox(仮想環境)以外
 をホスト環境に要求しない • vagrant up のみで完結 • vagrant ssh して、とか…><
  • 53. まとめ
  • 54. まとめ (c) 2013 Masashi Shinbara @shin1x1 • Vagrant はコントローラ • まずはシェルスクリプトから • vagrant up のみにこだわる
  • 55. @shin1x1 (c) 2014 Masashi Shinbara @shin1x1
  • 56. (c) 2014 Masashi Shinbara @shin1x1 Mac OS X 用 GUIアプリ VagrantX http://shin1x1.github.io/vagrantx/