• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
 

開発現場で活用するVagrant

on

  • 464 views

in JAWS-UG三都物語 2014

in JAWS-UG三都物語 2014

Statistics

Views

Total Views
464
Views on SlideShare
255
Embed Views
209

Actions

Likes
3
Downloads
0
Comments
0

1 Embed 209

http://www.1x1.jp 209

Accessibility

Categories

Upload Details

Uploaded via SlideShare as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    開発現場で活用するVagrant 開発現場で活用するVagrant Presentation Transcript

    • 2014/07/05 shin1x1 夏の JAWS-UG 三都物語 2014 開発現場で活用する Vagrant
    • Vagrant (c) 2014 Masashi Shinbara @shin1x1
    • Vagrant (c) 2014 Masashi Shinbara @shin1x1
    • Vagrant (c) 2014 Masashi Shinbara @shin1x1 軽量で、再現可能かつポータブルな 開発環境の構築、設定を行う
    • Vagrant (c) 2014 Masashi Shinbara @shin1x1 Vagrant Ⅱ 開発環境を構築するツール
    • (c) 2013 Masashi Shinbara @shin1x1 Vagrant については
    • (c) 2014 Masashi Shinbara @shin1x1 Vagrantを 支えるツール
    • (c) 2014 Masashi Shinbara @shin1x1 Vagrantと連携ツール Vagrant
    • (c) 2014 Masashi Shinbara @shin1x1 Vagrantと連携ツール どれがなんやねん><
    • Vagrantと連携ツール (c) 2014 Masashi Shinbara @shin1x1 • 仮想環境 • プロビジョニング • Vagrantは、コントローラに徹する
    • (c) 2014 Masashi Shinbara @shin1x1 Vagrantと仮想環境 VirtualBox 仮想マシン構築 Vagrant VMイメージはCentOS IPは、xxx.xxx.xxx.xxx メモリは、XXXMB
    • (c) 2014 Masashi Shinbara @shin1x1 Vagrantと仮想環境 VirtualBox 仮想マシン構築 Vagrant VBoxManage を実行
    • (c) 2014 Masashi Shinbara @shin1x1 Vagrantと仮想環境 EC2インスタンス構築 Vagrant AWS API を実行 AWS
    • (c) 2014 Masashi Shinbara @shin1x1 Vagrantとプロビジョニング プロビジョニング実行 Vagrant chef-solo を実行
    • (c) 2014 Masashi Shinbara @shin1x1 プロビジョニング実行 Vagrant ansible-playbook を 実行 Vagrantとプロビジョニング
    • (c) 2014 Masashi Shinbara @shin1x1 VagrantとDocker コンテナ構築
 コンテナ実行 Vagrant docker コマンドを 実行
    • (c) 2014 Masashi Shinbara @shin1x1 VagrantとDocker http://www.slideshare.net/shin1x1/lt-up-33437883
    • (c) 2014 Masashi Shinbara @shin1x1 Vagrantと連携ツール 仮想環境 プロビジョン
    • https://github.com/shin1x1/vagrant-demo-20140705 今日のコード
    • demo
    • (c) 2013 Masashi Shinbara @shin1x1 仮想環境 プロビジョニング $ vagrant up シェル スクリプト
    • httpd サーバ (c) 2014 Masashi Shinbara @shin1x1 • Apache • yum でインストール • document_root を /vagrant に
    • Vagrantfile作成 (c) 2014 Masashi Shinbara @shin1x1 •chef/centos-6.5 を利用 $ vagrant init chef/centos-6.5
    • 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
    • 仮想マシンの状態を確認 (c) 2014 Masashi Shinbara @shin1x1 $ vagrant status! Current machine states:! ! default not created (virtualbox)! • vagrant status で確認
    • 仮想マシン起動 (c) 2014 Masashi Shinbara @shin1x1 $ vagrant up! (snip)! $ vagrant ssh • vagrant up で起動 • vagrant ssh でログイン
    • シェルスクリプト (c) 2014 Masashi Shinbara @shin1x1 • config.vm.provision :shell を指定 • 仮想マシンで、root ユーザで実行 ! Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|! config.vm.provision :shell, inline: "whoami"! end
    • プロビジョニング実行 (c) 2014 Masashi Shinbara @shin1x1 • vagrant provision で実行
    • 設定ファイル (c) 2014 Masashi Shinbara @shin1x1 • 仮想マシンの設定ファイルを /vagrant にコピー % cp /etc/httpd/conf/httpd.conf /vagrant/ provision • ホストで設定ファイルを編集 $ vim provision/httpd.conf
    • 設定ファイル (c) 2014 Masashi Shinbara @shin1x1 • ホストで設定を追加 <VirtualHost *:80>! DocumentRoot /vagrant! </VirtualHost> • コンテンツを作成 $ vim index.html! Hello JAWS-UG !!
    • プロビジョニング (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
    • プロビジョニング実行 (c) 2014 Masashi Shinbara @shin1x1 • vagrant provision で実行
    • Hello JAWS-UG!! (c) 2014 Masashi Shinbara @shin1x1
    • 仮想マシン破棄 (c) 2014 Masashi Shinbara @shin1x1 $ vagrant destroy • vagrant destroy で破棄
    • demo2
    • (c) 2013 Masashi Shinbara @shin1x1 仮想環境 プロビジョニング $ vagrant up シェル スクリプト
    • アプリケーション (c) 2014 Masashi Shinbara @shin1x1
    • アプリケーションの構成 (c) 2014 Masashi Shinbara @shin1x1 • Linux(CentOS 6.5) • Apache • PHP • PostgreSQL
    • ディレクトリ構成 (c) 2014 Masashi Shinbara @shin1x1 . ├── .gitignore ├── Vagrantfile ├── provision/ └── src/ アプリケーション Vagrant 関連 .vagrant を ignore
    • demo3
    • (c) 2013 Masashi Shinbara @shin1x1 仮想環境 プロビジョニング $ vagrant up
    • 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
    • demo4
    • Vagrant Share (c) 2014 Masashi Shinbara @shin1x1 • 仮想マシンをインターネットで公開 • Vagrant Cloud でユーザ登録 • vagrant login • vagrant share
    • Vagrant Share (c) 2014 Masashi Shinbara @shin1x1
    • demo5
    • (c) 2013 Masashi Shinbara @shin1x1 仮想環境 プロビジョニング $ vagrant up
    • AWSへデプロイ (c) 2014 Masashi Shinbara @shin1x1 • vagrant-aws プラグイン • config.vm.define で
 仮想マシンを分ける • EC2 の情報をVagrantfileに設定
    • 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 共通
    • vagrant up
    • 開発環境を作る (c) 2014 Masashi Shinbara @shin1x1 $ git clone REPO/project! $ cd project! $ vagrant up • 環境構築はこれだけ
    • 開発環境を作る (c) 2014 Masashi Shinbara @shin1x1 • Vagrant / VirtualBox(仮想環境)以外
 をホスト環境に要求しない • vagrant up のみで完結 • vagrant ssh して、とか…><
    • まとめ
    • まとめ (c) 2013 Masashi Shinbara @shin1x1 • Vagrant はコントローラ • まずはシェルスクリプトから • vagrant up のみにこだわる
    • @shin1x1 (c) 2014 Masashi Shinbara @shin1x1
    • (c) 2014 Masashi Shinbara @shin1x1 Mac OS X 用 GUIアプリ VagrantX http://shin1x1.github.io/vagrantx/