2
2
# vi: set ft=ruby :
3
3
4
4
# Load in custom vagrant settings
5
- if File . file? ( "vagrant.yml" )
6
- require 'yaml'
7
- custom_settings = YAML . load_file 'vagrant.yml'
8
- puts '== Using Custom Vagrant Settings =='
9
- end
5
+ require 'yaml'
6
+ custom_settings = File . file? ( 'vagrant.yml' ) ? YAML . load_file ( 'vagrant.yml' ) : { }
7
+
8
+ puts '== Using Custom Vagrant Settings =='
9
+ puts custom_settings . inspect
10
10
11
11
VAGRANTFILE_API_VERSION = "2"
12
12
13
13
$box = 'coderwall'
14
- # The box is 1GB. Prepare yourself.
15
- #$box_url = 'http://cdn.coderwall.com/vagrant/coderwall.box'
16
- $box_url = 'https://s3.amazonaws.com/coderwall-assets-0/vagrant/coderwall.box'
14
+ $box_url = 'https://s3.amazonaws.com/coderwall-assets-0/vagrant/coderwall.box' # The box is 1GB. Prepare your
17
15
$provision = 'vagrant/bootstrap.sh'
18
16
19
17
Vagrant . configure ( VAGRANTFILE_API_VERSION ) do |config |
18
+
20
19
config . vm . box = $box
21
20
config . vm . box_url = $box_url
22
21
config . vm . provision :shell do |s |
@@ -28,33 +27,21 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
28
27
29
28
config . vm . network :private_network , ip : '192.168.237.95' # 192.168.cdr.wl
30
29
31
- # Use custom settings unless they don't exist
32
- unless custom_settings . nil?
33
- config . vm . network :forwarded_port , guest : 3000 , host : custom_settings [ 'network' ] [ 'port_mappings' ] [ 'rails' ]
34
- config . vm . network :forwarded_port , guest : 5432 , host : custom_settings [ 'network' ] [ 'port_mappings' ] [ 'postgres' ]
35
- config . vm . network :forwarded_port , guest : 6379 , host : custom_settings [ 'network' ] [ 'port_mappings' ] [ 'redis' ]
36
- config . vm . network :forwarded_port , guest : 9200 , host : custom_settings [ 'network' ] [ 'port_mappings' ] [ 'elasticsearch' ]
37
- config . vm . network :forwarded_port , guest : 27017 , host : custom_settings [ 'network' ] [ 'port_mappings' ] [ 'mongodb' ]
38
- else
39
- # Rails
40
- config . vm . network :forwarded_port , guest : 3000 , host : 3000
41
- # Postgres
42
- config . vm . network :forwarded_port , guest : 5432 , host : 2200
43
- # Redis
44
- config . vm . network :forwarded_port , guest : 6379 , host : 2201
45
- # ElasticSearch
46
- config . vm . network :forwarded_port , guest : 9200 , host : 9200
47
- # MongoDB
48
- config . vm . network :forwarded_port , guest : 27017 , host : 27017
49
- end
30
+ set_port_mapping_for ( config , 'elasticsearch' , 9200 , custom_settings )
31
+ set_port_mapping_for ( config , 'mongodb' , 27017 , custom_settings )
32
+ set_port_mapping_for ( config , 'postgres' , 5432 , custom_settings )
33
+ set_port_mapping_for ( config , 'redis' , 6379 , custom_settings )
34
+ set_port_mapping_for ( config , 'rails' , 3000 , custom_settings , true )
50
35
51
- config . vm . synced_folder '.' , '/home/vagrant/web' , nfs : true
36
+ if sync_settings = custom_settings [ 'sync' ]
37
+ config . vm . synced_folder '.' , '/home/vagrant/web' , nfs : sync_settings [ 'use_nfs' ]
38
+ end
52
39
53
40
config . vm . provider :virtualbox do |vb |
54
41
# Use custom settings unless they don't exist
55
- unless custom_settings . nil?
56
- vb . customize [ 'modifyvm' , :id , '--cpus' , custom_settings [ 'virtualbox' ] [ 'cpus' ] ]
57
- vb . customize [ 'modifyvm' , :id , '--memory' , custom_settings [ 'virtualbox' ] [ 'memory' ] ]
42
+ if virtualbox_settings = custom_settings [ 'virtualbox' ]
43
+ vb . customize [ 'modifyvm' , :id , '--cpus' , virtualbox_settings [ 'cpus' ] ]
44
+ vb . customize [ 'modifyvm' , :id , '--memory' , virtualbox_settings [ 'memory' ] ]
58
45
else
59
46
vb . customize [ 'modifyvm' , :id , '--cpus' , '4' ]
60
47
vb . customize [ 'modifyvm' , :id , '--memory' , '4096' ]
@@ -69,6 +56,26 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
69
56
# seems to be safe to run: https://github.com/griff/docker/commit/e5239b98598ece4287c1088e95a2eaed585d2da4
70
57
end
71
58
72
- config . vbguest . auto_update = true
73
- config . vbguest . no_remote = false
59
+ if Vagrant . has_plugin? ( 'vagrant-vbguest' )
60
+ config . vbguest . auto_update = true
61
+ config . vbguest . no_remote = false
62
+ else
63
+ puts "Please install the 'vagrant-vbguest' plugin"
64
+ end
65
+
66
+ end
67
+
68
+ def set_port_mapping_for ( config , service , guest_port , settings , force = false )
69
+ if settings [ 'network' ] && settings [ 'network' ] [ 'port_mappings' ] && settings [ 'network' ] [ 'port_mappings' ] [ service ]
70
+ host_port = settings [ 'network' ] [ 'port_mappings' ] [ service ]
71
+ puts " !! Setting up port mapping rule for #{ service } host:#{ host_port } => guest:#{ guest_port } "
72
+ config . vm . network ( :forwarded_port , guest : guest_port , host : host_port )
73
+ else
74
+ # no host port mapping was defined
75
+ if force
76
+ # but we want to force a mapping for the default ports
77
+ puts " !! Setting up port mapping rule for #{ service } host:#{ guest_port } => guest:#{ guest_port } "
78
+ config . vm . network ( :forwarded_port , guest : guest_port , host : guest_port )
79
+ end
80
+ end
74
81
end
0 commit comments