Permalink
Browse files

Allow components to specify ports to forward in Vagrantfile

  • Loading branch information...
1 parent 9858767 commit bbc7b3819801455973976e225bec0e84b1db36ed Gabriel Evans committed Jan 16, 2012
Showing with 24 additions and 6 deletions.
  1. +2 −0 components/nginx_component.rb
  2. +6 −0 lib/rails-up.rb
  3. +5 −0 lib/rails-up/component.rb
  4. +4 −0 lib/rails-up/component_builder.rb
  5. +7 −6 templates/Vagrantfile.tt
@@ -10,6 +10,8 @@
cookbook "nginx", "0.99.2"
+ forward_port "nginx", 80 => 8080
+
role "nginx" do
run_list "recipe[nginx::source]"
View
@@ -99,10 +99,16 @@ def components_listing
end
def vagrantfile_options(components, box_name, box_url)
+ forward_ports = {}
+ components.each do |c|
+ forward_ports.merge!(c.forward_ports)
+ end
+
{
:cookbooks_path => RailsUp.cookbooks_path,
:roles_path => RailsUp.roles_path,
:components => components,
+ :forward_ports => forward_ports,
:box_name => box_name,
:box_url => box_url
}
@@ -3,6 +3,7 @@ class Component
attr_accessor :name,
:version,
:summary,
+ :forward_ports,
:roles,
:cookbooks,
:definition_file,
@@ -17,6 +18,10 @@ def inspect
inspect1
end
+ def forward_ports
+ @forward_ports ||= {}
+ end
+
def roles
@roles ||= []
end
@@ -24,6 +24,10 @@ def summary(value)
@definition.summary = value
end
+ def forward_port(name, ports={})
+ @definition.forward_ports[name] = ports.flatten
+ end
+
def roles(*value)
@definition.roles = value
end
@@ -4,7 +4,7 @@ Vagrant::Config.run do |config|
# please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of.
- config.vm.box = "<%= config[:box_name] || "base" %>"
+ config.vm.box = "<%= config[:box_name] %>"
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
@@ -19,12 +19,13 @@ Vagrant::Config.run do |config|
# Forward a port from the guest to the host, which allows for outside
# computers to access the VM, whereas host only networking does not.
- # config.vm.forward_port "http", 80, 8080
<% if config[:forward_ports]
- config[:forward_ports].each do |p| -%>
- config.vm.forward_port "<%= p[:name] %>", <%= p[:guest] %>, <%= p[:host] %>
-<% end
-end -%>
+ config[:forward_ports].each do |service, ports| -%>
+ config.vm.forward_port "<%= service %>", <%= ports[0] %>, <%= ports[1] %>
+<% end -%>
+<% else -%>
+ # config.vm.forward_port "http", 80, 8080
+<% end -%>
# Share an additional folder to the guest VM. The first argument is
# an identifier, the second is the path on the guest to mount the

0 comments on commit bbc7b38

Please sign in to comment.