Skip to content

Instantly share code, notes, and snippets.

@huglester
Last active August 29, 2015 14:07
Show Gist options
  • Save huglester/9e297cbb98e9404910af to your computer and use it in GitHub Desktop.
Save huglester/9e297cbb98e9404910af to your computer and use it in GitHub Desktop.
Homestead config
class Homestead
def Homestead.configure(config, settings)
# 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"] ||= "4096"]
vb.customize ["modifyvm", :id, "--cpus", settings["cpus"] ||= "2"]
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: 80
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
config.vm.provider "virtualbox" do |vb|
vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate" + folder["to"], "1"]
end
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
# 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
# Run Any Optional Commands
if settings.has_key?("commands")
settings["commands"].each do |command|
config.vm.provision "shell" do |s|
s.inline = command
end
end
end
# Configure Git User
if settings.has_key?("git")
settings["git"].each do |g|
config.vm.provision "shell" do |s|
s.privileged = false
s.inline = "git config --global user.name \"$1\" && git config --global user.email \"$2\""
s.args = [g["name"], g["email"]]
end
end
end
end
end
---
ip: "192.168.10.10"
memory: 2048
cpus: 2
authorize: D:/ssh_keys/id_rsa.pub
keys:
- D:/ssh_keys/id_rsa
folders:
- map: D:/_homestead/emtctools.app
to: /home/vagrant/emtctools.app
sites:
- map: emtctools.app
to: /home/vagrant/emtctools.app/public
variables:
- key: APP_ENV
value: local
commands:
- sudo /etc/init.d/memcached restart
- sudo composer selfupdate
- sudo apt-get update
- sudo apt-get install -y php5-xsl mc
git:
- name: User
email: [email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment