Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sunny4381 committed Jul 11, 2015
0 parents commit 33500c4
Show file tree
Hide file tree
Showing 19 changed files with 376 additions and 0 deletions.
116 changes: 116 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
Ruby Vagrant
===

Ruby 開発環境入りの Vagrant Box を提供します。

## 必須条件

### Windows

* お使いのパソコンが Intel VT/AMD-V に対応している必要があります。
Intel VT/AMD-V に対応しているかどうかが不明な場合、[VirtualChecker](http://www.forest.impress.co.jp/library/software/virtualcheck/)
ダウンロードし実行してください。
* Enabled と表示されれば Intel VT/AMD-V が有効になっており、Vagrant を使用することができます。
* Disabled と表示された場合、BIOS の設定を確認し Intel VT/AMD-V を有効にすることで Vagrant を使うことが出来ます。
* ユーザ名に日本語が含まれる場合、Vagrant が起動しない場合があります。
環境変数 `VAGRANT_HOME` を日本語を含まないディレクトリに設定し、VirtualBox の設定を変更し、default VM folder を日本語を含まないディレクトリに変更してください。
参考: [incompatible character encodings: CP850 and Windows-1252](https://github.com/mitchellh/vagrant/issues/3937)

### Mac

* Intel ベースの Mac では、Intel VT は有効になっていますが、もし使用できない場合は https://support.apple.com/ja-jp/TS2744 を参照してください。

## VirtualBox と Vagrant のインストール方法

前項の必須条件を満たしている場合、VirtualBox と Vagrant をインストールしてください。

1. [VirtualBox Download](https://www.virtualbox.org/wiki/Downloads) ページから VirtualBox をダウンロードしてインストールします。
Vagrant が 最新の 5.0 に対応していないため、4.3.30 をインストールしてください。
2. [Vagrant Download](http://www.vagrantup.com/downloads.html) ページから Vagrant をダウンロードしてインストールします。
3. (Windows の人のみ) [Git for Windows](https://msysgit.github.io/) ページから Git をダウンロードしてインストールします。
これは `vagrant up` 時に ssh コマンドが必要になるためで、Git に付属している ssh を用いるのが一番手っ取り早いのでインストールします。
4. (Windows の人のみ) [Tera Term](http://sourceforge.jp/projects/ttssh2/releases/) などのお好きな SSH クライアントをインストール。

※ Mac には最初から十分な機能を持つ SSH とターミナルがインストールされているので、Git と Tera Term のインストールは不要です。

## 使用方法

適当なディレクトリを作成し、次のような内容を持つ `Vagrantfile` を作成してください。

$ mkdir ruby-dev
$ cd ruby-dev
$ cat Vagrantfile

64 ビットの Vagrant Box を使用する場合:

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ruby-vagrant"
config.vm.box_url = "https://github.com/tokushimarb/ruby-vagrant/releases/download/20150711/ruby-vagrant-virtualbox-x86_64.box"
config.vm.network :forwarded_port, guest: 3000, host: 3000

config.vm.provider :virtualbox do |vb|
# see: http://blog.shibayu36.org/entry/2013/08/12/090545
# IPv6 と DNS でのネットワーク遅延対策で追記
vb.customize ["modifyvm", :id, "--natdnsproxy1", "off"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "off"]
end
end

32 ビットの Vagrant Box を使用する場合:

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ruby-vagrant"
config.vm.box_url = "https://github.com/tokushimarb/ruby-vagrant/releases/download/20150711/ruby-vagrant-virtualbox-i386.box"
config.vm.network :forwarded_port, guest: 3000, host: 3000

config.vm.provider :virtualbox do |vb|
# see: http://blog.shibayu36.org/entry/2013/08/12/090545
# IPv6 と DNS でのネットワーク遅延対策で追記
vb.customize ["modifyvm", :id, "--natdnsproxy1", "off"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "off"]
end
end

次のコマンドで起動できます。

$ vagrant up

Windows の方は、別途 Git をインストールし git-bash から上記コマンドを実行してください。

`vagrant up` には 5 分から 10 分ぐらいかかるので、コーヒーでも飲みながら待ってください。
もし、`vagrant up` が失敗する場合、次の点を確認して下さい。
* Intel VT/AMD-V が有効になっている。
* ユーザ名はアルファベット、数字、ハイフン、アンダーバーのみを含む。

起動したら次のコマンドでログインしてください。

$ vagrant ssh

Windows の方は Tera Term などの SSH クライアントで、
次の接続情報を使用してログインしたほうが快適に使えると思います。

* host: localhost
* port: 2222
* user: vagrant
* password: vagrant

## Vagrant Box の中身

64 ビット:
* CentOS 7.1.1503 (2015-07-12 時点での最新)
* RVM 1.26.11
* Ruby 2.2.2p95

32 ビット:
* CentOS 6.6 (2015-07-12 時点での最新)
* RVM 1.26.11
* Ruby 2.2.2p95

## ライセンス

本書および `Vagrantfile` は、
[![クリエイティブ・コモンズ・ライセンス](https://i.creativecommons.org/l/by/4.0/88x31.png) クリエイティブ・コモンズ 表示 4.0 国際 ライセンスの下に提供されています。](http://creativecommons.org/licenses/by/4.0/)

それ以外のものについては、それぞれのライセンスにしたがいます。
13 changes: 13 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ruby-vagrant"
config.vm.box_url = "https://github.com/shirasagi/ss-vagrant/releases/download/v0.7.0/ss-vagrant-virtualbox-x86_64.box"
config.vm.network :forwarded_port, guest: 3000, host: 3000

config.vm.provider :virtualbox do |vb|
# see: http://blog.shibayu36.org/entry/2013/08/12/090545
# IPv6 と DNS でのネットワーク遅延対策で追記
vb.customize ["modifyvm", :id, "--natdnsproxy1", "off"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "off"]
end
end
32 changes: 32 additions & 0 deletions packer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Packer Tempalte for Ruby Vagrant
===

Ruby 開発環境入りの Vagrant Box をビルドするための Packer Template です。

OS には CentOS を使用し、VirtualBox 用の Vagrant Box をビルドすることがでます。

## ビルド方法

[VirtualBox](https://www.virtualbox.org/)[packer](https://www.packer.io/) をインストールしてください。
Vagrant が 最新の VirtualBox 5.0 に対応していないため、VirtualBox 4.3.30 をインストールしてください。

Packer Tempalte for Ruby Vagrant では 64 ビットの Vagrant Box と
32 ビットの Vagrant Box をビルドすることができます。

64 ビットの Vagrant Box をビルドする場合:

$ packer build -only=virtualbox-iso ./template.json

ビルドに成功すると `ruby-vagrant-virtualbox-x86_64.box` ができます。

32 ビットの Vagrant Box をビルドする場合:

$ packer build -only=virtualbox-iso -var-file=virtualbox-i386-variables.json template.json

ビルドに成功すると `ruby-vagrant-virtualbox-i386.box` ができます。

ビルドには 20 分ぐらいかかります。

## ライセンス

[![クリエイティブ・コモンズ・ライセンス](https://i.creativecommons.org/l/by/4.0/88x31.png) クリエイティブ・コモンズ 表示 4.0 国際 ライセンスの下に提供されています。](http://creativecommons.org/licenses/by/4.0/)
41 changes: 41 additions & 0 deletions packer/http/ks.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
install
cdrom
lang en_US.UTF-8
keyboard us
network --onboot yes --device eth0 --bootproto dhcp --noipv6
rootpw --plaintext vagrant
firewall --enabled --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone Asia/Tokyo
bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"

text
skipx
zerombr

clearpart --all --initlabel
autopart

auth --useshadow --enablemd5
firstboot --disabled
reboot

%packages --ignoremissing
@core
bzip2
kernel-devel
kernel-headers
-ipw2100-firmware
-ipw2200-firmware
-ivtv-firmware
%end

%post
/usr/bin/yum -y install sudo
/usr/sbin/groupadd -g 501 vagrant
/usr/sbin/useradd vagrant -u 501 -g vagrant -G wheel
echo "vagrant"|passwd --stdin vagrant
echo "vagrant ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/vagrant
chmod 0440 /etc/sudoers.d/vagrant
%end
2 changes: 2 additions & 0 deletions packer/scripts/base.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers
yum -y install gcc make gcc-c++ kernel-devel-`uname -r` perl bzip2
3 changes: 3 additions & 0 deletions packer/scripts/bundler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export rvmsudo_secure_path=1
source /etc/profile.d/rvm.sh
rvmsudo gem install bundler
5 changes: 5 additions & 0 deletions packer/scripts/cleanup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# yum -y erase gtk2 libX11 hicolor-icon-theme avahi freetype bitstream-vera-fonts
yum -y clean all
rm -rf VBoxGuestAdditions_*.iso
rm -rf /tmp/rubygems-*

11 changes: 11 additions & 0 deletions packer/scripts/disable-firewall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
os=${os:-"centos7"}

if [ "$os" == "centos6" ]; then
/sbin/chkconfig iptables off
/sbin/chkconfig ip6tables off
fi

if [ "$os" == "centos7" ]; then
systemctl stop firewalld
systemctl disable firewalld
fi
18 changes: 18 additions & 0 deletions packer/scripts/disable-ipv6.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
os=${os:-"centos7"}

if [ "$os" == "centos6" ]; then
echo 'NETWORKING_IPV6=no' >> /etc/sysconfig/network
echo "options ipv6 disable=1" > /etc/modprobe.d/disable-ipv6.conf
/sbin/chkconfig ip6tables off
sed -ie 's/::1/# ::1/' /etc/hosts
fi

if [ "$os" == "centos7" ]; then
sysctl -w net.ipv6.conf.all.disable_ipv6=1
sysctl -w net.ipv6.conf.default.disable_ipv6=1
cat << _EOT_ | tee /etc/sysctl.d/99-disableipv6.conf
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
_EOT_
sed -ie 's/::1/# ::1/' /etc/hosts
fi
2 changes: 2 additions & 0 deletions packer/scripts/epel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
yum install -y epel-release
sed -ie 's/enabled=1/enabled=0/' /etc/yum.repos.d/epel.repo
4 changes: 4 additions & 0 deletions packer/scripts/extra-package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
yum install --enablerepo=epel -y p7zip
yum install -y tree
# source /etc/profile.d/rvm.sh; rvmsudo gem install debase
# source /etc/profile.d/rvm.sh; rvmsudo gem install ruby-debug-ide
8 changes: 8 additions & 0 deletions packer/scripts/fix-slow-dns.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -eux

## https://access.redhat.com/site/solutions/58625 (subscription required)
# http://www.linuxquestions.org/questions/showthread.php?p=4399340#post4399340
# add 'single-request-reopen' so it is included when /etc/resolv.conf is generated
echo 'RES_OPTIONS="single-request-reopen"' >> /etc/sysconfig/network
service network restart
echo '==> Slow DNS fix applied (single-request-reopen)'
12 changes: 12 additions & 0 deletions packer/scripts/rvm-ruby.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# install rvm & ruby
gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
if [ $? -ne 0 ]; then
gpg2 --keyserver hkp://pgp.mit.edu --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
fi
curl -sSL https://get.rvm.io | sudo bash -s stable --ruby=2.2.2

echo "gem: --no-ri --no-rdoc" > /home/vagrant/.gemrc
chown vagrant:vagrant /home/vagrant/.gemrc

echo "export rvmsudo_secure_path=0" > /etc/profile.d/rvmsudo_secure_path.sh
sed -ie 's/\(Defaults[\t ][\t ]*secure_path\)/# \1/' /etc/sudoers
8 changes: 8 additions & 0 deletions packer/scripts/update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -eux
echo "==> Applying updates"
yum -y update

# reboot
echo "Rebooting the machine..."
reboot
sleep 60
6 changes: 6 additions & 0 deletions packer/scripts/vagrant.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
date > /etc/vagrant_box_build_time

mkdir -pm 700 /home/vagrant/.ssh
curl -L https://raw.githubusercontent.com/mitchellh/vagrant/master/keys/vagrant.pub -o /home/vagrant/.ssh/authorized_keys
chmod 0600 /home/vagrant/.ssh/authorized_keys
chown -R vagrant:vagrant /home/vagrant/.ssh
7 changes: 7 additions & 0 deletions packer/scripts/virtualbox.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
VBOX_VERSION=$(cat /home/vagrant/.vbox_version)
cd /tmp
mount -o loop /home/vagrant/VBoxGuestAdditions_$VBOX_VERSION.iso /mnt
sh /mnt/VBoxLinuxAdditions.run --nox11
umount /mnt
rm -rf /home/vagrant/VBoxGuestAdditions_*.iso
rm -rf /home/vagrant/.vbox_version
3 changes: 3 additions & 0 deletions packer/scripts/zerodisk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dd if=/dev/zero of=/EMPTY bs=1M
rm -f /EMPTY

76 changes: 76 additions & 0 deletions packer/template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"variables": {
"os": "centos7",
"guest_os_type": "RedHat_64",
"iso_url": "http://ftp.iij.ad.jp/pub/linux/centos/7.1.1503/isos/x86_64/CentOS-7-x86_64-Minimal-1503-01.iso",
"iso_checksum": "7c1e34e95c991175290d704dbdcc6531774cbecb",
"iso_checksum_type": "sha1",
"memory": "1024",
"arch": "x86_64"
},
"provisioners": [
{
"type": "shell",
"execute_command": "echo 'vagrant' | {{ .Vars }} sudo -E -S bash '{{.Path}}'",
"environment_vars": [
"os={{user `os`}}",
"arch={{user `arch`}}"
],
"override": {
"virtualbox-iso": {
"scripts": [
"scripts/fix-slow-dns.sh",
"scripts/update.sh",
"scripts/epel.sh",
"scripts/base.sh",
"scripts/vagrant.sh",
"scripts/virtualbox.sh",
"scripts/rvm-ruby.sh",
"scripts/bundler.sh",
"scripts/disable-firewall.sh",
"scripts/disable-ipv6.sh",
"scripts/extra-package.sh",
"scripts/cleanup.sh",
"scripts/zerodisk.sh"
]
}
}
}
],
"post-processors": [
{
"type": "vagrant",
"override": {
"virtualbox": {
"output": "ruby-vagrant-virtualbox-{{user `arch`}}.box"
}
}
}
],
"builders": [
{
"type": "virtualbox-iso",
"boot_command": [
"<tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg<enter><wait>"
],
"boot_wait": "10s",
"disk_size": 15195,
"guest_os_type": "{{user `guest_os_type`}}",
"http_directory": "http",
"iso_checksum": "{{user `iso_checksum`}}",
"iso_checksum_type": "{{user `iso_checksum_type`}}",
"iso_url": "{{user `iso_url`}}",
"ssh_username": "vagrant",
"ssh_password": "vagrant",
"ssh_port": 22,
"ssh_wait_timeout": "10000s",
"shutdown_command": "echo '/sbin/halt -h -p' > /tmp/shutdown.sh; echo 'vagrant'|sudo -S sh '/tmp/shutdown.sh'",
"guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso",
"virtualbox_version_file": ".vbox_version",
"vboxmanage": [
[ "modifyvm", "{{.Name}}", "--memory", "{{user `memory`}}" ],
[ "modifyvm", "{{.Name}}", "--cpus", "1" ]
]
}
]
}
9 changes: 9 additions & 0 deletions packer/virtualbox-i386-variables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"os": "centos6",
"guest_os_type" : "RedHat",
"iso_url" : "http://ftp.iij.ad.jp/pub/linux/centos/6.6/isos/i386/CentOS-6.6-i386-minimal.iso",
"iso_checksum" : "6760e2e2a807081731763fcfa680d8413cf24cb7",
"iso_checksum_type" : "sha1",
"memory" : "512",
"arch": "i386"
}

0 comments on commit 33500c4

Please sign in to comment.