julien-duponchelle / docker-osx

Fast and easy installation of Docker on OS X
1.03k stars 70 forks source link

extra config injected from ~/.docker-osx/Vagrantfile.extra_config #21

Closed GermanDZ closed 10 years ago

GermanDZ commented 10 years ago

Adding a file name Vagrantfile_extra.rb into the ~/.docker-osx directory will allow to keep some additional config for Vagrant without messing up too much the installation.

I used it for port forwarding some extra ports.

My Vagrantfile_extra.rb looks like:

config.vm.network :forwarded_port, guest: 3000, host: 3000
config.vm.network :forwarded_port, guest: 8080, host: 8080

This dirty patch doesn't want to be a final solution, just an idea to open the discussion about extend and customisation methods.

zaim commented 10 years ago

I was just about to work on something like this. My solution was, instead of concatenating the extra config on install, have the Vagrantfile require an extra ruby module. Something like:

Vagrant.configure("2") do |config|
  # ...
end

vagrantfile_extra = "#{ENV['VAGRANT_CWD']}/Vagrantfile_extra.rb"

if File.exists?(vagrantfile_extra) then
  require vagrantfile_extra
end

The Vagrantfile_extra.rb file needs to be a valid Vagrantfile with a Vagrant.configure block.

GermanDZ commented 10 years ago

Sounds pretty good, I am not a Vagrant expert. Is the order of config sentences important? we could need something like "pre-config", "config" and "post-config"?

Swatto commented 10 years ago

We could add a second extra configuration file for easy port forwarding: a YAML file. We could use the same rules as @zaim propose for checking if the file exist and use it only if it's present.

The structure could be somethings like:

ports:
  railsApp1:
    guest: 3000
    host: 3000
  railsApp2:
    guest: 5000
    host: 8080

The yaml module in ruby could use it and makes an easy configuration for a dev environnement.

bfirsh commented 10 years ago

I prefer @zaim's solution, then we don't necessarily have to generate Vagrantfile on every run.

bfirsh commented 10 years ago

Squashed and merged in 392e5e56df492d4c662ba2155859b43cb67453e1 . Thanks!