wordpress-deploy 1.0.0.alpha1 → 1.0.0.alpha2
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/.gitignore +26 -1
- data/.rspec +1 -0
- data/.rvmrc +48 -0
- data/.travis.yml +4 -0
- data/Gemfile +2 -5
- data/Gemfile.lock +40 -28
- data/Guardfile +24 -0
- data/README.md +22 -7
- data/bin/wp-deploy +1 -4
- data/lib/wordpress_deploy.rb +22 -48
- data/lib/wordpress_deploy/cli/helpers.rb +27 -14
- data/lib/wordpress_deploy/cli/utility.rb +86 -37
- data/lib/wordpress_deploy/database/mysql.rb +22 -136
- data/lib/wordpress_deploy/environment.rb +68 -0
- data/lib/wordpress_deploy/errors.rb +54 -0
- data/lib/wordpress_deploy/logger.rb +28 -50
- data/lib/wordpress_deploy/transfer_protocols/ftp.rb +305 -0
- data/lib/wordpress_deploy/version.rb +1 -1
- data/lib/wordpress_deploy/wordpress/configuration.rb +196 -0
- data/spec/data/ftp.yml +4 -0
- data/spec/data/wp-config-sample.php +90 -0
- data/spec/data/wp-config.yml +128 -0
- data/spec/database/mysql_spec.rb +93 -0
- data/spec/environment_spec.rb +35 -0
- data/spec/spec_helper.rb +36 -1
- data/spec/transfer_protocols/ftp_spec.rb +193 -0
- data/spec/wordpress/configuration_spec.rb +202 -0
- data/wordpress_deploy.gemspec +13 -10
- metadata +63 -47
- data/lib/wordpress_deploy/config.rb +0 -68
- data/lib/wordpress_deploy/database/base.rb +0 -53
- data/lib/wordpress_deploy/pipeline.rb +0 -110
- data/lib/wordpress_deploy/storage/base.rb +0 -99
- data/lib/wordpress_deploy/storage/ftp.rb +0 -133
- data/lib/wordpress_deploy/storage/local.rb +0 -82
- data/lib/wordpress_deploy/storage/scp.rb +0 -99
- data/lib/wordpress_deploy/storage/sftp.rb +0 -108
- data/spec/config_spec.rb +0 -16
@@ -1,82 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module WordpressDeploy
|
4
|
-
module Storage
|
5
|
-
class Local < Base
|
6
|
-
|
7
|
-
##
|
8
|
-
# Path where the backup will be stored.
|
9
|
-
attr_accessor :path
|
10
|
-
|
11
|
-
##
|
12
|
-
# Creates a new instance of the storage object
|
13
|
-
def initialize(model, storage_id = nil, &block)
|
14
|
-
super(model, storage_id)
|
15
|
-
|
16
|
-
@path ||= File.join(
|
17
|
-
File.expand_path(ENV['HOME'] || ''),
|
18
|
-
'backups'
|
19
|
-
)
|
20
|
-
|
21
|
-
instance_eval(&block) if block_given?
|
22
|
-
|
23
|
-
@path = File.expand_path(@path)
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
##
|
29
|
-
# Transfers the archived file to the specified path
|
30
|
-
def transfer!
|
31
|
-
remote_path = remote_path_for(@package)
|
32
|
-
FileUtils.mkdir_p(remote_path)
|
33
|
-
|
34
|
-
files_to_transfer_for(@package) do |local_file, remote_file|
|
35
|
-
Logger.message "#{storage_name} started transferring '#{ local_file }'."
|
36
|
-
|
37
|
-
src_path = File.join(local_path, local_file)
|
38
|
-
dst_path = File.join(remote_path, remote_file)
|
39
|
-
FileUtils.send(transfer_method, src_path, dst_path)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
##
|
44
|
-
# Removes the transferred archive file(s) from the storage location.
|
45
|
-
# Any error raised will be rescued during Cycling
|
46
|
-
# and a warning will be logged, containing the error message.
|
47
|
-
def remove!(package)
|
48
|
-
remote_path = remote_path_for(package)
|
49
|
-
|
50
|
-
messages = []
|
51
|
-
transferred_files_for(package) do |local_file, remote_file|
|
52
|
-
messages << "#{storage_name} started removing '#{ local_file }'."
|
53
|
-
end
|
54
|
-
Logger.message messages.join("\n")
|
55
|
-
|
56
|
-
FileUtils.rm_r(remote_path)
|
57
|
-
end
|
58
|
-
|
59
|
-
##
|
60
|
-
# Set and return the transfer method.
|
61
|
-
# If this Local Storage is not the last Storage for the Model,
|
62
|
-
# force the transfer to use a *copy* operation and issue a warning.
|
63
|
-
def transfer_method
|
64
|
-
return @transfer_method if @transfer_method
|
65
|
-
|
66
|
-
if self == @model.storages.last
|
67
|
-
@transfer_method = :mv
|
68
|
-
else
|
69
|
-
Logger.warn Errors::Storage::Local::TransferError.new(<<-EOS)
|
70
|
-
Local File Copy Warning!
|
71
|
-
The final backup file(s) for '#{@model.label}' (#{@model.trigger})
|
72
|
-
will be *copied* to '#{remote_path_for(@package)}'
|
73
|
-
To avoid this, when using more than one Storage, the 'Local' Storage
|
74
|
-
should be added *last* so the files may be *moved* to their destination.
|
75
|
-
EOS
|
76
|
-
@transfer_method = :cp
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
@@ -1,99 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
##
|
4
|
-
# Only load the Net::SSH and Net::SCP library/gems
|
5
|
-
# when the WordpressDeploy::Storage::SCP class is loaded
|
6
|
-
WordpressDeploy::Dependency.load('net-ssh')
|
7
|
-
WordpressDeploy::Dependency.load('net-scp')
|
8
|
-
|
9
|
-
module WordpressDeploy
|
10
|
-
module Storage
|
11
|
-
class SCP < Base
|
12
|
-
|
13
|
-
##
|
14
|
-
# Server credentials
|
15
|
-
attr_accessor :username, :password
|
16
|
-
|
17
|
-
##
|
18
|
-
# Server IP Address and SCP port
|
19
|
-
attr_accessor :ip, :port
|
20
|
-
|
21
|
-
##
|
22
|
-
# Path to store backups to
|
23
|
-
attr_accessor :path
|
24
|
-
|
25
|
-
##
|
26
|
-
# Creates a new instance of the storage object
|
27
|
-
def initialize(model, storage_id = nil, &block)
|
28
|
-
super(model, storage_id)
|
29
|
-
|
30
|
-
@port ||= 22
|
31
|
-
@path ||= 'backups'
|
32
|
-
|
33
|
-
instance_eval(&block) if block_given?
|
34
|
-
|
35
|
-
@path = path.sub(/^\~\//, '')
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
##
|
41
|
-
# Establishes a connection to the remote server
|
42
|
-
# and yields the Net::SSH connection.
|
43
|
-
# Net::SCP will use this connection to transfer backups
|
44
|
-
def connection
|
45
|
-
Net::SSH.start(
|
46
|
-
ip, username, :password => password, :port => port
|
47
|
-
) {|ssh| yield ssh }
|
48
|
-
end
|
49
|
-
|
50
|
-
##
|
51
|
-
# Transfers the archived file to the specified remote server
|
52
|
-
def transfer!
|
53
|
-
remote_path = remote_path_for(@package)
|
54
|
-
|
55
|
-
connection do |ssh|
|
56
|
-
ssh.exec!("mkdir -p '#{ remote_path }'")
|
57
|
-
|
58
|
-
files_to_transfer_for(@package) do |local_file, remote_file|
|
59
|
-
Logger.message "#{storage_name} started transferring " +
|
60
|
-
"'#{local_file}' to '#{ip}'."
|
61
|
-
|
62
|
-
ssh.scp.upload!(
|
63
|
-
File.join(local_path, local_file),
|
64
|
-
File.join(remote_path, remote_file)
|
65
|
-
)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
##
|
71
|
-
# Removes the transferred archive file(s) from the storage location.
|
72
|
-
# Any error raised will be rescued during Cycling
|
73
|
-
# and a warning will be logged, containing the error message.
|
74
|
-
def remove!(package)
|
75
|
-
remote_path = remote_path_for(package)
|
76
|
-
|
77
|
-
messages = []
|
78
|
-
transferred_files_for(package) do |local_file, remote_file|
|
79
|
-
messages << "#{storage_name} started removing " +
|
80
|
-
"'#{local_file}' from '#{ip}'."
|
81
|
-
end
|
82
|
-
Logger.message messages.join("\n")
|
83
|
-
|
84
|
-
errors = []
|
85
|
-
connection do |ssh|
|
86
|
-
ssh.exec!("rm -r '#{remote_path}'") do |ch, stream, data|
|
87
|
-
errors << data if stream == :stderr
|
88
|
-
end
|
89
|
-
end
|
90
|
-
unless errors.empty?
|
91
|
-
raise Errors::Storage::SCP::SSHError,
|
92
|
-
"Net::SSH reported the following errors:\n" +
|
93
|
-
errors.join("\n")
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
@@ -1,108 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
##
|
4
|
-
# Only load the Net::SFTP library/gem when the WordpressDeploy::Storage::SFTP class is loaded
|
5
|
-
WordpressDeploy::Dependency.load('net-ssh')
|
6
|
-
WordpressDeploy::Dependency.load('net-sftp')
|
7
|
-
|
8
|
-
module WordpressDeploy
|
9
|
-
module Storage
|
10
|
-
class SFTP < Base
|
11
|
-
|
12
|
-
##
|
13
|
-
# Server credentials
|
14
|
-
attr_accessor :username, :password
|
15
|
-
|
16
|
-
##
|
17
|
-
# Server IP Address and SFTP port
|
18
|
-
attr_accessor :ip, :port
|
19
|
-
|
20
|
-
##
|
21
|
-
# Path to store backups to
|
22
|
-
attr_accessor :path
|
23
|
-
|
24
|
-
##
|
25
|
-
# Creates a new instance of the storage object
|
26
|
-
def initialize(model, storage_id = nil, &block)
|
27
|
-
super(model, storage_id)
|
28
|
-
|
29
|
-
@port ||= 22
|
30
|
-
@path ||= 'backups'
|
31
|
-
|
32
|
-
instance_eval(&block) if block_given?
|
33
|
-
|
34
|
-
@path = path.sub(/^\~\//, '')
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
##
|
40
|
-
# Establishes a connection to the remote server
|
41
|
-
def connection
|
42
|
-
Net::SFTP.start(
|
43
|
-
ip, username,
|
44
|
-
:password => password,
|
45
|
-
:port => port
|
46
|
-
) {|sftp| yield sftp }
|
47
|
-
end
|
48
|
-
|
49
|
-
##
|
50
|
-
# Transfers the archived file to the specified remote server
|
51
|
-
def transfer!
|
52
|
-
remote_path = remote_path_for(@package)
|
53
|
-
|
54
|
-
connection do |sftp|
|
55
|
-
create_remote_path(remote_path, sftp)
|
56
|
-
|
57
|
-
files_to_transfer_for(@package) do |local_file, remote_file|
|
58
|
-
Logger.message "#{storage_name} started transferring " +
|
59
|
-
"'#{ local_file }' to '#{ ip }'."
|
60
|
-
|
61
|
-
sftp.upload!(
|
62
|
-
File.join(local_path, local_file),
|
63
|
-
File.join(remote_path, remote_file)
|
64
|
-
)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
##
|
70
|
-
# Removes the transferred archive file(s) from the storage location.
|
71
|
-
# Any error raised will be rescued during Cycling
|
72
|
-
# and a warning will be logged, containing the error message.
|
73
|
-
def remove!(package)
|
74
|
-
remote_path = remote_path_for(package)
|
75
|
-
|
76
|
-
connection do |sftp|
|
77
|
-
transferred_files_for(package) do |local_file, remote_file|
|
78
|
-
Logger.message "#{storage_name} started removing " +
|
79
|
-
"'#{ local_file }' from '#{ ip }'."
|
80
|
-
|
81
|
-
sftp.remove!(File.join(remote_path, remote_file))
|
82
|
-
end
|
83
|
-
|
84
|
-
sftp.rmdir!(remote_path)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
##
|
89
|
-
# Creates (if they don't exist yet) all the directories on the remote
|
90
|
-
# server in order to upload the backup file. Net::SFTP does not support
|
91
|
-
# paths to directories that don't yet exist when creating new
|
92
|
-
# directories. Instead, we split the parts up in to an array (for each
|
93
|
-
# '/') and loop through that to create the directories one by one.
|
94
|
-
# Net::SFTP raises an exception when the directory it's trying to create
|
95
|
-
# already exists, so we have rescue it
|
96
|
-
def create_remote_path(remote_path, sftp)
|
97
|
-
path_parts = Array.new
|
98
|
-
remote_path.split('/').each do |path_part|
|
99
|
-
path_parts << path_part
|
100
|
-
begin
|
101
|
-
sftp.mkdir!(path_parts.join('/'))
|
102
|
-
rescue Net::SFTP::StatusException; end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
data/spec/config_spec.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe WordpressDeploy::Config do
|
4
|
-
it { should respond_to :env }
|
5
|
-
it { should respond_to :environment }
|
6
|
-
it { should respond_to :base_dir }
|
7
|
-
it { should respond_to :config_dir }
|
8
|
-
it { should respond_to :sites_dir }
|
9
|
-
it { should respond_to :ftp_config }
|
10
|
-
it { should respond_to :wp_config }
|
11
|
-
it { should respond_to :wp_config_sample }
|
12
|
-
it { should respond_to :wp_config_output }
|
13
|
-
it { should respond_to :environment }
|
14
|
-
it { WordpressDeploy::Config.env.should == "production" }
|
15
|
-
it { WordpressDeploy::Config.env.should eq WordpressDeploy::Config.environment }
|
16
|
-
end
|