-
Notifications
You must be signed in to change notification settings - Fork 4
/
Vagrantfile
145 lines (134 loc) · 4.78 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# encoding: utf-8
# This file originally created at http://rove.io/81034967e7d436b5f9972910f9e39115
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Thanks to colinsurprenant for this
# https://github.com/colinsurprenant/redstorm/blob/master/vagrant/Vagrantfile
#
# @param swap_size_mb [Integer] swap size in megabytes
# @param swap_file [String] full path for swap file, default is /swapfile1
# @return [String] the script text for shell inline provisioning
def create_swap(swap_size_mb, swap_file = "/swapfile1")
<<-EOS
if [ ! -f #{swap_file} ]; then
echo "Creating #{swap_size_mb}mb swap file=#{swap_file}. This could take a while..."
dd if=/dev/zero of=#{swap_file} bs=1024 count=#{swap_size_mb * 1024}
mkswap #{swap_file}
chmod 0600 #{swap_file}
swapon #{swap_file}
if ! grep -Fxq "#{swap_file} swap swap defaults 0 0" /etc/fstab
then
echo "#{swap_file} swap swap defaults 0 0" >> /etc/fstab
fi
fi
EOS
end
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.ssh.forward_agent = true
config.vm.network :forwarded_port, guest: 3000, host: 3000
config.vm.network "private_network", ip: "10.10.10.10"
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--memory", "1024", "--ioapic", "on", "--cpus", 2]
end
provider = if ENV['VAGRANT_DEFAULT_PROVIDER'].nil? || ENV['VAGRANT_DEFAULT_PROVIDER'].empty?
'virtualbox'
else
ENV['VAGRANT_DEFAULT_PROVIDER']
end
# Thanks to spkane for this workaround to a vagrant bug
# https://github.com/mitchellh/vagrant/issues/5199
#------------------------------------------------------
# Require the Trigger plugin for Vagrant
unless Vagrant.has_plugin?('vagrant-triggers')
# Attempt to install ourself.
# Bail out on failure so we don't get stuck in an infinite loop.
system('vagrant plugin install vagrant-triggers') || exit!
# Relaunch Vagrant so the new plugin(s) are detected.
# Exit with the same status code.
exit system('vagrant', *ARGV)
end
# Workaround for https://github.com/mitchellh/vagrant/issues/5199
config.trigger.before [:reload, :up], stdout: true do
SYNCED_FOLDER = ".vagrant/machines/default/#{provider}/synced_folders"
info "Trying to delete folder #{SYNCED_FOLDER}"
begin
File.delete(SYNCED_FOLDER)
rescue StandardError => e
warn "Could not delete folder #{SYNCED_FOLDER}."
warn e.inspect
end
end
#------------------------------------------------------
%w(autoconf bison build-essential libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libncurses5-dev libffi-dev libgdbm3 libgdbm-dev libffi-dev).each do |l|
config.vm.provision :shell, :inline => "apt-get install -y #{l}"
end
config.vm.provision :chef_solo do |chef|
chef.binary_env = 'RUBY_CONFIGURE_OPTS=--disable-install-doc'
chef.version = "13.7"
chef.cookbooks_path = ["cookbooks"]
chef.add_recipe :apt
chef.add_recipe 'build-essential'
chef.add_recipe :openssl
chef.add_recipe :readline
chef.add_recipe :logrotate
chef.add_recipe 'sc-mongodb::default'
chef.add_recipe 'sqlite'
chef.add_recipe 'subversion'
chef.add_recipe 'vim'
chef.add_recipe 'nginx'
chef.add_recipe 'git'
chef.add_recipe 'nodejs'
chef.add_recipe 'ruby_build'
chef.add_recipe 'ruby_rbenv::user'
chef.add_recipe "ruby_rbenv::user_install"
chef.add_recipe 'redis::install_from_package'
chef.json = {
'mongodb_instance' => {
:dbpath => "/var/lib/mongodb",
:logpath => "/var/log/mongodb",
:port => "27017"
},
:subversion => {
:repo_dir => "/srv/svn",
:repo_name => "repo",
:server_name => "svn",
:user => "subversion",
:password => "subversion"
},
:vim => {
:extra_packages => [
"vim-rails"
]
},
:nginx => {
:dir => "/etc/nginx",
:log_dir => "/var/log/nginx",
:binary => "/usr/sbin/nginx",
:user => "www-data",
:init_style => "runit",
:pid => "/var/run/nginx.pid",
:worker_connections => "1024"
},
:git => {
:prefix => "/usr/local"
},
:rbenv => {
:user_installs => [
:user => 'vagrant',
:rubies => ["2.1.6"],
:global => "2.1.6",
:gems => {
"2.1.6" => [
{ 'name' => 'bundler' },
{ 'name' => 'pry' },
{ 'name' => 'awesome_print' }
]
}
]
}
}
end
config.vm.provision :shell, path: 'grab_projects.sh', args: '/vagrant/', privileged: false
config.vm.provision :shell, :inline => create_swap(1024, "/mnt/swapfile1")
end