Skip to content

Commit

Permalink
Merge pull request #262 from lemberg/task/236-configurable-plugins
Browse files Browse the repository at this point in the history
Make Vagrant plugins configurable
  • Loading branch information
T2L committed Jul 7, 2022
2 parents 717d004 + d39f99c commit 3972c07
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ This is Vagrant-based development environment for Drupal projects. This project

Manages host and/or guest `hosts` files. Draft is configured to create a `hostname.test` DNS record on a host machine.

#### [vagrant-vbguest](https://github.com/dotless-de/vagrant-vbguest)

Automatically installs the host's VirtualBox Guest Additions on the guest system.

#### [vagrant-disksize](https://github.com/sprotheroe/vagrant-disksize)

A Vagrant plugin to resize disks in VirtualBox.
Expand Down
48 changes: 22 additions & 26 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,6 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# Before we start: auto-install recommended plugins. Code borrowed here:
# https://github.com/hashicorp/vagrant/issues/8055#issuecomment-403171757
# Installs:
# - vagrant-hostmanager - https://github.com/devopsgroup-io/vagrant-hostmanager
# - vagrant-vbguest - https://github.com/dotless-de/vagrant-vbguest
# - vagrant-disksize - https://github.com/sprotheroe/vagrant-disksize
required_plugins = %w(vagrant-hostmanager vagrant-vbguest vagrant-disksize)

# Additionally install Vagrant WinNFSd on Windows hosts.
require "rbconfig"
if (RbConfig::CONFIG["host_os"] =~ /cygwin|mswin|mingw|bccwin|wince|emx/)
required_plugins.push('vagrant-winnfsd')
end

return if !Vagrant.plugins_enabled?

plugins_to_install = required_plugins.select { |plugin| !Vagrant.has_plugin? plugin }
unless plugins_to_install.empty?
puts "Installing plugins: #{plugins_to_install.join(' ')}"
if system "vagrant plugin install #{plugins_to_install.join(' ')}"
exit system "vagrant #{ARGV.join(' ')}"
else
abort "Installation of one or more plugins has failed. Aborting."
end
end

# Some features used in this configuration file require specific version of
# Vagrant.
Vagrant.require_version ">= 2.2.6"
Expand Down Expand Up @@ -58,6 +32,28 @@ require "#{VM_BASE_PATH}/provisioning/src/configuration"
# new values will be added to the resulting settings hash.
configuration = Configuration.new(PROJECT_BASE_PATH, DRAFT_BASE_PATH)

# Before we start: auto-install recommended plugins. Code borrowed here:
# https://github.com/hashicorp/vagrant/issues/8055#issuecomment-403171757
required_plugins = configuration.get("vagrant.plugins")

# Remove Vagrant WinNFSd on non-Windows hosts.
require "rbconfig"
if (RbConfig::CONFIG["host_os"] !~ /cygwin|mswin|mingw|bccwin|wince|emx/)
required_plugins.delete_if { |name| name == 'vagrant-winnfsd' }
end

return if !Vagrant.plugins_enabled?

plugins_to_install = required_plugins.select { |plugin| !Vagrant.has_plugin? plugin }
unless plugins_to_install.empty?
puts "Installing plugins: #{plugins_to_install.join(' ')}"
if system "vagrant plugin install #{plugins_to_install.join(' ')}"
exit system "vagrant #{ARGV.join(' ')}"
else
abort "Installation of one or more plugins has failed. Aborting."
end
end

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

# Boxes
Expand Down
8 changes: 8 additions & 0 deletions default.vm-settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ draft:

# Vagrant configuration.
vagrant:
# Before we start: auto-install recommended plugins. Code borrowed here:
# https://github.com/hashicorp/vagrant/issues/8055#issuecomment-403171757
plugins:
- vagrant-hostmanager
- vagrant-disksize
# On Windows hosts additionally install Vagrant WinNFSd. This plugin won't
# be installed on non-Windows hosts.
- vagrant-winnfsd
# Box to use. At the moment Debian-based distributions are supported only.
# Do not change this value, unless absolutely necessary. Valid use case is
# 32-bit host machine and no support for virtualization of 64-bit guest
Expand Down

0 comments on commit 3972c07

Please sign in to comment.