Skip to content
This repository has been archived by the owner on Aug 20, 2019. It is now read-only.

Move Vagrantfile into the box #74

Closed
thom8 opened this issue Jan 26, 2016 · 5 comments
Closed

Move Vagrantfile into the box #74

thom8 opened this issue Jan 26, 2016 · 5 comments
Milestone

Comments

@thom8
Copy link
Member

thom8 commented Jan 26, 2016

Rather than requiring a custom Vagrantfile it would be nice if this was moved into the box so a new project can be initialised by just vagrant init DrupalMel/beetbox; vagrant up

@thom8
Copy link
Member Author

thom8 commented Jan 26, 2016

The biggest issue I see with this is being able to reference the project root dir from the box Vagrantfile.

I often use vagrant ID to reference VM's see vagrant global-status. eg vagrant destroy [ID]

This could be run inside another project so traversing the current location to find the closest Vagrantfile won't work.

@Decipher
Copy link
Contributor

So the approach I plan to work on will be as such:

  • If the command was invoked with an ID
    • Determine the ID by iterating over ARGV and extracting the most logical value
    • Run vagrant global-status into a ruby variable
    • Use regex to extract the working directory
  • Else
    • Iterate over the current directories until the Vagrantfile is found

The second part is already written, but will likely need some modifications: https://github.com/Realityloop/packer-templates/blob/realityloop/ubuntu-12.04-x86_64/example/Vagrantfile#L7

I have a proof of concept for the first that, that if you put it in your Box Vagrantfile and run vagrant status [ID] you will get a result (but it will also break your box, so remove it after testing it):

output = `vagrant global-status`
puts /#{ARGV[1]}.*?(\/.*?)\n/.match(output)[1]
exit

@Decipher
Copy link
Contributor

Updated PoC:

# Find the Vagrant ID if supplied.
id = nil
ARGV.each do |arg|
  id = arg[/\h{7}/] ? arg : id
end

# Determine the current working directory.
cwd = nil
if id != nil
  cwd = /#{id}.*?(\/.*?)\n/.match(`vagrant global-status`)[1]
else
  paths = Dir.pwd.split('/')
  while cwd == nil
    dir = paths.join('/')
    current = paths.pop
    if File.exists?("#{dir}/VagrantFile")
      cwd = dir
    end
  end
end
puts cwd
exit

That works in the project dir, a sub-dir and from anywhere via use of the ID

@Decipher
Copy link
Contributor

Work implemented at: #80

@Decipher Decipher modified the milestone: 0.2.0 Jan 29, 2016
Decipher added a commit that referenced this issue Jan 31, 2016
#74: Supply a default Vagrantfile with the box.
@Decipher
Copy link
Contributor

Done.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants