vagrant-cloner 2.0.0 → 2.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.
- data.tar.gz.sig +0 -0
- data/Gemfile +5 -0
- data/README.md +1 -0
- data/lib/vagrant-cloner/base_cloner.rb +6 -1
- data/lib/vagrant-cloner/cloners/mysql.rb +46 -14
- data/spec/cloners/mysql_spec.rb +41 -0
- data/spec/spec_helper.rb +0 -0
- data/vagrant-cloner.gemspec +2 -2
- metadata +7 -3
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -43,6 +43,7 @@ The following keys are valid:
|
|
43
43
|
- **enabled** - Required: Boolean whether to use this cloner or not. Defaults to false.
|
44
44
|
- **run_order** - Suggested: Integer value that dictates which order cloners run in. Lower orders run first. Defaults to 1000.
|
45
45
|
- **mysql**
|
46
|
+
- **use_ssh** - If false, will attempt to connect to the remote MySQL server at the `remote_host` using the `remote_user` and `remote_password` settings. Elsewise, will SSH into the remote host, export the database, download it locally, upload it to the VM, and install it that way.
|
46
47
|
- **remote_host** - String containing the remote server's FQDN.
|
47
48
|
- **remote_user** - Username to connect to remote server.
|
48
49
|
- **remote_password** - Optional: Password to connect to remote server. (Can be ignored if using publickey auth.)
|
@@ -63,9 +63,14 @@ module VagrantCloner
|
|
63
63
|
# Wrap debugging options.
|
64
64
|
%w(info warn error success).each do |meth|
|
65
65
|
define_method(meth) do |message|
|
66
|
-
|
66
|
+
machine.env.ui.send(meth.to_sym, message)
|
67
67
|
end
|
68
68
|
protected meth.to_sym
|
69
69
|
end
|
70
|
+
|
71
|
+
def debug(message)
|
72
|
+
machine.env.ui.info message
|
73
|
+
end
|
74
|
+
protected :debug
|
70
75
|
end
|
71
76
|
end
|
@@ -3,7 +3,7 @@ module VagrantCloner
|
|
3
3
|
class MysqlCloner < ::VagrantCloner::BaseCloner
|
4
4
|
|
5
5
|
attr_accessor :remote_host, :remote_user, :remote_password,
|
6
|
-
:remote_db_user, :remote_db_password,
|
6
|
+
:remote_db_user, :remote_db_password, :use_ssh,
|
7
7
|
:vm_db_user, :vm_db_password,
|
8
8
|
:databases_to_clone,
|
9
9
|
:remote_backup_path, :local_backup_path, :vm_backup_path, :backup_file,
|
@@ -16,12 +16,11 @@ module VagrantCloner
|
|
16
16
|
def validate(machine, errors)
|
17
17
|
failures = []
|
18
18
|
failures.push "Must specify a remote user and host." unless remote_user && remote_host
|
19
|
-
failures.push "Must specify a remote database user and password." unless remote_db_user && remote_db_password
|
19
|
+
failures.push "Must specify a remote database user and password." unless (remote_db_user && remote_db_password) || use_ssh
|
20
20
|
unless warned_about_password or remote_password
|
21
21
|
machine.env.ui.warn "You haven't specified a remote password. Pulling down MySQL databases may fail unless you have proper publickey authentication enabled."
|
22
22
|
@warned_about_password = true
|
23
23
|
end
|
24
|
-
|
25
24
|
errors.merge(name.to_sym => failures) if failures.any?
|
26
25
|
end
|
27
26
|
|
@@ -54,6 +53,11 @@ module VagrantCloner
|
|
54
53
|
end
|
55
54
|
alias_method :disable_cleanup?, :disable_cleanup
|
56
55
|
|
56
|
+
def use_ssh
|
57
|
+
@use_ssh.nil? ? true : @use_ssh
|
58
|
+
end
|
59
|
+
alias_method :use_ssh?, :use_ssh
|
60
|
+
|
57
61
|
|
58
62
|
def extract_relevant_options
|
59
63
|
@enabled = options.enabled
|
@@ -63,6 +67,8 @@ module VagrantCloner
|
|
63
67
|
@remote_db_user = options.remote_db_user
|
64
68
|
@remote_db_password = options.remote_db_password
|
65
69
|
|
70
|
+
@use_ssh = options.use_ssh
|
71
|
+
|
66
72
|
@databases_to_clone = options.databases_to_clone
|
67
73
|
|
68
74
|
@vm_db_user = options.vm_db_user
|
@@ -75,9 +81,9 @@ module VagrantCloner
|
|
75
81
|
@vm_backup_path = options.vm_backup_path
|
76
82
|
@backup_file = options.backup_file || "mysql-backup-#{datestring}.sql"
|
77
83
|
|
78
|
-
@remote_backup_location = File.join(
|
79
|
-
@local_backup_location = File.join(
|
80
|
-
@vm_backup_location = File.join(
|
84
|
+
@remote_backup_location = File.join(remote_backup_path, @backup_file)
|
85
|
+
@local_backup_location = File.join(local_backup_path, @backup_file)
|
86
|
+
@vm_backup_location = File.join(vm_backup_path, @backup_file)
|
81
87
|
end
|
82
88
|
|
83
89
|
def mysql_database_flag
|
@@ -88,16 +94,39 @@ module VagrantCloner
|
|
88
94
|
end
|
89
95
|
end
|
90
96
|
|
97
|
+
# We don't want to output -p if password is nil, because that will prompt
|
98
|
+
# for a password.
|
99
|
+
def mysql_password_flag(password)
|
100
|
+
if password.nil? || password.empty?
|
101
|
+
""
|
102
|
+
else
|
103
|
+
%Q{ -p"#{password}"}
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
91
107
|
def call
|
92
108
|
extract_relevant_options
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
109
|
+
if use_ssh?
|
110
|
+
dump_remote_database
|
111
|
+
download_remote_database
|
112
|
+
import_database
|
113
|
+
clean_up
|
114
|
+
else
|
115
|
+
remote_dump_and_pipe
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def remote_dump_and_pipe
|
120
|
+
info "Doing remote mysqldump..."
|
121
|
+
command = %Q{mysqldump --verbose -h #{@remote_host} -u"#{@remote_user}"#{mysql_password_flag(@remote_password)} #{mysql_database_flag} | mysql -u"#{@vm_db_user}"#{mysql_password_flag(@vm_db_password)}}
|
122
|
+
vm.tap do |host|
|
123
|
+
vm.execute command
|
124
|
+
end
|
125
|
+
info "All done!"
|
97
126
|
end
|
98
127
|
|
99
128
|
def dump_remote_database
|
100
|
-
command =
|
129
|
+
command = %Q{mysqldump -u"#{@remote_db_user}"#{mysql_password_flag(@remote_db_password)} #{mysql_database_flag} > #{@remote_backup_location}}
|
101
130
|
ssh(*remote_credentials) {|s| s.exec! command }
|
102
131
|
info "Finished dumping database!"
|
103
132
|
end
|
@@ -110,7 +139,8 @@ module VagrantCloner
|
|
110
139
|
def import_database
|
111
140
|
vm.tap do |host|
|
112
141
|
host.upload @local_backup_location, @vm_backup_location
|
113
|
-
|
142
|
+
command = %Q{mysql -u"#{@vm_db_user}"#{mysql_password_flag(@vm_db_password)} < #{@vm_backup_location}}
|
143
|
+
host.execute command
|
114
144
|
end
|
115
145
|
info "Done loading database."
|
116
146
|
end
|
@@ -120,11 +150,13 @@ module VagrantCloner
|
|
120
150
|
ssh(*remote_credentials) {|s| s.exec! "rm #{@remote_backup_location}" } and info "Removed remote backup file."
|
121
151
|
system "rm #{@local_backup_location}" and info "Removed local backup file."
|
122
152
|
vm.execute "rm #{@vm_backup_location}" and info "Removed vm backup file."
|
123
|
-
|
153
|
+
success "Done!"
|
124
154
|
end
|
125
155
|
end
|
126
156
|
end
|
127
157
|
end
|
128
158
|
end
|
129
159
|
|
130
|
-
VagrantCloner::ClonerContainer
|
160
|
+
if defined? VagrantCloner::ClonerContainer
|
161
|
+
VagrantCloner::ClonerContainer.instance.send("#{VagrantCloner::Cloners::MysqlCloner.instance.name}=".to_sym, VagrantCloner::Cloners::MysqlCloner.instance)
|
162
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'pry'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
# Mock this
|
6
|
+
module VagrantCloner
|
7
|
+
class BaseCloner
|
8
|
+
def datestring; "2013-01-01"; end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'vagrant-cloner/cloners/mysql'
|
13
|
+
|
14
|
+
module VagrantCloner
|
15
|
+
module Cloners
|
16
|
+
describe MysqlCloner do
|
17
|
+
describe "#extract_relevant_options" do
|
18
|
+
describe "when missing keys" do
|
19
|
+
before do
|
20
|
+
subject.stub!(:options).and_return(OpenStruct.new({:remote_db_password => ''}))
|
21
|
+
subject.extract_relevant_options
|
22
|
+
end
|
23
|
+
|
24
|
+
its(:remote_db_password) { should be_empty }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#mysql_password_flag" do
|
29
|
+
it "produces nothing if password is nil or empty" do
|
30
|
+
result = subject.mysql_password_flag("")
|
31
|
+
result.should be_empty
|
32
|
+
end
|
33
|
+
|
34
|
+
it "outputs the flag if password is present" do
|
35
|
+
result = subject.mysql_password_flag("test")
|
36
|
+
result.should == %Q{ -p"test"}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/spec_helper.rb
ADDED
File without changes
|
data/vagrant-cloner.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
|
5
|
-
version = '2.
|
5
|
+
version = '2.1.0'
|
6
6
|
|
7
7
|
Gem::Specification.new do |gem|
|
8
8
|
gem.name = "vagrant-cloner"
|
@@ -14,8 +14,8 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.homepage = "https://github.com/rjocoleman/vagrant-cloner/"
|
15
15
|
|
16
16
|
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.test_files = gem.files.grep(%r{^(spec)/})
|
17
18
|
# gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
-
# gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
21
|
gem.signing_key = '/Users/rjocoleman/.gemcert/gem-private_key.pem'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-cloner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -39,7 +39,7 @@ cert_chain:
|
|
39
39
|
ME9XOXNmTwoxbjFNamRBaGZra1VWeHJiamZHT0VqcFRlZVEzckFjSGtVTkFX
|
40
40
|
TkxlSWVIKzJ6OHNrYTZ6QUhsNDFhVT0KLS0tLS1FTkQgQ0VSVElGSUNBVEUt
|
41
41
|
LS0tLQo=
|
42
|
-
date: 2013-03-
|
42
|
+
date: 2013-03-26 00:00:00.000000000 Z
|
43
43
|
dependencies: []
|
44
44
|
description: Copy production resources down to your new VM.
|
45
45
|
email:
|
@@ -65,6 +65,8 @@ files:
|
|
65
65
|
- lib/vagrant-cloner/plugin.rb
|
66
66
|
- lib/vagrant-cloner/provisioner.rb
|
67
67
|
- lib/vagrant_init.rb
|
68
|
+
- spec/cloners/mysql_spec.rb
|
69
|
+
- spec/spec_helper.rb
|
68
70
|
- vagrant-cloner.gemspec
|
69
71
|
homepage: https://github.com/rjocoleman/vagrant-cloner/
|
70
72
|
licenses: []
|
@@ -90,4 +92,6 @@ rubygems_version: 1.8.24
|
|
90
92
|
signing_key:
|
91
93
|
specification_version: 3
|
92
94
|
summary: Copy production resources down to your new VM.
|
93
|
-
test_files:
|
95
|
+
test_files:
|
96
|
+
- spec/cloners/mysql_spec.rb
|
97
|
+
- spec/spec_helper.rb
|
metadata.gz.sig
CHANGED
Binary file
|