Skip to content

Instantly share code, notes, and snippets.

@lucadegasperi
Created September 28, 2014 20:10
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lucadegasperi/e4e3e200c70bcbc1bff3 to your computer and use it in GitHub Desktop.
Save lucadegasperi/e4e3e200c70bcbc1bff3 to your computer and use it in GitHub Desktop.
Homestead Plus
class Homestead
def Homestead.configure(config, settings, hostsupdater)
# Configure The Box
config.vm.box = "laravel/homestead"
config.vm.hostname = "homestead"
# Configure A Private Network IP
config.vm.network :private_network, ip: settings["ip"] ||= "192.168.10.10"
# Configure A Few VirtualBox Settings
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", settings["memory"] ||= "2048"]
vb.customize ["modifyvm", :id, "--cpus", settings["cpus"] ||= "1"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
# Configure Port Forwarding To The Box
# config.vm.network "forwarded_port", guest: 80, host: 8000
config.vm.network "forwarded_port", guest: 3306, host: 33060
config.vm.network "forwarded_port", guest: 5432, host: 54320
# Configure The Public Key For SSH Access
config.vm.provision "shell" do |s|
s.inline = "echo $1 | tee -a /home/vagrant/.ssh/authorized_keys"
s.args = [File.read(File.expand_path(settings["authorize"]))]
end
# Copy The SSH Private Keys To The Box
settings["keys"].each do |key|
config.vm.provision "shell" do |s|
s.privileged = false
s.inline = "echo \"$1\" > /home/vagrant/.ssh/$2 && chmod 600 /home/vagrant/.ssh/$2"
s.args = [File.read(File.expand_path(key)), key.split('/').last]
end
end
# Copy The Bash Aliases
config.vm.provision "shell" do |s|
s.inline = "cp /vagrant/aliases /home/vagrant/.bash_aliases"
end
# Register All Of The Configured Shared Folders
settings["folders"].each do |folder|
config.vm.synced_folder folder["map"], folder["to"], type: folder["type"] ||= nil
end
# Install All The Configured Nginx Sites
settings["sites"].each do |site|
config.vm.provision "shell" do |s|
s.inline = "bash /vagrant/scripts/serve.sh $1 $2"
s.args = [site["map"], site["to"]]
end
end
# Add the aliases to the host machine
if hostsupdater
aliases = Array.new
settings["sites"].each do |site|
aliases.push(site["map"])
end
config.hostsupdater.aliases = aliases
end
# Configure All Of The Server Environment Variables
if settings.has_key?("variables")
settings["variables"].each do |var|
config.vm.provision "shell" do |s|
s.inline = "echo \"\nenv[$1] = '$2'\" >> /etc/php5/fpm/php-fpm.conf && service php5-fpm restart"
s.args = [var["key"], var["value"]]
end
end
end
end
end
VAGRANTFILE_API_VERSION = "2"
path = "#{File.dirname(__FILE__)}"
require 'yaml'
require path + '/scripts/homestead.rb'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
Homestead.configure(config, YAML::load(File.read(path + '/Homestead.yaml')), Vagrant.has_plugin?('vagrant-hostsupdater'))
end
@SeanWhelan
Copy link

Nice, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment