Created
March 27, 2015 08:48
-
-
Save aslakhellesoy/5c6b98d10214c90f31a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script sets up (or removes) port forwarding on VirtualBox | |
# for all ports defined in fig.yml | |
require 'yaml' | |
op = ARGV[0] | |
if op.nil? || !( /(up|down)/ =~ op ) | |
$stderr.puts "Usage:\n ruby #{__FILE__} up|down" | |
exit 1 | |
end | |
system('boot2docker stop') | |
fig = YAML.load_file('fig.yml') | |
fig.each do |container, config| | |
config['ports'].each do |mapping| | |
host_port, container_port = *mapping.split(':') | |
mapping_name = "tcp-port-#{container}-#{host_port}" | |
if op == 'up' | |
puts "Forwarding #{mapping_name} to #{container_port}" | |
system %Q{VBoxManage modifyvm "boot2docker-vm" --natpf1 "#{mapping_name},tcp,,#{host_port},,#{host_port}"} | |
else | |
puts "Unforwarding #{mapping_name} to #{container_port}" | |
system %Q{VBoxManage modifyvm "boot2docker-vm" --natpf1 delete "#{mapping_name}"} | |
end | |
end | |
end | |
system('boot2docker start') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment