Skip to content

Commit

Permalink
Allow VM networks to be configured
Browse files Browse the repository at this point in the history
  • Loading branch information
damianlewis committed Aug 14, 2018
1 parent 0881d75 commit d284e4c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 16 deletions.
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,41 @@ DevBox can be configured using the `config.yaml` configuration file.


#### VM
By default, DevBox will create a private network with an automatically assigned IP address. Use `ifconfig` on the VM to determine the IP address. A static IP address for the VM can be given by adding the `ip` property and assigning an address from the [reserved private address space](https://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces). Also the default name for the VM is 'devbox', this can be changed by adding the `name` property. The default hostname for the VM is also 'devbox', this can be changed by adding the `hostname` property.
By default, the name for the VM is 'devbox', this can be changed by adding the `name` property. The default hostname for the VM is also 'devbox', this can be changed by adding the `hostname` property.
```yaml
ip: "192.168.22.18"
name: vmname
hostname: vmhostname
```
#### Network
By default, DevBox will create a private network with an automatically assigned IP address. Use `ifconfig` on the VM to determine the IP address. To create a bridged (public) network, add a `networks` array with a `type` property of `bridged`.
```yaml
networks:
- type: bridged
```

A static IP address for the VM can also be given by adding an `ip` property and assigning an address from the [reserved private address space](https://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces).
```yaml
networks:
- type: private
ip: "192.168.178.40"
```

```yaml
networks:
- type: bridged
ip: "192.168.178.40"
```

By default, DevBox will forward ports 80 and 3306 on the guest machine to ports 8000 and 33060 on the host. To forward additional ports, add a `ports` array with `guest` and `host` properties set to the ports you want to forward.
```yaml
ports:
- guest: 443
host: 44300
```


#### Folders
By default, DevBox will share your project folder `.` with the `/vagrant` folder on the guest machine. To share additional folders with the guest machine `map` the host folder `to` the guest folder in the `folders` array.
```yaml
Expand Down
42 changes: 29 additions & 13 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ name = settings["name"] ||= "devbox"
# Default ports for forwarding
default_ports = {
80 => 8000,
443 => 44300,
3306 => 33060
}

Expand Down Expand Up @@ -70,19 +69,41 @@ Vagrant.configure("2") do |config|
config.vm.box = settings["box"] ||= "damianlewis/ubuntu-#{settings["ubuntu"] ||= default_ubuntu}-#{webserver == "apache" ? "lamp" : "lemp"}"
config.vm.box_version = settings["version"] ||= ">= 1.0"

# Configure default ports
default_ports.each do |guest, host|
config.vm.network "forwarded_port", guest: guest, host: host, auto_correct: true
end

# Configure additional ports to forward
if settings.has_key?("ports")
settings["ports"].each do |port|
config.vm.network "forwarded_port", guest: port["guest"], host: port["host"], auto_correct: true
end
end

# Configure networks
if settings.has_key?("networks")
settings["networks"].each do |network|
if network.has_key?("ip")
config.vm.network network["type"], ip: network["ip"], bridge: network["bridge"] ||= nil
else
config.vm.network network["type"], bridge: network["bridge"] ||= nil
if network.has_key?("type")
if network["type"] == "private"
if network.has_key?("ip")
config.vm.network "private_network", ip: network["ip"]
else
config.vm.network "private_network", type: "dhcp"
end
end

if network["type"] == "bridged"
if network.has_key?("ip")
config.vm.network "public_network", ip: network["ip"], bridge: network["bridge"] ||= nil
else
config.vm.network "public_network", bridge: network["bridge"] ||= nil
end
end
end
end
elsif settings.has_key?("ip")
config.vm.network :private_network, ip: settings["ip"]
else
config.vm.network :private_network, type: "dhcp"
config.vm.network "private_network", type: "dhcp"
end

# Configure VirtualBox settings
Expand All @@ -98,11 +119,6 @@ Vagrant.configure("2") do |config|
end
end

# Configure default ports
default_ports.each do |guest, host|
config.vm.network "forwarded_port", guest: guest, host: host, auto_correct: true
end

# Configure shared folders
if settings.has_key?("folders")
settings["folders"].each do |folder|
Expand Down
11 changes: 10 additions & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
---
# VM configurations
ip: "192.168.10.10"
#ubuntu: "14.04"

# Networks to configure
#networks:
# - type: bridged
# ip: "192.168.178.40"

# Additional ports to forward
#ports:
# - guest: 443
# host: 44300

# Shared folders to configure
#folders:
# - map: ~/code
Expand Down

0 comments on commit d284e4c

Please sign in to comment.