forked from treasure-data/omnibus-td-agent
-
Notifications
You must be signed in to change notification settings - Fork 50
/
Vagrantfile
194 lines (167 loc) · 6.58 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'vagrant'
if Vagrant::VERSION.to_f < 1.5
raise "The Omnibus Build Lab only supports Vagrant >= 1.5.0"
end
host_project_path = File.expand_path('..', __FILE__)
project_name = 'td-agent'
host_name = "#{project_name}-omnibus-build-lab"
bootstrap_chef_version = '12.10.24'
Vagrant.configure('2') do |config|
#config.vm.hostname = "#{project_name}-omnibus-build-lab"
use_nfs = false
chef_version = bootstrap_chef_version
%w{
ubuntu-10.04
ubuntu-10.04-i386
ubuntu-12.04
ubuntu-12.04-i386
ubuntu-14.04
ubuntu-14.04-i386
ubuntu-16.04
debian-7.10
debian-8.4
centos-5.11
centos-5.11-i386
centos-6.7
centos-6.7-i386
centos-7.2
}.each_with_index do |platform, index|
project_build_user = 'vagrant'
guest_project_path = "/home/#{project_build_user}/#{File.basename(host_project_path)}"
config.vm.define platform do |c|
chef_run_list = []
case platform
when /^freebsd/
raise "Not supported yet: FreeBSD"
when /^ubuntu/, /^debian/
chef_run_list << 'recipe[apt::default]'
when /^centos/
chef_run_list << 'recipe[yum-epel::default]'
else
raise "Unknown platform: #{platform}"
end
c.vm.box = "opscode-#{platform}"
c.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_#{platform}_chef-provisionerless.box"
c.omnibus.chef_version = chef_version
c.vm.provider :virtualbox do |vb|
# Give enough horsepower to build without taking all day.
vb.customize [
'modifyvm', :id,
'--memory', '4096',
'--cpus', '4'
]
end
# Shared configuraiton
chef_run_list << 'recipe[omnibus::default]'
config.berkshelf.enabled = true
config.ssh.forward_agent = true
config.vm.synced_folder '.', '/vagrant', :id => 'vagrant-root', :nfs => use_nfs
config.vm.synced_folder host_project_path, guest_project_path, :nfs => use_nfs
if platform == 'ubuntu-14.04-i386'
config.vbguest.auto_update = true
else
config.vbguest.auto_update = false
end
c.vm.provision :chef_solo do |chef|
chef.synced_folder_type = "nfs" if use_nfs
chef.json = {
'omnibus' => {
'build_user' => project_build_user,
'build_dir' => guest_project_path,
'ruby_version' => '2.1.8',
'install_dir' => "/opt/#{project_name}"
}
}
chef.run_list = chef_run_list
end
# We have to nuke any chef omnibus packages (used during provisioning) before
# we build new chef omnibus packages!
c.vm.provision :shell, :privileged => true, :inline => <<-REMOVE_OMNIBUS
if command -v dpkg &>/dev/null; then
dpkg -P #{project_name} || true
elif command -v rpm &>/dev/null; then
rpm -ev #{project_name} || true
fi
rm -rf /opt/#{project_name} || true
REMOVE_OMNIBUS
# it will be resolved after new omnibus cookbook released, 2.3.1 or later.
if platform.start_with?('centos-5.10')
c.vm.provision :shell, :privileged => true, :inline => <<-UPDATE_GCC
yum install gcc44 gcc44-c++
UPDATE_GCC
export_gcc = <<-GCC_EXPORT
export CC="gcc44"
export CXX="g++44"
GCC_EXPORT
else
export_gcc = ''
end
c.vm.provision :shell, :privileged => false, :inline => <<-OMNIBUS_BUILD
#{export_gcc}
export PATH="/opt/omnibus-toolchain/embedded/bin/:$PATH"
sudo mkdir -p /opt/#{project_name}
sudo chown #{project_build_user} /opt/#{project_name}
cd #{guest_project_path}
bundle install --path=/home/#{project_build_user}/.bundler
bundle exec omnibus build #{project_name}2
OMNIBUS_BUILD
end # config.vm.define.platform
end # each_with_index
config.vm.define 'amazon' do |c|
project_build_user = 'ec2-user'
guest_project_path = "/home/#{project_build_user}/#{File.basename(host_project_path)}"
# Amazon Linux doesn't have SELinux so it should be removed from Omnibus run_list.
chef_run_list = ['recipe[yum-epel::default]'] + ['omnibus::_common', 'omnibus::_bash', 'omnibus::_cacerts', 'omnibus::_ccache',
'omnibus::_chruby', 'omnibus::_compile', 'omnibus::_ruby', 'omnibus::_git', 'omnibus::_github', 'omnibus::_openssl',
'omnibus::_packaging', 'omnibus::_rsync', 'omnibus::_xml', 'omnibus::_yaml', 'omnibus::_environment'].map { |r|
"recipe[#{r}]"
}
c.vm.box = "dummy"
c.vm.box_url = "https://github.com/mitchellh/vagrant-aws/raw/master/dummy.box"
c.omnibus.chef_version = chef_version
c.vm.provider :aws do |aws, override|
aws.access_key_id = ENV['AWS_ACCESS_KEY_ID']
aws.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
aws.keypair_name = "td-agent-build"
aws.ami = "ami-08111162"
aws.instance_type = 'm3.large'
aws.tags = {'Name' => 'td-agent-build'}
aws.security_groups = ['td-agent-build']
aws.user_data = "#!/bin/bash\nsed -i -e 's/^Defaults.*requiretty/# Defaults requiretty/g' /etc/sudoers"
aws.block_device_mapping = [{'DeviceName' => '/dev/xvda', 'Ebs.VolumeSize' => 20}]
override.ssh.username = project_build_user
override.ssh.private_key_path = ENV["AWS_SSH_KEY_PATH"]
override.ssh.pty = true
end
config.berkshelf.enabled = true
config.ssh.forward_agent = true
config.vm.synced_folder '.', '/vagrant', :id => 'vagrant-root', :nfs => use_nfs
config.vm.synced_folder host_project_path, guest_project_path, :nfs => use_nfs
config.vm.provision :chef_solo do |chef|
chef.synced_folder_type = "nfs" if use_nfs
chef.json = {
'omnibus' => {
'build_user' => project_build_user,
'build_dir' => guest_project_path,
'ruby_version' => '2.1.8',
'install_dir' => "/opt/#{project_name}"
}
}
chef.run_list = chef_run_list
end
config.vm.provision :shell, :privileged => true, :inline => <<-REMOVE_OMNIBUS
rpm -ev #{project_name} || true
rm -rf /opt/#{project_name} || true
REMOVE_OMNIBUS
config.vm.provision :shell, :privileged => false, :inline => <<-OMNIBUS_BUILD
export PATH="/opt/omnibus-toolchain/embedded/bin/:$PATH"
sudo mkdir -p /opt/#{project_name}
sudo chown #{project_build_user} /opt/#{project_name}
cd #{guest_project_path}
bundle install --path=/home/#{project_build_user}/.bundler
bundle exec omnibus build #{project_name}2
OMNIBUS_BUILD
end # config.vm.define.platform
end # Vagrant.configure