vagrant-impressbox 0.1.0
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 +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,116 @@
|
|
1
|
+
module Impressbox
|
2
|
+
module Objects
|
3
|
+
# This class is used for detecting SSh keys automatically
|
4
|
+
class SshKeyDetect
|
5
|
+
UNSET_VALUE = ::Vagrant::Plugin::V2::Config::UNSET_VALUE
|
6
|
+
|
7
|
+
# @!attribute [rw] private_key
|
8
|
+
attr_accessor :private_key
|
9
|
+
|
10
|
+
# @!attribute [rw] public_key
|
11
|
+
attr_accessor :public_key
|
12
|
+
|
13
|
+
# initializer
|
14
|
+
def initialize(config)
|
15
|
+
keys_from_config config
|
16
|
+
unless validate
|
17
|
+
detect_ssh_keys_from_config
|
18
|
+
unless validate
|
19
|
+
detect_from_filesystem
|
20
|
+
validate
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def keys_from_config(config)
|
26
|
+
@private_key = config.keys[:private] if key_is_set(config, :private)
|
27
|
+
if key_is_set(config, :private)
|
28
|
+
@public_key = config.keys[:public] if config.keys[:public]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def key_is_set(config, name)
|
33
|
+
config.keys[name].nil? && (config.keys[name] != UNSET_VALUE)
|
34
|
+
end
|
35
|
+
|
36
|
+
def empty?
|
37
|
+
@private_key.nil? && @public_key.nil?
|
38
|
+
end
|
39
|
+
|
40
|
+
def private_key?
|
41
|
+
!@private_key.nil?
|
42
|
+
end
|
43
|
+
|
44
|
+
def public_key?
|
45
|
+
!@public_key.nil?
|
46
|
+
end
|
47
|
+
|
48
|
+
def validate
|
49
|
+
return false unless private_key?
|
50
|
+
return false unless public_key?
|
51
|
+
File.exist?(@private_key) && File.exist?(@public_key)
|
52
|
+
end
|
53
|
+
|
54
|
+
# Try detect SSH keys by using only a config
|
55
|
+
def detect_ssh_keys_from_config
|
56
|
+
if private_key?
|
57
|
+
@public_key = @private_key + '.pub'
|
58
|
+
elsif public_key?
|
59
|
+
@private_key = private_filename_from_public(@public_key)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Try detect SSH keys by using local filesystem
|
64
|
+
def detect_from_filesystem
|
65
|
+
ssh_keys_search_paths.each do |dir|
|
66
|
+
iterate_dir_fs dir
|
67
|
+
break unless empty?
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# used in detect_ssh_keys_from_filesystem
|
72
|
+
def iterate_dir_fs(dir)
|
73
|
+
Dir.entries(dir).each do |entry|
|
74
|
+
entry = File.join(dir, entry)
|
75
|
+
next unless good_file_on_filesystem?(entry)
|
76
|
+
@private_key = private_filename_from_public(entry)
|
77
|
+
@public_key = entry
|
78
|
+
break
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# converts private SSH key to public
|
83
|
+
def private_filename_from_public(filename)
|
84
|
+
File.join(
|
85
|
+
File.dirname(
|
86
|
+
filename
|
87
|
+
),
|
88
|
+
File.basename(
|
89
|
+
filename,
|
90
|
+
'.pub'
|
91
|
+
)
|
92
|
+
)
|
93
|
+
end
|
94
|
+
|
95
|
+
# is a correct file in filesystem tobe a SSH key?
|
96
|
+
def good_file_on_filesystem?(filename)
|
97
|
+
File.file?(filename) && \
|
98
|
+
File.extname(filename).eql?('.pub') && \
|
99
|
+
File.exist?(private_filename_from_public(filename))
|
100
|
+
end
|
101
|
+
|
102
|
+
# gets paths for looking for SSH keys
|
103
|
+
def ssh_keys_search_paths
|
104
|
+
[
|
105
|
+
File.join(__dir__, '.ssh'),
|
106
|
+
File.join(__dir__, 'ssh'),
|
107
|
+
File.join(__dir__, 'keys'),
|
108
|
+
File.join(Dir.home, '.ssh'),
|
109
|
+
File.join(Dir.home, 'keys')
|
110
|
+
].reject do |dir|
|
111
|
+
!Dir.exist?(dir)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'mustache'
|
2
|
+
|
3
|
+
# Impressbox namespace
|
4
|
+
module Impressbox
|
5
|
+
# Objects namespace
|
6
|
+
module Objects
|
7
|
+
# Template
|
8
|
+
class Template
|
9
|
+
def real_path(filename)
|
10
|
+
File.join File.dirname(File.dirname(__FILE__)), 'templates', filename
|
11
|
+
end
|
12
|
+
|
13
|
+
def prepare_file(src_file, dst_file, options, default, base_file = nil)
|
14
|
+
new_options = make_new_options(
|
15
|
+
src_file, dst_file, options,
|
16
|
+
default, base_file
|
17
|
+
)
|
18
|
+
ret = render_string(src_file, new_options)
|
19
|
+
File.write dst_file, ret
|
20
|
+
new_options.to_a == options.to_a
|
21
|
+
end
|
22
|
+
|
23
|
+
def render_string(src_file, options)
|
24
|
+
Mustache.render File.read(src_file), options
|
25
|
+
end
|
26
|
+
|
27
|
+
def quick_prepare(filename, options, recreate, default, base_file = nil)
|
28
|
+
dst_file = File.basename(filename)
|
29
|
+
File.delete dst_file if recreate && File.exist?(dst_file)
|
30
|
+
prepare_file filename, dst_file, options, default, base_file
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def make_new_options(_src_file, dst_file, options, default, base_file)
|
36
|
+
merge_options_multiple(
|
37
|
+
make_data_filenames_array([
|
38
|
+
base_file,
|
39
|
+
dst_file
|
40
|
+
]),
|
41
|
+
default,
|
42
|
+
options
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
def make_data_filenames_array(filenames)
|
47
|
+
filenames.reject do |f|
|
48
|
+
f.nil? || f.empty?
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def merge_options_multiple(filenames, default, options)
|
53
|
+
ret = default
|
54
|
+
filenames.each do |filename|
|
55
|
+
ret = merge_options(filename, ret.dup)
|
56
|
+
end
|
57
|
+
options.each do |key, val|
|
58
|
+
next if key.to_s.start_with?('__')
|
59
|
+
if val.kind_of?(String)
|
60
|
+
parts = val.split(/\r?\n/)
|
61
|
+
if parts.length > 1
|
62
|
+
val = parts
|
63
|
+
end
|
64
|
+
end
|
65
|
+
ret[key.to_sym] = val
|
66
|
+
end
|
67
|
+
ret
|
68
|
+
end
|
69
|
+
|
70
|
+
def merge_options(filename, options)
|
71
|
+
return options unless File.exist? filename
|
72
|
+
ext = File.extname(filename)
|
73
|
+
return options if ext.nil? || ext == ''
|
74
|
+
method_name = 'merge_file' + ext.sub!('.', '_')
|
75
|
+
method(method_name).call filename, options
|
76
|
+
end
|
77
|
+
|
78
|
+
def merge_file_yml(filename, options)
|
79
|
+
merge_file_yaml(filename, options)
|
80
|
+
end
|
81
|
+
|
82
|
+
def merge_file_yaml(filename, options)
|
83
|
+
old_data = YAML.load(File.open(filename))
|
84
|
+
new_data = options.dup
|
85
|
+
old_data.each do |key, val|
|
86
|
+
next if key.to_s.start_with?('__')
|
87
|
+
if val.kind_of?(String)
|
88
|
+
parts = val.split(/\r?\n/)
|
89
|
+
if parts.length > 1
|
90
|
+
val = parts
|
91
|
+
end
|
92
|
+
end
|
93
|
+
new_data[key.to_sym] = val
|
94
|
+
end
|
95
|
+
new_data
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Loads all requirements
|
2
|
+
require 'vagrant'
|
3
|
+
|
4
|
+
# Plugin definition
|
5
|
+
class Impressbox::Plugin < Vagrant.plugin(2)
|
6
|
+
@@data = {}
|
7
|
+
|
8
|
+
name 'vagrant-impressbox'
|
9
|
+
|
10
|
+
description I18n.t('description')
|
11
|
+
|
12
|
+
def self.set_item(property, value)
|
13
|
+
@@data[property] = value
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.get_item(property)
|
17
|
+
@@data[property]
|
18
|
+
end
|
19
|
+
|
20
|
+
config(:impressbox, :provisioner) do
|
21
|
+
require_relative 'config'
|
22
|
+
Impressbox::Config
|
23
|
+
end
|
24
|
+
|
25
|
+
provisioner(:impressbox) do
|
26
|
+
require_relative 'provisioner'
|
27
|
+
Impressbox::Provisioner
|
28
|
+
end
|
29
|
+
|
30
|
+
action_hook(:impressbox) do |hook|
|
31
|
+
require_relative 'action_builder'
|
32
|
+
hook.after(
|
33
|
+
Vagrant::Action::Builtin::Provision,
|
34
|
+
Impressbox::ActionBuilder.insert_key
|
35
|
+
)
|
36
|
+
hook.after(
|
37
|
+
Vagrant::Action::Builtin::Provision,
|
38
|
+
Impressbox::ActionBuilder.copy_git_settings
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
command 'impressbox' do
|
43
|
+
require_relative 'command'
|
44
|
+
Impressbox::Command
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# Loads all requirements
|
2
|
+
require 'vagrant'
|
3
|
+
require_relative File.join('objects', 'ssh_key_detect.rb')
|
4
|
+
|
5
|
+
# Impressbox namepsace
|
6
|
+
module Impressbox
|
7
|
+
# Provisioner namepsace
|
8
|
+
class Provisioner < Vagrant.plugin('2', :provisioner)
|
9
|
+
# @!attribute [rw] provision_actions
|
10
|
+
attr_accessor :provision_actions
|
11
|
+
|
12
|
+
def provision
|
13
|
+
if !@provision_actions.nil? && @provision_actions.to_s.length > 0
|
14
|
+
@machine.communicate.wait_for_ready 300
|
15
|
+
|
16
|
+
@machine.communicate.execute(@provision_actions.to_s) do |type, line|
|
17
|
+
write_line type, line
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def cleanup
|
23
|
+
end
|
24
|
+
|
25
|
+
def configure(root_config)
|
26
|
+
configurator = create_configurator(root_config)
|
27
|
+
cfg = xaml_config
|
28
|
+
|
29
|
+
do_primary_configuration configurator, cfg
|
30
|
+
do_ssh_configuration configurator, cfg
|
31
|
+
do_provider_configuration configurator, cfg
|
32
|
+
do_network_configuration configurator, cfg
|
33
|
+
do_provision_configure configurator, cfg
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def write_line(type, contents)
|
39
|
+
case type
|
40
|
+
when :stdout
|
41
|
+
@machine.ui.info contents
|
42
|
+
when :stderr
|
43
|
+
@machine.ui.error contents
|
44
|
+
else
|
45
|
+
@machine.ui.info 'W: ' + type
|
46
|
+
@machine.ui.info contents
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def do_provision_configure(_configurator, cfg)
|
51
|
+
@provision_actions = cfg.provision if !cfg.provision.nil? && cfg.provision
|
52
|
+
end
|
53
|
+
|
54
|
+
def do_primary_configuration(configurator, cfg)
|
55
|
+
configurator.name cfg.name
|
56
|
+
configurator.check_for_update cfg.check_update
|
57
|
+
configurator.forward_ports cfg.ports
|
58
|
+
end
|
59
|
+
|
60
|
+
def do_network_configuration(configurator, cfg)
|
61
|
+
configurator.configure_network cfg.ip unless cfg.ip.nil?
|
62
|
+
aliases = cfg.hostname
|
63
|
+
if aliases.is_a?(Array)
|
64
|
+
hostname = aliases.shift
|
65
|
+
else
|
66
|
+
hostname = aliases.dup
|
67
|
+
aliases = []
|
68
|
+
end
|
69
|
+
configurator.configure_hostnames(hostname, aliases)
|
70
|
+
end
|
71
|
+
|
72
|
+
def do_ssh_configuration(configurator, cfg)
|
73
|
+
keys = Impressbox::Objects::SshKeyDetect.new(cfg)
|
74
|
+
configurator.configure_ssh keys.public_key, keys.private_key
|
75
|
+
end
|
76
|
+
|
77
|
+
def do_provider_configuration(configurator, cfg)
|
78
|
+
configurator.basic_configure cfg.name, cfg.cpus, cfg.memory, cfg.gui
|
79
|
+
configurator.specific_configure cfg
|
80
|
+
end
|
81
|
+
|
82
|
+
def detect_provider
|
83
|
+
if ARGV[1] && (ARGV[1].split('=')[0] == '--provider' || ARGV[2])
|
84
|
+
return (ARGV[1].split('=')[1] || ARGV[2])
|
85
|
+
end
|
86
|
+
(ENV['VAGRANT_DEFAULT_PROVIDER'] || :virtualbox).to_sym
|
87
|
+
end
|
88
|
+
|
89
|
+
def create_configurator(root_config)
|
90
|
+
require_relative File.join('objects', 'configurator')
|
91
|
+
Impressbox::Objects::Configurator.new(
|
92
|
+
root_config,
|
93
|
+
@machine,
|
94
|
+
detect_provider
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
def xaml_config
|
99
|
+
require_relative File.join('objects', 'config_file')
|
100
|
+
Impressbox::Objects::ConfigFile.new @config.file
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
# -----------------------------------------------------------------------------
|
5
|
+
# This is file that was automatically generated with vagrant-impressbox plugin.
|
6
|
+
# We recommend do not edit it or at least do not use again impressbox command
|
7
|
+
# because this file will be overwritten in that case. If you want to set some
|
8
|
+
# special values for vagrant box, use config.yaml instead.
|
9
|
+
# -----------------------------------------------------------------------------
|
10
|
+
# Last generation date: {{info.last_update}}
|
11
|
+
# More information: {{info.website_url}}
|
12
|
+
# -----------------------------------------------------------------------------
|
13
|
+
|
14
|
+
# Installs required plugins if not installed
|
15
|
+
if ARGV.include?('up')
|
16
|
+
needed_reboot = false
|
17
|
+
[
|
18
|
+
'vagrant-impressbox',
|
19
|
+
'vagrant-hostmanager'
|
20
|
+
].each do |plugin|
|
21
|
+
unless Vagrant.has_plugin?(plugin)
|
22
|
+
system 'vagrant plugin install ' + plugin
|
23
|
+
needed_reboot = true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
if needed_reboot
|
27
|
+
system 'vagrant up'
|
28
|
+
exit true
|
29
|
+
end
|
30
|
+
needed_reboot = nil
|
31
|
+
end
|
32
|
+
|
33
|
+
# Configure vagrant
|
34
|
+
Vagrant.configure(2) do |config|
|
35
|
+
config.vm.box = '{{box}}'
|
36
|
+
config.vm.provision :impressbox
|
37
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# This file is to easy configure development enviroment
|
2
|
+
# Last automatic file update/creation was on {{info.last_update}}
|
3
|
+
# More info could be found at {{info.website_url}}
|
4
|
+
|
5
|
+
# ---------------------------------------------------------------------------------------
|
6
|
+
# IP of this virtual machine.
|
7
|
+
# ---------------------------------------------------------------------------------------
|
8
|
+
ip: {{ip}}
|
9
|
+
|
10
|
+
# ---------------------------------------------------------------------------------------
|
11
|
+
# You can type this hostname in your browser and launch the website
|
12
|
+
# ---------------------------------------------------------------------------------------
|
13
|
+
hostname:
|
14
|
+
{{#hostname}} - {{.}}
|
15
|
+
{{/hostname}}
|
16
|
+
|
17
|
+
# ---------------------------------------------------------------------------------------
|
18
|
+
# This is name how is box is listed in virtual machine
|
19
|
+
# ---------------------------------------------------------------------------------------
|
20
|
+
name: {{name}}
|
21
|
+
|
22
|
+
# ---------------------------------------------------------------------------------------
|
23
|
+
# SSH Keys. If you use GitHub client, you can just simply change "id_rsa" to "github_rsa"
|
24
|
+
# and everything should work without any extended configuration.
|
25
|
+
#
|
26
|
+
# If you remove lines these lines below, code in vagrantfile will try to autodetect
|
27
|
+
# where your keys are located. If it fails, it raise an error.
|
28
|
+
# ---------------------------------------------------------------------------------------
|
29
|
+
#keys:
|
30
|
+
# private: ~/.ssh/id_rsa
|
31
|
+
# public: ~/.ssh/id_rsa.pub
|
32
|
+
|
33
|
+
# ---------------------------------------------------------------------------------------
|
34
|
+
# Defines ports forwarted list
|
35
|
+
# ---------------------------------------------------------------------------------------
|
36
|
+
ports:
|
37
|
+
{{# ports}}
|
38
|
+
- host: {{host}}
|
39
|
+
guest: {{guest}}
|
40
|
+
{{/ ports}}
|
41
|
+
|
42
|
+
# ---------------------------------------------------------------------------------------
|
43
|
+
# If you use HyperV provider than is recommended to set some samba configuration values
|
44
|
+
# below
|
45
|
+
# ---------------------------------------------------------------------------------------
|
46
|
+
smb:
|
47
|
+
ip: {{smb.ip}}
|
48
|
+
user: {{smb.user}}
|
49
|
+
pass: {{smb.pass}}
|
50
|
+
|
51
|
+
# ---------------------------------------------------------------------------------------
|
52
|
+
# How many CPUs should this box use? Default value is 1.
|
53
|
+
# ---------------------------------------------------------------------------------------
|
54
|
+
cpus: {{cpus}}
|
55
|
+
|
56
|
+
# ---------------------------------------------------------------------------------------
|
57
|
+
# How much RAM should this box have? This is a number in megabytes. Default value is 512.
|
58
|
+
# ---------------------------------------------------------------------------------------
|
59
|
+
memory: {{memory}}
|
60
|
+
|
61
|
+
# ---------------------------------------------------------------------------------------
|
62
|
+
# Do we need to check automatically for box updates? Default value is false
|
63
|
+
# ---------------------------------------------------------------------------------------
|
64
|
+
check_update: {{#check_update}}true{{/check_update}}{{^check_update}}false{{/check_update}}
|
65
|
+
|
66
|
+
# ---------------------------------------------------------------------------------------
|
67
|
+
# What command should execute vagrant exec command on host?
|
68
|
+
# ---------------------------------------------------------------------------------------
|
69
|
+
cmd: {{cmd}}
|
70
|
+
|
71
|
+
# ---------------------------------------------------------------------------------------
|
72
|
+
# What shell commands will be executed on provision?
|
73
|
+
# ---------------------------------------------------------------------------------------
|
74
|
+
provision: |
|
75
|
+
{{#provision}} {{.}}
|
76
|
+
{{/provision}}
|