vagrant-impressbox 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +31 -0
- data/Rakefile +9 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/vagrant-impressbox.rb +21 -0
- data/lib/vagrant-impressbox/action_builder.rb +20 -0
- data/lib/vagrant-impressbox/actions/copy_git_settings.rb +38 -0
- data/lib/vagrant-impressbox/actions/insert_key.rb +56 -0
- data/lib/vagrant-impressbox/command.rb +165 -0
- data/lib/vagrant-impressbox/config.rb +38 -0
- data/lib/vagrant-impressbox/configs/command.yml +30 -0
- data/lib/vagrant-impressbox/configs/default.yml +13 -0
- data/lib/vagrant-impressbox/configs/for/impresscms.yml +8 -0
- data/lib/vagrant-impressbox/configurators/base.rb +21 -0
- data/lib/vagrant-impressbox/configurators/hyperv.rb +36 -0
- data/lib/vagrant-impressbox/configurators/virtualbox.rb +23 -0
- data/lib/vagrant-impressbox/objects/config_data.rb +62 -0
- data/lib/vagrant-impressbox/objects/config_file.rb +128 -0
- data/lib/vagrant-impressbox/objects/configurator.rb +135 -0
- data/lib/vagrant-impressbox/objects/ssh_key_detect.rb +116 -0
- data/lib/vagrant-impressbox/objects/template.rb +99 -0
- data/lib/vagrant-impressbox/plugin.rb +46 -0
- data/lib/vagrant-impressbox/provisioner.rb +103 -0
- data/lib/vagrant-impressbox/templates/Vagrantfile +37 -0
- data/lib/vagrant-impressbox/templates/config.yaml +76 -0
- data/lib/vagrant-impressbox/version.rb +4 -0
- data/locales/en.yml +28 -0
- data/spec/impressbox_spec.rb +11 -0
- data/spec/spec_helper.rb +2 -0
- data/vagrant-impressbox.gemspec +31 -0
- metadata +157 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
# Loads all requirements
|
2
|
+
require 'vagrant'
|
3
|
+
|
4
|
+
# Impressbox namepsace
|
5
|
+
module Impressbox
|
6
|
+
# Vagrant config class
|
7
|
+
class Config < Vagrant.plugin('2', :config)
|
8
|
+
# @!attribute file
|
9
|
+
# @return [string] Filename from where to read all config data
|
10
|
+
attr_reader :file
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@file = UNSET_VALUE
|
14
|
+
end
|
15
|
+
|
16
|
+
def finalize!
|
17
|
+
@file = 'config.yaml' if @file == UNSET_VALUE
|
18
|
+
end
|
19
|
+
|
20
|
+
def file_config
|
21
|
+
unless @file_config_data
|
22
|
+
require_relative File.join('objects', 'config_file')
|
23
|
+
@file_config_data = Impressbox::Objects::ConfigFile.new(@file)
|
24
|
+
end
|
25
|
+
@file_config_data
|
26
|
+
end
|
27
|
+
|
28
|
+
def validate(_machine)
|
29
|
+
errors = []
|
30
|
+
|
31
|
+
unless File.exist?(@file)
|
32
|
+
errors << I18n.t('config.not_exist', file: @file)
|
33
|
+
end
|
34
|
+
|
35
|
+
{ 'Impressbox' => errors }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
box:
|
2
|
+
short: -b
|
3
|
+
full: --box=BOX_NAME
|
4
|
+
description: command.impressbox.arguments.box
|
5
|
+
|
6
|
+
ip:
|
7
|
+
description: command.impressbox.arguments.ip
|
8
|
+
full: --ip=IP
|
9
|
+
|
10
|
+
hostname:
|
11
|
+
full: --url=HOSTNAME
|
12
|
+
description: command.impressbox.arguments.hostname
|
13
|
+
|
14
|
+
memory:
|
15
|
+
full: --memory=RAM
|
16
|
+
description: command.impressbox.arguments.memory
|
17
|
+
|
18
|
+
cpus:
|
19
|
+
full: --cpus=CPU_NUMBER
|
20
|
+
description: command.impressbox.arguments.cpus
|
21
|
+
|
22
|
+
___recreate___:
|
23
|
+
short: -r
|
24
|
+
full: --recreate
|
25
|
+
description: command.impressbox.arguments.special.recreate
|
26
|
+
|
27
|
+
___use_template___:
|
28
|
+
short: -f
|
29
|
+
full: --for=NAME
|
30
|
+
description: command.impressbox.arguments.special.use_template
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Impressbox namespace
|
2
|
+
module Impressbox
|
3
|
+
# Configurators namespace
|
4
|
+
module Configurators
|
5
|
+
# Base configurator
|
6
|
+
class Base
|
7
|
+
# @!attribute [rw] config
|
8
|
+
attr_accessor :config
|
9
|
+
|
10
|
+
# initializer
|
11
|
+
def initialize(config)
|
12
|
+
@config = config
|
13
|
+
end
|
14
|
+
|
15
|
+
# Is with same name?
|
16
|
+
def same?(name)
|
17
|
+
self.class.name.eql?(name)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
module Impressbox
|
4
|
+
# Configurators namespace
|
5
|
+
module Configurators
|
6
|
+
# HyperV configurator
|
7
|
+
class HyperV < Impressbox::Configurators::Base
|
8
|
+
# Configure basic settings
|
9
|
+
def basic_configure(vmname, cpus, memory, _gui)
|
10
|
+
@config.vm.provider 'hyperv' do |v|
|
11
|
+
v.vmname = vmname
|
12
|
+
v.cpus = cpus
|
13
|
+
v.memory = memory
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Configure specific
|
18
|
+
def specific_configure(cfg)
|
19
|
+
samba_configure cfg.ip, cfg.pass, cfg.user
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# Configure samba
|
25
|
+
def samba_configure(ip, password, username)
|
26
|
+
@config.vm.synced_folder '.', '/vagrant',
|
27
|
+
id: 'vagrant',
|
28
|
+
smb_host: ip,
|
29
|
+
smb_password: password,
|
30
|
+
smb_username: username,
|
31
|
+
user: 'www-data',
|
32
|
+
owner: 'www-data'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
|
3
|
+
module Impressbox
|
4
|
+
# Configurators namespace
|
5
|
+
module Configurators
|
6
|
+
# Virtualbox configurator
|
7
|
+
class VirtualBox < Impressbox::Configurators::Base
|
8
|
+
# Configure basic settings
|
9
|
+
def basic_configure(vmname, cpus, memory, gui)
|
10
|
+
@config.vm.provider 'virtualbox' do |v|
|
11
|
+
v.gui = gui
|
12
|
+
v.vmname = vmname
|
13
|
+
v.cpus = cpus
|
14
|
+
v.memory = memory
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Configure specific
|
19
|
+
def specific_configure(cfg)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Impressbox
|
2
|
+
module Objects
|
3
|
+
# This class is used for deal with configs subfolder contents
|
4
|
+
class ConfigData
|
5
|
+
def self.list_of_type(name)
|
6
|
+
ret = []
|
7
|
+
Dir.entries(real_path(name)).select do |f|
|
8
|
+
next if File.directory?(f)
|
9
|
+
ret.push File.basename(f, '.*')
|
10
|
+
end
|
11
|
+
ret
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.real_path(filename)
|
15
|
+
File.join File.dirname(File.dirname(__FILE__)), 'configs', filename
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.real_type_filename(type, filename)
|
19
|
+
real_path File.join(type, filename + '.yml')
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(filename)
|
23
|
+
@filename = ConfigData.real_path(filename)
|
24
|
+
@data = symbolize_keys(load_yaml)
|
25
|
+
end
|
26
|
+
|
27
|
+
def [](key)
|
28
|
+
@data[key]
|
29
|
+
end
|
30
|
+
|
31
|
+
def all
|
32
|
+
@data
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def load_yaml
|
38
|
+
YAML.load(File.open(@filename))
|
39
|
+
end
|
40
|
+
|
41
|
+
def symbolize_make_new_key(key)
|
42
|
+
case key
|
43
|
+
when String then key.to_sym
|
44
|
+
else key
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Code from http://devblog.avdi.org/2009/07/14/recursively-symbolize-keys/
|
49
|
+
def symbolize_keys(hash)
|
50
|
+
hash.inject({}) do |result, (key, value)|
|
51
|
+
new_key = symbolize_make_new_key(key)
|
52
|
+
new_value = case value
|
53
|
+
when Hash then symbolize_keys(value)
|
54
|
+
else value
|
55
|
+
end
|
56
|
+
result[new_key] = new_value
|
57
|
+
result
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'vagrant'
|
2
|
+
require 'yaml'
|
3
|
+
require_relative 'config_data'
|
4
|
+
|
5
|
+
# Impressbox namespace
|
6
|
+
module Impressbox
|
7
|
+
# Objects namepsace
|
8
|
+
module Objects
|
9
|
+
# Config reader
|
10
|
+
class ConfigFile
|
11
|
+
UNSET_VALUE = ::Vagrant::Plugin::V2::Config::UNSET_VALUE
|
12
|
+
|
13
|
+
# @!attribute [rw] ip
|
14
|
+
attr_accessor :ip
|
15
|
+
|
16
|
+
# @!attribute [rw] hostname
|
17
|
+
attr_accessor :hostname
|
18
|
+
|
19
|
+
# @!attribute [rw] name
|
20
|
+
attr_accessor :name
|
21
|
+
|
22
|
+
# @!attribute [rw] cpus
|
23
|
+
attr_accessor :cpus
|
24
|
+
|
25
|
+
# @!attribute [rw] memory
|
26
|
+
attr_accessor :memory
|
27
|
+
|
28
|
+
# @!attribute [rw] check_update
|
29
|
+
attr_accessor :check_update
|
30
|
+
|
31
|
+
# @!attribute [rw] keys
|
32
|
+
attr_accessor :keys
|
33
|
+
|
34
|
+
# @!attribute [rw] smb
|
35
|
+
attr_accessor :smb
|
36
|
+
|
37
|
+
# @!attribute [rw] ports
|
38
|
+
attr_accessor :ports
|
39
|
+
|
40
|
+
# @!attribute [rw] gui
|
41
|
+
attr_accessor :gui
|
42
|
+
|
43
|
+
# @!attribute [rw] provision
|
44
|
+
attr_accessor :provision
|
45
|
+
|
46
|
+
def initialize(file)
|
47
|
+
@default = ConfigData.new('default.yml')
|
48
|
+
map_values YAML.load(File.open(file))
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def map_values(config)
|
54
|
+
%w(
|
55
|
+
cpus memory check_update ip hostname name
|
56
|
+
ports keys smb provision).each do |attr|
|
57
|
+
method_name = 'convert_' + attr
|
58
|
+
instance_variable_set '@' + attr, method(method_name).call(config)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def convert_provision(config)
|
63
|
+
select_value(config, 'provision', @default[:provision]).to_s
|
64
|
+
end
|
65
|
+
|
66
|
+
def convert_name(config)
|
67
|
+
select_value(config, 'name', @default[:name]).to_s
|
68
|
+
end
|
69
|
+
|
70
|
+
def convert_ip(config)
|
71
|
+
select_value(config, 'ip', @default[:ip])
|
72
|
+
end
|
73
|
+
|
74
|
+
def convert_cpus(config)
|
75
|
+
select_value(config, 'cpus', @default[:cpus]).to_s.to_i
|
76
|
+
end
|
77
|
+
|
78
|
+
def convert_memory(config)
|
79
|
+
select_value(config, 'memory', @default[:memory]).to_s.to_i
|
80
|
+
end
|
81
|
+
|
82
|
+
def convert_hostname(config)
|
83
|
+
value = select_value(config, 'hostname', @default[:hostname])
|
84
|
+
return @default[:hostname] if value.nil?
|
85
|
+
unless value.is_a?(String) && value.is_a?(Array)
|
86
|
+
return @default[:hostname]
|
87
|
+
end
|
88
|
+
value
|
89
|
+
end
|
90
|
+
|
91
|
+
def convert_ports(config)
|
92
|
+
select_value(config, 'ports', @default[:ports])
|
93
|
+
end
|
94
|
+
|
95
|
+
def convert_check_update(config)
|
96
|
+
value = select_value(config, 'check_update', @default[:check_update])
|
97
|
+
to_b(value)
|
98
|
+
end
|
99
|
+
|
100
|
+
def to_b(value)
|
101
|
+
return true if value
|
102
|
+
false
|
103
|
+
end
|
104
|
+
|
105
|
+
def convert_keys(config)
|
106
|
+
value = select_value(config, 'keys', {})
|
107
|
+
value = {} unless value.is_a?(Hash)
|
108
|
+
value[:private] = nil unless value.key?('private')
|
109
|
+
value[:public] = nil unless value.key?('public')
|
110
|
+
value
|
111
|
+
end
|
112
|
+
|
113
|
+
def convert_smb(config)
|
114
|
+
value = select_value(config, 'smb', {})
|
115
|
+
value = {} unless value.is_a?(Hash)
|
116
|
+
value[:ip] = nil unless value.key?('ip')
|
117
|
+
value[:user] = nil unless value.key?('user')
|
118
|
+
value[:pass] = nil unless value.key?('pass')
|
119
|
+
value
|
120
|
+
end
|
121
|
+
|
122
|
+
def select_value(config, key, default_value)
|
123
|
+
return config[key] if config.key?(key)
|
124
|
+
default_value
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require_relative 'template'
|
2
|
+
|
3
|
+
# Impressbox namespace
|
4
|
+
module Impressbox
|
5
|
+
# Objects Namespace
|
6
|
+
module Objects
|
7
|
+
# Class used to configure instance
|
8
|
+
class Configurator
|
9
|
+
CONFIGURATORS = %w(
|
10
|
+
HyperV
|
11
|
+
VirtualBox
|
12
|
+
).freeze
|
13
|
+
|
14
|
+
# Initializator
|
15
|
+
def initialize(root_config, machine, provider)
|
16
|
+
@config = root_config
|
17
|
+
@machine = machine
|
18
|
+
@template = Impressbox::Objects::Template.new
|
19
|
+
load_configurators provider
|
20
|
+
end
|
21
|
+
|
22
|
+
def load_configurators(provider)
|
23
|
+
@configurators = []
|
24
|
+
CONFIGURATORS.each do |name|
|
25
|
+
require_relative File.join('..', 'configurators', name.downcase)
|
26
|
+
class_name = 'Impressbox::Configurators::' + name
|
27
|
+
clazz = class_name.split('::').inject(Object) do |o, c|
|
28
|
+
o.const_get c
|
29
|
+
end
|
30
|
+
instance = clazz.new(@config)
|
31
|
+
@configurators.push instance if instance.same?(provider)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Provision
|
36
|
+
# cd /srv/www/phpmyadmin
|
37
|
+
# chown -R www-data ./
|
38
|
+
# chgrp www-data ./
|
39
|
+
# git pull
|
40
|
+
# chown -R www-data ./
|
41
|
+
# chgrp www-data ./
|
42
|
+
# cd /srv/www/Memchaced-Dashboard
|
43
|
+
# chown -R www-data ./
|
44
|
+
# chgrp www-data ./
|
45
|
+
# git pull
|
46
|
+
# chown -R www-data ./
|
47
|
+
# chgrp www-data ./
|
48
|
+
|
49
|
+
# Basic configure
|
50
|
+
def basic_configure(vmname, cpus, memory, gui)
|
51
|
+
@configurators.each do |configurator|
|
52
|
+
configurator.basic_configure vmname, cpus, memory, gui
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Specific configure
|
57
|
+
def specific_configure(config)
|
58
|
+
@configurators.each do |configurator|
|
59
|
+
configurator.specific_configure config
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Box name to use for this vagrant configuration
|
64
|
+
def name(name)
|
65
|
+
@config.vm.box = name
|
66
|
+
end
|
67
|
+
|
68
|
+
# Configure SSH
|
69
|
+
def configure_ssh(public_key, private_key)
|
70
|
+
# @config.ssh.insert_key = true
|
71
|
+
@config.ssh.pty = false
|
72
|
+
@config.ssh.forward_x11 = false
|
73
|
+
@config.ssh.forward_agent = false
|
74
|
+
Impressbox::Plugin.set_item :public_key, public_key
|
75
|
+
Impressbox::Plugin.set_item :private_key, private_key
|
76
|
+
end
|
77
|
+
|
78
|
+
# configure hostnames
|
79
|
+
def configure_hostnames(hostname, aliases)
|
80
|
+
require 'vagrant-hostmanager'
|
81
|
+
@config.vm.hostname = hostname
|
82
|
+
@config.hostmanager.enabled = true
|
83
|
+
@config.hostmanager.manage_host = true
|
84
|
+
@config.hostmanager.manage_guest = true
|
85
|
+
@config.hostmanager.ignore_private_ip = false
|
86
|
+
@config.hostmanager.include_offline = true
|
87
|
+
@config.hostmanager.aliases = aliases unless aliases.empty?
|
88
|
+
end
|
89
|
+
|
90
|
+
# Configure network
|
91
|
+
def configure_network(ip)
|
92
|
+
return unless ip
|
93
|
+
@config.vm.network 'private_network',
|
94
|
+
ip: ip
|
95
|
+
end
|
96
|
+
|
97
|
+
# Forward vars
|
98
|
+
def forward_vars(vars)
|
99
|
+
@config.ssh.forward_env = vars
|
100
|
+
end
|
101
|
+
|
102
|
+
# Automatically check for update for this box ?
|
103
|
+
def check_for_update(check)
|
104
|
+
@config.vm.box_check_update = check
|
105
|
+
end
|
106
|
+
|
107
|
+
# forward one port
|
108
|
+
def forward_port(guest_port, host_port, protocol = 'tcp')
|
109
|
+
@config.vm.network 'forwarded_port',
|
110
|
+
guest: guest_port,
|
111
|
+
host: host_port,
|
112
|
+
protocol: protocol,
|
113
|
+
auto_correct: true
|
114
|
+
end
|
115
|
+
|
116
|
+
# Forward ports
|
117
|
+
def forward_ports(ports)
|
118
|
+
ports.each do |pgroup|
|
119
|
+
forward_port pgroup['guest'],
|
120
|
+
pgroup['host'],
|
121
|
+
extract_protocol(pgroup)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
def extract_protocol(pgroup)
|
128
|
+
possible = %w(tcp udp)
|
129
|
+
return 'tcp' unless pgroup.key?('protocol')
|
130
|
+
return 'tcp' unless possible.include?(pgroup['protocol'])
|
131
|
+
pgroup[protocol]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|