Created
October 6, 2017 21:30
-
-
Save zachflower/2cb32fc910d0566bea3b400a5bc8b9cc to your computer and use it in GitHub Desktop.
Standard Vagrantfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# @Author: Dev_NIX | |
require 'getoptlong' | |
def check_plugins(dependencies) | |
if ['up', 'reload'].include?(ARGV[0]) | |
installed_dependencies = [] | |
puts "\033[1m" << "Checking dependencies..." << "\e[0m" | |
raw_output = `vagrant plugin list` | |
raw_list = raw_output.split("\n") | |
raw_list.each do |plugin| | |
if plugin.index("\e[0m") != nil | |
first = plugin.index("\e[0m") + 4 | |
else | |
first = 0 | |
end | |
installed_dependencies.push plugin.slice((first)..(plugin.index("(")-1)).strip | |
end | |
dependencies_already_satisfied = true | |
dependencies.each_with_index do |dependency, index| | |
if not installed_dependencies.include? dependency | |
dependencies_already_satisfied = false | |
puts "\033[33m" << " - Missing '#{dependency}'!" << "\e[0m" | |
if not system "vagrant plugin install #{dependency}" | |
puts "\n\033[33m" << " - Could not install plugin '#{dependency}'. " << "\e[0m\033[41m" << "Stopped." << "\e[0m" | |
exit(-1) | |
end | |
end | |
end | |
if dependencies_already_satisfied | |
puts "\033[1m\033[36m" << " - All dependencies already satisfied" << "\e[0m" | |
else | |
puts "\033[1m\033[32m" << " - Dependencies installed" << "\e[0m" | |
exec "vagrant " << "--skip-dependency-manager " << ARGV.join(" ") | |
exit | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
# bring in the vagrant dependency manager | |
require File.dirname(__FILE__) + "/dependency_manager" | |
# make sure the following plugins are installed (managed using dependency manager above) | |
check_plugins ["vagrant-exec", "vagrant-hostmanager", "vagrant-triggers"] | |
Vagrant.configure(2) do |config| | |
# use scotchbox as base box | |
config.vm.box = "scotch/box" | |
config.vm.box_version = "2.5" | |
# set ip address to 192.168.33.10 | |
# | |
# NOTE: this makes it easy to access the VM without having to know the auto-selected SSH port | |
config.vm.network "private_network", ip: "192.168.33.10", hostsupdater: "skip" | |
# set project folder to /var/www | |
config.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777", "fmode=777"] | |
# set hostname to vagrant.dev | |
# | |
# NOTE: this is automatically added to the hosts file using vagrant-hostmanager, which | |
# will prompt for admin or root permissions | |
config.vm.hostname = "vagrant.dev" | |
# setup hostmanager | |
config.hostmanager.enabled = true | |
config.hostmanager.manage_host = true | |
config.hostmanager.manage_guest = true | |
config.hostmanager.ignore_private_ip = false | |
config.hostmanager.include_offline = true | |
# make /var/www the working directory for all commands | |
# | |
# NOTE: this allows us to run one-line commands directly within the project directory | |
# of the VM, such as `vagrant exec make` | |
config.exec.commands '*', directory: '/var/www' | |
# provisioners go here (puppet, chef, shell, etc) | |
config.vm.provision "shell", path: "path/to/provisioner.sh" | |
# run the following commands after every vagrant up, reload, and provision | |
# | |
# NOTE: use this when dealing with commands that aren't appropriate for the provisioner, | |
# such as running migrations or installing project dependencies (via npm, composer, etc) | |
config.trigger.after [:up, :reload, :provision] do | |
info "Migrating database..." | |
run "vagrant ssh -c \"cd /var/www ; migrate\"" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment