-
Notifications
You must be signed in to change notification settings - Fork 847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Splitting VVV code in Vagrantfile into classes #2641
Closed
aldavigdis
wants to merge
3
commits into
Varying-Vagrant-Vagrants:develop
from
aldavigdis:revamp_vagrantfile_squashed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
AllCops: | ||
NewCops: enable | ||
Exclude: | ||
- 'Vagrantfile' | ||
|
||
Layout/LineLength: | ||
Max: 80 | ||
|
||
Metrics/ClassLength: | ||
Max: 128 | ||
CountComments: false | ||
|
||
Metrics/MethodLength: | ||
Max: 20 | ||
CountComments: false | ||
|
||
Metrics/AbcSize: | ||
Enabled: false | ||
|
||
Style/Documentation: | ||
Exclude: | ||
- '.vvv/lib/config.rb' | ||
- '.vvv/lib/info.rb' | ||
- '.vvv/lib/migrate.rb' | ||
- '.vvv/lib/splash_screens.rb' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2.7.6 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
┌-──────────────────────────────────────────────────────────────────────────────┐ | ||
│ │ | ||
│ ⚠ DANGER DO NOT USE SUDO ⚠ │ | ||
│ │ | ||
│ ! ▄▀▀▀▄▄▄▄▄▄▄▀▀▀▄ ! You should never use sudo or root with vagrant. │ | ||
│ !█▒▒░░░░░░░░░▒▒█ It causes lots of problems :( │ | ||
│ █░░█░▄▄░░█░░█ ! │ | ||
│ █░░█░░█░▄▄█ ! We're really sorry but you may need to do painful │ | ||
│ ! ▀▄░█░░██░░█ cleanup commands to fix this. │ | ||
│ │ | ||
│ If vagrant does not work for you without sudo, open a GitHub issue instead │ | ||
│ In the future, this warning will halt provisioning to prevent new users │ | ||
│ making this mistake. │ | ||
│ │ | ||
│ ⚠ DANGER SUDO DETECTED! │ | ||
│ │ | ||
│ In the future the VVV team will be making it harder to use VVV with sudo. │ | ||
│ We will require a config option so that users can do data recovery, and │ | ||
│ disable sites and the dashboard. │ | ||
│ │ | ||
│ DO NOT USE SUDO, use ctrl+c/cmd+c and cancel this command ASAP!!! │ | ||
│ │ | ||
└───────────────────────────────────────────────────────────────────────────────┘ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
module VVV | ||
# The Bootstrap class | ||
# | ||
# Used for determining which and if logos and other messages should be | ||
# displayed before the `Vagrant.configure` block in the `Vagrantfile`. | ||
class Bootstrap | ||
# Determine if the VVV logo and platform splash should be displayed | ||
def self.show_logo? | ||
return false if ENV['VVV_SKIP_LOGO'] | ||
|
||
return true if %w[up resume status provision reload].include? ARGV[0] | ||
|
||
false | ||
end | ||
|
||
# Determine if the sudo warning should be displayed | ||
def self.show_sudo_bear? | ||
return true if !Vagrant::Util::Platform.windows? && Process.uid.zero? | ||
|
||
false | ||
end | ||
|
||
def self.box_overridden?(config) | ||
config['vm_config'].key?('box') | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
# frozen_string_literal: true | ||
|
||
module VVV | ||
class Config | ||
GITHUB_USER_URL = 'https://github.com/Varying-Vagrant-Vagrants/' | ||
UTILITIES_REPO_URL = "#{GITHUB_USER_URL}vvv-utilities.git" | ||
DASHBOARD_REPO_URL = "#{GITHUB_USER_URL}dashboard.git" | ||
PRIVATE_NETWORK_IP = '192.168.56.4' | ||
|
||
CONFIG_FILE = File.join(VVV::Info.vagrant_dir, 'config/config.yml').freeze | ||
|
||
require 'yaml' | ||
|
||
def initialize | ||
@config = YAML.load_file(CONFIG_FILE) | ||
lint | ||
end | ||
|
||
def values | ||
@config | ||
end | ||
|
||
def lint | ||
# If 'hosts' isn't an array, redefine it as such | ||
@config['hosts'] = ['vvv.test'] unless @config['hosts'].is_a? Array | ||
|
||
@config['sites'].each do |site, args| | ||
# If the site's value is a string, treat it as the repo value | ||
if @config['sites'][site].is_a? String | ||
@config['sites'][site] = { repo: args } | ||
end | ||
|
||
# If the site's args aren't defined as a Hash already, | ||
# redefine it as such. | ||
@config['sites'][site] = {} unless @config['sites'][site].is_a? Hash | ||
|
||
merge_site_defaults(site) | ||
process_hosts_for_site(site) | ||
end | ||
process_dashboard | ||
process_utilities | ||
process_utility_sources | ||
process_extensions | ||
process_extension_sources | ||
process_vm_config | ||
process_general | ||
process_vagrant_plugins | ||
set_vagrant_default_provider_env_variable | ||
end | ||
|
||
private | ||
|
||
def set_vagrant_default_provider_env_variable | ||
return unless @config['vm_config']['provider'] | ||
|
||
ENV['VAGRANT_DEFAULT_PROVIDER'] = @config['vm_config']['provider'] | ||
end | ||
|
||
def process_vagrant_plugins | ||
@config['vagrant-plugins'] = {} unless @config['vagrant-plugins'] | ||
end | ||
|
||
def process_utilities | ||
@config['utilities'] = {} unless @config['utilities'].is_a? Hash | ||
end | ||
|
||
def process_utility_sources | ||
return if @config['utility-sources'].is_a? Hash | ||
|
||
@config['utility-sources'] = {} | ||
end | ||
|
||
def process_extensions | ||
@config['extensions'] = {} unless @config['extensions'].is_a? Hash | ||
end | ||
|
||
def process_extension_sources | ||
if @config['extension-sources'].is_a? Hash | ||
@config['extension-sources'].each do |name, args| | ||
next unless args.is_a? String | ||
|
||
@config['extension-sources'][name] = { 'repo' => args, | ||
'branch' => 'master' } | ||
end | ||
unless @config['extension-sources'].key?('core') | ||
@config['extension-sources']['core'] = { 'repo' => UTILITIES_REPO_URL, | ||
'branch' => 'master' } | ||
end | ||
else | ||
@config['extension-sources'] = {} | ||
end | ||
end | ||
|
||
def process_vm_config | ||
@config['vm_config'] = {} unless @config['vm_config'].is_a? Hash | ||
merge_vm_config_defaults | ||
end | ||
|
||
def merge_vm_config_defaults | ||
defaults = { 'memory' => 2048, 'cores' => 1, 'provider' => 'virtualbox', | ||
'private_network_ip' => PRIVATE_NETWORK_IP } | ||
defaults['provider'] = 'parallels' if Etc.uname[:version].include? 'ARM64' | ||
@config['vm_config'] = defaults.merge(@config['vm_config']) | ||
end | ||
|
||
def process_general | ||
@config['general'] = {} unless @config['general'].is_a? Hash | ||
end | ||
|
||
def process_dashboard | ||
@config['dashboard'] = {} unless @config['dashboard'].is_a? Hash | ||
merge_dashboard_defaults | ||
end | ||
|
||
def merge_dashboard_defaults | ||
defaults = { 'repo' => DASHBOARD_REPO_URL, 'branch' => 'master' } | ||
@config['dashboard'] = defaults.merge(@config['dashboard']) | ||
end | ||
|
||
def process_hosts_for_site(site) | ||
unless @config['sites'][site]['skip_provisioning'] | ||
# Find vvv-hosts files and add their lines to the @config hash | ||
site_host_paths = Dir.glob( | ||
"#{@config['sites'][site]['local_dir']}/*/vvv-hosts" | ||
) | ||
site_host_paths.each do |path| | ||
lines = File.readlines(path).map(&:chomp).grep(/\A[^#]/) | ||
lines.each do |l| | ||
@config['sites'][site]['hosts'] << l | ||
end | ||
end | ||
|
||
# Add the site's hosts to the 'global' hosts array | ||
@config['hosts'] += if @config['sites'][site]['hosts'].is_a? Array | ||
@config['sites'][site]['hosts'] | ||
else | ||
["#{site}.test"] | ||
end | ||
@config['sites'][site].delete('hosts') | ||
end | ||
@config['hosts'] = @config['hosts'].uniq | ||
end | ||
|
||
def merge_site_defaults(site) | ||
# Merge the defaults with the currently defined site args | ||
@config['sites'][site] = site_defaults(site).merge(@config['sites'][site]) | ||
end | ||
|
||
def site_defaults(site) | ||
{ 'repo' => false, | ||
'vm_dir' => "/srv/www/#{site}", | ||
'local_dir' => File.join(VVV::Info.vagrant_dir, 'www', site), | ||
'branch' => 'master', | ||
'skip_provisioning' => false, | ||
'allow_customfile' => false, | ||
'nginx_upstream' => 'php', | ||
'hosts' => [] } | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are the wrong way around
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
though it is just linting so this isn't as important as it looked when I read it