vagrant-hypconfigmgmt 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f1ca6d12b79bff6c9cc89da885833eb16a0a2d3b
4
+ data.tar.gz: 4663a9bd184d529a84ec76a4d0afcf42f975c900
5
+ SHA512:
6
+ metadata.gz: 3832d2fa53fac113c4ae7a41f5eae81d127ddd4b6bde96bc16a6723c03cf3c7dd7dda702fb130ab0ec531b034e8571355decd7c712c16f923051928a25ea5630
7
+ data.tar.gz: e653bc874f0a4ced2a4b5fa4718a3ce3552b2241a2baa78ca2616db35d6d9ad5422d149dbdf4724b6c81b0ab4497db5b2a84aca62362501899671db092696566
data/.gitignore ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vagrant-hypconfigmgmt.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Rick van de Loo
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Makefile ADDED
@@ -0,0 +1,14 @@
1
+ .PHONY: all clean
2
+
3
+ NAME := vagrant-hypconfigmgmt
4
+ VERSION := 0.1
5
+ MAINTAINER := Rick van de Loo <rick@byte.nl>
6
+ DESCRIPTION := Prompt to configure a hypernode-vagrant
7
+
8
+ all:
9
+ rake build
10
+ install:
11
+ find pkg/ | tail -n 1 | xargs vagrant plugin install
12
+ clean:
13
+ git clean -xfd
14
+
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+ Install the build deps
2
+ ======================
3
+
4
+ ```
5
+ sudo apt-get install bundler
6
+ sudo apt-get install rake
7
+ ```
8
+
9
+ Create the gemfile (package)
10
+ ============================
11
+
12
+ ```
13
+ $ make
14
+ rake build
15
+ vagrant-hypconfigmgmt 0.0.1 built to pkg/vagrant-hypconfigmgmt-0.0.1.gem.
16
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,235 @@
1
+ # coding: utf-8
2
+ # vim: set fileencoding=utf-8
3
+
4
+ DEFAULT_MAGENTO_VERSION = 2
5
+ AVAILABLE_MAGENTO_VERSIONS = [1, 2]
6
+
7
+ DEFAULT_PHP_VERSION = 7.0
8
+ AVAILABLE_PHP_VERSIONS = [5.5, 7.0]
9
+
10
+ DEFAULT_VARNISH_STATE = false
11
+ AVAILABLE_VARNISH_STATES = [true, false]
12
+
13
+ # paths to local settings file
14
+ H_V_SETTINGS_FILE = "local.yml"
15
+
16
+ RECOMMENDED_PLUGINS = ["vagrant-hostmanager", "vagrant-vbguest"]
17
+
18
+
19
+ def retrieve_settings()
20
+ return YAML.load_file(H_V_SETTINGS_FILE)
21
+ end
22
+
23
+
24
+ def update_settings(settings)
25
+ File.open(H_V_SETTINGS_FILE, 'w') {|f| f.write settings.to_yaml }
26
+ end
27
+
28
+
29
+ def use_default_if_input_empty(input, default)
30
+ if input == ''
31
+ return default.to_s
32
+ else
33
+ return input
34
+ end
35
+ end
36
+
37
+
38
+ def get_varnish_state(env)
39
+ input = env[:ui].ask("Do you want to enable Varnish? Enter true or false [default false]: ")
40
+ varnish_state = use_default_if_input_empty(input, DEFAULT_VARNISH_STATE)
41
+
42
+ case varnish_state
43
+ when "true"
44
+ env[:ui].info("Varnish will be enabled.")
45
+ when "false"
46
+ env[:ui].info("Varnish will be disabled by loading a nocache vcl.")
47
+ else
48
+ env[:ui].error("The value #{varnish_state} is not a valid value. Please enter true or false")
49
+ return get_varnish_state(env)
50
+ end
51
+ return varnish_state == "true" ? true : false
52
+ end
53
+
54
+
55
+ def get_magento_version(env)
56
+ available_versions = AVAILABLE_MAGENTO_VERSIONS.join(' or ')
57
+ input = env[:ui].ask("Is this a Magento #{available_versions} Hypernode? [default #{DEFAULT_MAGENTO_VERSION}]: ")
58
+ magento_version = use_default_if_input_empty(input, DEFAULT_MAGENTO_VERSION)
59
+
60
+ case magento_version
61
+ when "1"
62
+ env[:ui].info("Nginx will be configured for Magento 1. The webdir will be /data/web/public")
63
+ when "2"
64
+ env[:ui].info("Nginx will be configured for Magento 2. /data/web/magento2/pub will be symlinked to /data/web/public")
65
+ else
66
+ env[:ui].error("The value #{magento_version} is not a valid Magento version. Please enter #{available_versions}")
67
+ return get_magento_version(env)
68
+ end
69
+ return magento_version.to_i
70
+ end
71
+
72
+
73
+ # todo: refactor this and the above function into one
74
+ def get_php_version(env)
75
+ available_versions = AVAILABLE_PHP_VERSIONS.join(' or ')
76
+ input = env[:ui].ask("Is this a PHP #{available_versions} Hypernode? [default #{DEFAULT_PHP_VERSION}]: ")
77
+ php_version = use_default_if_input_empty(input, DEFAULT_PHP_VERSION)
78
+
79
+ case php_version
80
+ when "5.5"
81
+ env[:ui].info("Will boot a box with PHP 5.5 installed")
82
+ when "7.0"
83
+ env[:ui].info("Will boot a box with PHP 7.0 installed")
84
+ else
85
+ env[:ui].error("The value #{php_version} is not a valid PHP version. Please enter #{available_versions}")
86
+ return get_php_version(env)
87
+ end
88
+ return php_version.to_f
89
+ end
90
+
91
+
92
+ def ensure_varnish_state_configured(env)
93
+ settings = retrieve_settings()
94
+ if settings['varnish']['enabled'].nil?
95
+ settings['varnish']['enabled'] = get_varnish_state(env)
96
+ elsif ![true, false].include?(settings['varnish']['enabled'])
97
+ env[:ui].error("The Varnish state configured in local.yml is invalid.")
98
+ settings['varnish']['enabled'] = get_varnish_state(env)
99
+ end
100
+ update_settings(settings)
101
+ end
102
+
103
+
104
+ def ensure_magento_version_configured(env)
105
+ settings = retrieve_settings()
106
+ if settings['magento']['version'].nil?
107
+ settings['magento']['version'] = get_magento_version(env)
108
+ elsif !AVAILABLE_MAGENTO_VERSIONS.include?(settings['magento']['version'].to_i)
109
+ env[:ui].error("The Magento version configured in local.yml is invalid.")
110
+ settings['magento']['version'] = get_magento_version(env)
111
+ end
112
+ update_settings(settings)
113
+ end
114
+
115
+
116
+ # Make sure we don't link /data/web/public on Magento 2 Vagrants
117
+ # because that dir will be a symlink to /data/web/magento2/pub and
118
+ # we mount that. On Magento 1 Vagrants we need to make sure we don't
119
+ # mount /data/web/magento2/pub.
120
+ def ensure_magento_mounts_configured(env)
121
+ settings = retrieve_settings()
122
+ if !settings['fs'].nil? and !settings['fs']['folders'].nil?
123
+ if settings['fs']['disabled_folders'].nil?
124
+ settings['fs']['disabled_folders'] = Hash.new
125
+ end
126
+ if settings['magento']['version'] == 1
127
+ if !settings['fs']['disabled_folders']['magento1'].nil?
128
+ settings['fs']['folders']['magento1'] = settings['fs']['disabled_folders']['magento1'].clone
129
+ settings['fs']['disabled_folders'].delete('magento1')
130
+ env[:ui].info("Re-enabling fs->disabled_folders->magento1 in the local.yml.")
131
+ end
132
+ if !settings['fs']['folders']['magento2'].nil?
133
+ settings['fs']['disabled_folders']['magento2'] = settings['fs']['folders']['magento2'].clone
134
+ settings['fs']['folders'].delete('magento2')
135
+ env[:ui].info("Disabling fs->folders->magento2 in the local.yml because Magento 1 was configured.")
136
+ end
137
+ elsif settings['magento']['version'] == 2
138
+ if !settings['fs']['disabled_folders']['magento2'].nil?
139
+ settings['fs']['folders']['magento2'] = settings['fs']['disabled_folders']['magento2'].clone
140
+ settings['fs']['disabled_folders'].delete('magento2')
141
+ env[:ui].info("Re-enabling fs->disabled_folders->magento2 in the local.yml.")
142
+ end
143
+ if !settings['fs']['folders']['magento1'].nil?
144
+ settings['fs']['disabled_folders']['magento1'] = settings['fs']['folders']['magento1'].clone
145
+ settings['fs']['folders'].delete('magento1')
146
+ env[:ui].info("Disabling fs->folders->magento1 in the local.yml because Magento 2 was configured..")
147
+ end
148
+ end
149
+ if settings['fs']['disabled_folders'] == Hash.new
150
+ settings['fs'].delete('disabled_folders')
151
+ end
152
+ end
153
+ update_settings(settings)
154
+ end
155
+
156
+
157
+ # todo: refactor this and the above function into one
158
+ def ensure_php_version_configured(env)
159
+ settings = retrieve_settings()
160
+ if settings['php']['version'].nil?
161
+ settings['php']['version'] = get_php_version(env)
162
+ elsif !AVAILABLE_PHP_VERSIONS.include?(settings['php']['version'].to_f)
163
+ env[:ui].error("The PHP version configured in local.yml is invalid.")
164
+ settings['php']['version'] = get_php_version(env)
165
+ end
166
+ update_settings(settings)
167
+ end
168
+
169
+
170
+ def ensure_setting_exists(name)
171
+ settings = retrieve_settings()
172
+ if settings[name].nil?
173
+ settings[name] = Hash.new
174
+ end
175
+ update_settings(settings)
176
+ end
177
+
178
+
179
+ def validate_magento2_root(env)
180
+ settings = retrieve_settings()
181
+ if !settings['fs'].nil? and !settings['fs']['folders'].nil?
182
+ if settings['fs']['folders'].select{ |_, f| f['guest'].start_with?('/data/web/public') }.any? && settings['magento']['version'] == 2
183
+ env[:ui].info("Can not configure a synced /data/web/public directory with Magento 2, this will be symlinked to /data/web/magento2!")
184
+ env[:ui].error("Please remove all fs->folders->*->guest paths that start with /data/web/public from your local.yml. Use /data/web/magento2 instead.")
185
+ end
186
+ end
187
+ end
188
+
189
+
190
+ def ensure_settings_configured(env)
191
+ old_settings = retrieve_settings()
192
+ ensure_setting_exists('magento')
193
+ ensure_magento_version_configured(env)
194
+ ensure_setting_exists('php')
195
+ ensure_php_version_configured(env)
196
+ ensure_setting_exists('varnish')
197
+ ensure_varnish_state_configured(env)
198
+ ensure_magento_mounts_configured(env)
199
+ validate_magento2_root(env)
200
+ new_settings = retrieve_settings()
201
+ return new_settings.to_yaml != old_settings.to_yaml
202
+ end
203
+
204
+
205
+ def ensure_required_plugins_are_installed(env)
206
+ RECOMMENDED_PLUGINS.each do |plugin|
207
+ unless Vagrant.has_plugin?(plugin)
208
+ env[:ui].info("Installing the #{plugin} plugin.")
209
+ system("vagrant plugin install #{plugin}")
210
+ end
211
+ end
212
+ end
213
+
214
+
215
+ module VagrantHypconfigmgmt
216
+ class Command
217
+
218
+ def initialize(app, env)
219
+ @app = app
220
+ @env = env
221
+ end
222
+
223
+ def call(env)
224
+ if env[:machine].config.hypconfigmgmt.enabled
225
+ changed = ensure_settings_configured(env)
226
+ ensure_required_plugins_are_installed(env)
227
+ if changed
228
+ env[:ui].info("Your hypernode-vagrant is now configured. Please run \"vagrant up\" again.")
229
+ return
230
+ end
231
+ end
232
+ @app.call(env)
233
+ end
234
+ end
235
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # vim: set fileencoding=utf-8
3
+
4
+ require 'vagrant'
5
+
6
+ module VagrantHypconfigmgmt
7
+ class Config < Vagrant.plugin("2", :config)
8
+ attr_accessor :enabled
9
+
10
+ def initialize
11
+ super
12
+ # UNSET_VALUE so that Vagrant can properly automatically merge multiple configurations.
13
+ # https://www.vagrantup.com/docs/plugins/configuration.html
14
+ @enabled = UNSET_VALUE
15
+ end
16
+
17
+ def finalize!
18
+ @enabled = (@enabled != UNSET_VALUE) && (@enabled != false)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,8 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # vim: set fileencoding=utf-8
3
+
4
+ module Vagrant
5
+ module Hypconfigmgmt
6
+ VERSION = "0.0.1"
7
+ end
8
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # vim: set fileencoding=utf-8
3
+
4
+ require "vagrant"
5
+ require "vagrant-hypconfigmgmt/command"
6
+
7
+ module VagrantHypconfigmgmt
8
+ class Plugin < Vagrant.plugin("2")
9
+ name "hypconfigmgmt"
10
+ description <<-DESC
11
+ Configure the hypernode-vagrant during runtime
12
+ DESC
13
+
14
+ config 'hypconfigmgmt' do
15
+ require File.expand_path("../vagrant-hypconfigmgmt/config", __FILE__)
16
+ Config
17
+ end
18
+
19
+ action_hook(:VagrantHypconfigmgmt, :machine_action_up) do |hook|
20
+ hook.prepend(VagrantHypconfigmgmt::Command)
21
+ end
22
+ end
23
+ end
Binary file
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ require File.expand_path('../lib/vagrant-hypconfigmgmt/version', __FILE__)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "vagrant-hypconfigmgmt"
6
+ spec.version = Vagrant::Hypconfigmgmt::VERSION
7
+ spec.authors = ["Rick van de Loo"]
8
+ spec.email = ["rick@byte.nl"]
9
+ spec.description = %q{Prompt to configure a hypernode-vagrant}
10
+ spec.summary = %q{Prompt to configure a hypernode-vagrant}
11
+ spec.homepage = "https://github.com/ByteInternet/hypernode-vagrant"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files`.split("\n")
15
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler"
20
+ spec.add_development_dependency "rake"
21
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-hypconfigmgmt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rick van de Loo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Prompt to configure a hypernode-vagrant
42
+ email:
43
+ - rick@byte.nl
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - Makefile
52
+ - README.md
53
+ - Rakefile
54
+ - lib/vagrant-hypconfigmgmt.rb
55
+ - lib/vagrant-hypconfigmgmt/command.rb
56
+ - lib/vagrant-hypconfigmgmt/config.rb
57
+ - lib/vagrant-hypconfigmgmt/version.rb
58
+ - pkg/vagrant-hypconfigmgmt-0.0.1.gem
59
+ - vagrant-hypconfigmgmt.gemspec
60
+ homepage: https://github.com/ByteInternet/hypernode-vagrant
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.5.1
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Prompt to configure a hypernode-vagrant
84
+ test_files: []