danarchy_deploy 0.1.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/Gemfile.lock +9 -20
- data/README.md +10 -9
- data/Rakefile +0 -4
- data/bin/danarchy_deploy +24 -10
- data/danarchy_deploy.gemspec +4 -3
- data/lib/danarchy_deploy.rb +186 -55
- data/lib/danarchy_deploy/applicator.rb +39 -0
- data/lib/danarchy_deploy/applicator/nginx.rb +86 -0
- data/lib/danarchy_deploy/applicator/phpfpm.rb +84 -0
- data/lib/danarchy_deploy/applicator/redmine.rb +40 -0
- data/lib/danarchy_deploy/applicator/ssl.rb +14 -0
- data/lib/danarchy_deploy/applicator/wordpress.rb +146 -0
- data/lib/danarchy_deploy/applicator/wordpress/wpcli.rb +67 -0
- data/lib/danarchy_deploy/applicator/wordpress/wpcli_install.sh +36 -0
- data/lib/danarchy_deploy/applicator/wordpress/wpconfig.rb +49 -0
- data/lib/danarchy_deploy/archiver.rb +9 -7
- data/lib/danarchy_deploy/archiver/svn.rb +17 -0
- data/lib/danarchy_deploy/hash_deep_merge.rb +9 -0
- data/lib/danarchy_deploy/helpers.rb +42 -10
- data/lib/danarchy_deploy/installer.rb +2 -2
- data/lib/danarchy_deploy/services.rb +12 -25
- data/lib/danarchy_deploy/services/init.rb +52 -0
- data/lib/danarchy_deploy/services/init/openrc.rb +72 -0
- data/lib/danarchy_deploy/services/init/systemd.rb +69 -0
- data/lib/danarchy_deploy/services/mongodb.rb +162 -0
- data/lib/danarchy_deploy/services/mysql.rb +58 -0
- data/lib/danarchy_deploy/services/mysql/new_server.rb +72 -0
- data/lib/danarchy_deploy/services/mysql/privileges.rb +35 -0
- data/lib/danarchy_deploy/system.rb +86 -0
- data/lib/danarchy_deploy/system/centos.rb +17 -0
- data/lib/danarchy_deploy/system/debian.rb +61 -0
- data/lib/danarchy_deploy/system/gentoo.rb +66 -0
- data/lib/danarchy_deploy/system/opensuse.rb +22 -0
- data/lib/danarchy_deploy/templater.rb +53 -13
- data/lib/danarchy_deploy/users.rb +29 -19
- data/lib/danarchy_deploy/version.rb +1 -1
- metadata +34 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7282c6d5655d36a9f4fe2685df951a4faf1abdc1df283d997b74d56ce11cfc9e
|
4
|
+
data.tar.gz: 65ed14f1a804481aa53358439db88eed24654770ef253223ff607caf8b6e608d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92582f2b1ae3b019c0add4a6eacad943929cf499f5c572bc01b7cd84a018366edb5a4f78b2638ae905688960f88003a5827fe059713a180f373f853cd36b62b3
|
7
|
+
data.tar.gz: 8c23cd79d331bc93519eefc7e8e862534ce2bc83bd6a260b3bdd29437f4a6b965b87dc2f3f4ce34da39442a29bb643ea628f436bfef235f3b88bc794a33f405a
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,37 +1,26 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
danarchy_deploy (0.
|
4
|
+
danarchy_deploy (0.2.0)
|
5
5
|
danarchy_couchdb (~> 0.1.0)
|
6
|
+
mongo (~> 2.13)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
11
|
+
bson (4.10.1)
|
10
12
|
danarchy_couchdb (0.1.2)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
rspec-core (~> 3.7.0)
|
15
|
-
rspec-expectations (~> 3.7.0)
|
16
|
-
rspec-mocks (~> 3.7.0)
|
17
|
-
rspec-core (3.7.1)
|
18
|
-
rspec-support (~> 3.7.0)
|
19
|
-
rspec-expectations (3.7.0)
|
20
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
-
rspec-support (~> 3.7.0)
|
22
|
-
rspec-mocks (3.7.0)
|
23
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
-
rspec-support (~> 3.7.0)
|
25
|
-
rspec-support (3.7.1)
|
13
|
+
mongo (2.13.1)
|
14
|
+
bson (>= 4.8.2, < 5.0.0)
|
15
|
+
rake (13.0.1)
|
26
16
|
|
27
17
|
PLATFORMS
|
28
18
|
ruby
|
29
19
|
|
30
20
|
DEPENDENCIES
|
31
|
-
bundler (~> 1
|
21
|
+
bundler (~> 2.1)
|
32
22
|
danarchy_deploy!
|
33
|
-
rake (~>
|
34
|
-
rspec (~> 3.0)
|
23
|
+
rake (~> 13.0)
|
35
24
|
|
36
25
|
BUNDLED WITH
|
37
|
-
1.
|
26
|
+
2.1.4
|
data/README.md
CHANGED
@@ -19,28 +19,29 @@ Or install it yourself as:
|
|
19
19
|
|
20
20
|
$ gem install danarchy_deploy
|
21
21
|
|
22
|
-
!! Since dAnarchy Deploy takes several actions that require root/sudo access, I install the gem with sudo as any remote deployment will on the target host:
|
23
22
|
|
24
|
-
|
23
|
+
If you will be running dAnarchy Deploy as a LocalDeploy, it will require root/sudo access, so install the gem with sudo.
|
24
|
+
This is RemoteDeploy's process for running LocalDeploy on target hosts (DanarchyDeploy::RemoteDeploy#gem_install [L99-L109]):
|
25
|
+
|
26
|
+
$ sudo gem install danarchy_deploy
|
25
27
|
|
26
28
|
|
27
29
|
## Usage
|
28
30
|
|
29
31
|
dAnarchy Deploy usage info can be read with -h/--help:
|
30
32
|
```ruby
|
31
|
-
|
32
|
-
Usage: sudo
|
33
|
+
~$ danarchy_deploy -h
|
34
|
+
Usage: sudo bin/danarchy_deploy (local|remote) --json /path/to/deployment.json [options]
|
33
35
|
-j, --json=file Read configuration from JSON file.
|
34
36
|
-y, --yaml=file Read configuration from YAML file.
|
35
37
|
-p, --pretend Pretend run: Don't take any action.
|
36
38
|
-f, --first-run First Run: Run as a first run causing services to run all init actions.
|
37
39
|
-d, --deploy-dir Deployment directory. Defaults to '/danarchy/deploy'.
|
38
|
-
--
|
39
|
-
--
|
40
|
+
--dev-gem Build dAnarchy_deploy gem locally and push to target host in RemoteDeploy.
|
41
|
+
--ssh-verbose Verbose SSH stdout/stderr output.
|
42
|
+
--vars-verbose Verbose template variable output.
|
43
|
+
--version Print bin/danarchy_deploy version.
|
40
44
|
-h, --help Print this help info.
|
41
|
-
|
42
|
-
DanarchyDeploy: 0.1.0
|
43
|
-
Exiting! Must be run with sudo!
|
44
45
|
```
|
45
46
|
|
46
47
|
More documentation incoming...
|
data/Rakefile
CHANGED
data/bin/danarchy_deploy
CHANGED
@@ -5,12 +5,13 @@ require 'date'
|
|
5
5
|
require 'optparse'
|
6
6
|
|
7
7
|
deployment = nil
|
8
|
-
options = { couchdb: "
|
8
|
+
options = { couchdb: "#{ENV['HOME']}/.danarchy/danarchy_deploy/danarchy_deploy.json",
|
9
9
|
deploy_dir: '/danarchy/deploy',
|
10
10
|
deploy_file: nil,
|
11
|
+
first_run: false,
|
11
12
|
pretend: false,
|
12
13
|
ssh_verbose: false,
|
13
|
-
|
14
|
+
vars_verbose: false }
|
14
15
|
|
15
16
|
ARGV.push('--help') if ARGV.empty?
|
16
17
|
optparse = OptionParser.new do |opts|
|
@@ -32,34 +33,44 @@ optparse = OptionParser.new do |opts|
|
|
32
33
|
options[:pretend] = true
|
33
34
|
end
|
34
35
|
|
35
|
-
opts.on('-f', '--first-run', 'First Run: Run as a first run causing services to run all init actions.') do |val|
|
36
|
-
options[:first_run] = true
|
37
|
-
end
|
38
|
-
|
39
36
|
opts.on('-d', '--deploy-dir', "Deployment directory. Defaults to '/danarchy/deploy'.") do |val|
|
40
37
|
options[:deploy_dir] = val.gsub(/\/$/, '')
|
41
38
|
end
|
42
39
|
|
40
|
+
opts.on('--dev-gem', 'Build dAnarchy_deploy gem locally and push to target host in RemoteDeploy.') do |val|
|
41
|
+
options[:dev_gem] = true
|
42
|
+
end
|
43
|
+
|
44
|
+
opts.on('-f', '--first-run', 'First Run: Run as a first run causing services to run all init actions.') do |val|
|
45
|
+
options[:first_run] = true
|
46
|
+
end
|
47
|
+
|
43
48
|
opts.on('--ssh-verbose', "Verbose SSH stdout/stderr output.") do |val|
|
44
49
|
options[:ssh_verbose] = true
|
45
50
|
end
|
46
51
|
|
52
|
+
opts.on('--vars-verbose', "Verbose template variables and diff output.") do |val|
|
53
|
+
options[:vars_verbose] = true
|
54
|
+
end
|
55
|
+
|
47
56
|
opts.on('--version', "Print #{$PROGRAM_NAME} version.") do |val|
|
48
57
|
puts "DanarchyDeploy: #{DanarchyDeploy::VERSION}"
|
58
|
+
exit 1
|
49
59
|
end
|
50
60
|
|
51
61
|
opts.on('-h', '--help', 'Print this help info.') do |val|
|
52
|
-
puts opts
|
62
|
+
puts opts
|
63
|
+
exit 1
|
53
64
|
end
|
54
65
|
end.parse!
|
55
66
|
|
56
67
|
puts "DanarchyDeploy: #{DanarchyDeploy::VERSION}"
|
57
|
-
abort('Exiting! Must be run with sudo!') if Process.uid != 0
|
58
|
-
|
59
68
|
location = ARGV.delete('remote') || ARGV.delete('local') || abort("ERROR: Need an option 'local' or 'remote' to know what to do!")
|
60
69
|
cdb_config = File.exist?(options[:couchdb]) ? JSON.parse(File.read(options[:couchdb]), symbolize_names: true)[:couchdb] : nil
|
61
70
|
cdb = DanarchyCouchDB::Connection.new(cdb_config) if cdb_config
|
62
71
|
|
72
|
+
# Error handling for !cdb_config && !input_file
|
73
|
+
|
63
74
|
if !deployment && !options[:deploy_file] && cdb
|
64
75
|
deployment_name = ARGV.shift
|
65
76
|
abort("Need a deployment name!") if !deployment_name
|
@@ -71,6 +82,8 @@ if !deployment && !options[:deploy_file] && cdb
|
|
71
82
|
options[:deploy_file] = "#{options[:deploy_dir]}/#{deployment_name}/#{deployment_name}.json"
|
72
83
|
puts "Temp JSON path: #{options[:deploy_file]}"
|
73
84
|
File.write(options[:deploy_file], deployment.to_json)
|
85
|
+
elsif !deployment && !cdb
|
86
|
+
abort('ERROR: No --json or --yaml file was provided, nor was a CouchDB connection found.')
|
74
87
|
end
|
75
88
|
|
76
89
|
if !deployment[:last_deploy] || deployment[:last_deploy].empty?
|
@@ -81,6 +94,7 @@ end
|
|
81
94
|
if location == 'remote'
|
82
95
|
deployment = DanarchyDeploy::RemoteDeploy.new(deployment, options)
|
83
96
|
elsif location == 'local'
|
97
|
+
abort('Exiting! Must be run with sudo!') if Process.uid != 0
|
84
98
|
puts "Deploying #{deployment[:hostname]} locally to #{`hostname`.chomp}."
|
85
99
|
|
86
100
|
if !options[:pretend]
|
@@ -97,7 +111,7 @@ elsif location == 'local'
|
|
97
111
|
deployment = DanarchyDeploy::LocalDeploy.new(deployment, options)
|
98
112
|
end
|
99
113
|
|
100
|
-
if deployment && cdb && !options[:pretend]
|
114
|
+
if deployment && cdb && !options[:pretend] && options[:deploy_file] !~ /.*(json|yaml)$/
|
101
115
|
puts "Saving deployment to CouchDB."
|
102
116
|
old_rev = cdb.get(cdb_config[:database], deployment_name)[:_rev]
|
103
117
|
save = cdb.put(cdb_config[:database], deployment[:_id], deployment)
|
data/danarchy_deploy.gemspec
CHANGED
@@ -30,7 +30,8 @@ Gem::Specification.new do |spec|
|
|
30
30
|
|
31
31
|
spec.add_dependency "danarchy_couchdb", "~> 0.1.0"
|
32
32
|
|
33
|
-
spec.add_development_dependency "bundler", "~> 1
|
34
|
-
spec.add_development_dependency "rake", "~>
|
35
|
-
|
33
|
+
spec.add_development_dependency "bundler", "~> 2.1"
|
34
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
35
|
+
|
36
|
+
spec.add_runtime_dependency "mongo", "~> 2.13"
|
36
37
|
end
|
data/lib/danarchy_deploy.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
-
require_relative 'danarchy_deploy/version'
|
2
|
-
|
3
1
|
module DanarchyDeploy
|
4
|
-
require_relative '
|
5
|
-
require_relative '
|
6
|
-
require_relative '
|
7
|
-
require_relative '
|
8
|
-
require_relative '
|
9
|
-
require_relative '
|
10
|
-
require_relative '
|
2
|
+
require_relative 'danarchy_deploy/applicator'
|
3
|
+
require_relative 'danarchy_deploy/archiver'
|
4
|
+
require_relative 'danarchy_deploy/groups'
|
5
|
+
require_relative 'danarchy_deploy/hash_deep_merge'
|
6
|
+
require_relative 'danarchy_deploy/helpers'
|
7
|
+
require_relative 'danarchy_deploy/services'
|
8
|
+
require_relative 'danarchy_deploy/system'
|
9
|
+
require_relative 'danarchy_deploy/templater'
|
10
|
+
require_relative 'danarchy_deploy/users'
|
11
|
+
require_relative 'danarchy_deploy/version'
|
11
12
|
|
12
13
|
class LocalDeploy
|
13
14
|
def self.new(deployment, options)
|
@@ -17,19 +18,23 @@ module DanarchyDeploy
|
|
17
18
|
puts 'Begining Deployment:'
|
18
19
|
printf("%12s %0s\n", 'Hostname:', deployment[:hostname])
|
19
20
|
printf("%12s %0s\n", 'OS:', deployment[:os])
|
20
|
-
printf("%12s %0s\n", 'Packages:', deployment[:packages].join(', '))
|
21
|
+
printf("%12s %0s\n", 'Packages:', deployment[:packages].join(', ')) if deployment[:packages]
|
21
22
|
|
22
|
-
deployment = DanarchyDeploy::
|
23
|
-
deployment = DanarchyDeploy::Services.new(deployment, options)
|
24
|
-
deployment = DanarchyDeploy::Groups.new(deployment, options)
|
25
|
-
deployment = DanarchyDeploy::Users.new(deployment, options)
|
26
|
-
deployment = DanarchyDeploy::Services.
|
23
|
+
deployment = DanarchyDeploy::System.new(deployment, options)
|
24
|
+
deployment = DanarchyDeploy::Services.new(deployment, options) if deployment[:services]
|
25
|
+
deployment = DanarchyDeploy::Groups.new(deployment, options) if deployment[:groups]
|
26
|
+
deployment = DanarchyDeploy::Users.new(deployment, options) if deployment[:users]
|
27
|
+
deployment = DanarchyDeploy::Services::Init.new(deployment, options) if deployment[:services]
|
27
28
|
|
28
29
|
deployment[:last_deploy] = DateTime.now.strftime("%Y/%m/%d %H:%M:%S")
|
29
30
|
puts "\nFinished Local Deployment at #{deployment[:last_deploy]}!"
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
|
32
|
+
if options[:deploy_file].end_with?('.json')
|
33
|
+
File.write(options[:deploy_file], JSON.pretty_generate(deployment))
|
34
|
+
elsif options[:deploy_file].end_with?('.yaml')
|
35
|
+
File.write(options[:deploy_file], deployment.to_yaml)
|
36
|
+
end
|
37
|
+
|
33
38
|
deployment
|
34
39
|
end
|
35
40
|
end
|
@@ -37,25 +42,33 @@ module DanarchyDeploy
|
|
37
42
|
class RemoteDeploy
|
38
43
|
def self.new(deployment, options)
|
39
44
|
puts "\n" + self.name
|
45
|
+
|
40
46
|
options[:working_dir] = options[:deploy_dir] + '/' + deployment[:hostname]
|
41
47
|
connector = { hostname: deployment[:hostname],
|
42
48
|
ipv4: deployment[:ipv4],
|
43
49
|
ssh_user: deployment[:ssh_user],
|
44
50
|
ssh_key: deployment[:ssh_key] }
|
45
51
|
|
46
|
-
|
47
|
-
push_deployment(connector, options)
|
48
|
-
deploy_result = remote_LocalDeploy(connector, options)
|
52
|
+
remote_mkdir(connector, options)
|
49
53
|
|
50
|
-
if
|
51
|
-
puts
|
52
|
-
|
54
|
+
if options[:dev_gem]
|
55
|
+
puts "\nDev Gem mode: Building and pushing gem..."
|
56
|
+
gem = dev_gem_build(options)
|
57
|
+
dev_gem_install(connector, gem, options)
|
53
58
|
else
|
54
|
-
|
59
|
+
gem_install(connector, options)
|
55
60
|
end
|
56
61
|
|
57
|
-
|
58
|
-
|
62
|
+
gem_clean(connector, options)
|
63
|
+
gem_binary = _locate_gem_binary(connector, options) # this should run before any install; check version too
|
64
|
+
push_temmplates(connector, options)
|
65
|
+
push_deployment(connector, options)
|
66
|
+
deploy_result = remote_LocalDeploy(connector, gem_binary, options)
|
67
|
+
|
68
|
+
abort("\n ! Deployment failed to complete!") if !deploy_result
|
69
|
+
|
70
|
+
pull_deployment(connector, options) if !options[:pretend]
|
71
|
+
# remote_cleanup(connector, options) if !options[:pretend]
|
59
72
|
|
60
73
|
puts "\nRemote deployment complete!"
|
61
74
|
deployment = JSON.parse(File.read(options[:deploy_file]), symbolize_names: true) if options[:deploy_file].end_with?('.json')
|
@@ -64,68 +77,186 @@ module DanarchyDeploy
|
|
64
77
|
end
|
65
78
|
|
66
79
|
private
|
67
|
-
def self.
|
80
|
+
def self.remote_mkdir(connector, options)
|
81
|
+
puts "\n > Creating directory: #{options[:working_dir]}"
|
82
|
+
mkdir_cmd = _ssh_command(connector, "test -d #{options[:working_dir]} || sudo mkdir -vp #{options[:working_dir]}")
|
83
|
+
mkdir_result = DanarchyDeploy::Helpers.run_command(mkdir_cmd, options)
|
84
|
+
|
85
|
+
if mkdir_result[:stderr]
|
86
|
+
abort(' ! Directory creation failed!')
|
87
|
+
else
|
88
|
+
puts " |+ Created directory: '#{options[:deploy_dir]}'"
|
89
|
+
end
|
90
|
+
|
91
|
+
puts "\n > Setting directory permissions to '0750' for '#{connector[:ssh_user]}' on '#{options[:deploy_dir]}'"
|
92
|
+
chown_cmd = _ssh_command(connector, "sudo chown -Rc #{connector[:ssh_user]}:#{connector[:ssh_user]} #{options[:deploy_dir]}; " +
|
93
|
+
"sudo chmod -c 0750 #{options[:deploy_dir]}")
|
94
|
+
chown_result = DanarchyDeploy::Helpers.run_command(chown_cmd, options)
|
95
|
+
|
96
|
+
if chown_result[:stderr]
|
97
|
+
abort(' ! Setting directory permissions failed!')
|
98
|
+
else
|
99
|
+
puts ' |+ Set directory permissions!'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.gem_install(connector, options)
|
68
104
|
puts "\n > Installing danarchy_deploy on #{connector[:hostname]}"
|
69
|
-
|
105
|
+
install_cmd = _ssh_command(connector, 'sudo gem install -f danarchy_deploy')
|
106
|
+
install_result = DanarchyDeploy::Helpers.run_command(install_cmd, options)
|
70
107
|
|
71
108
|
if install_result[:stderr]
|
72
|
-
|
73
|
-
abort("STDERR:\n#{install_result[:stderr]}")
|
109
|
+
abort(' ! Gem install failed!')
|
74
110
|
else
|
75
111
|
puts " |+ Gem installed!"
|
76
112
|
end
|
77
113
|
end
|
78
114
|
|
79
|
-
|
115
|
+
def self.dev_gem_build(options)
|
116
|
+
gem = "danarchy_deploy-#{DanarchyDeploy::VERSION}.gem"
|
117
|
+
puts "\n > Building gem: #{gem}"
|
118
|
+
gem_dir = File.expand_path('../../', __FILE__)
|
119
|
+
|
120
|
+
abort('ERROR: Need to be in development gem directory for --dev-gem!') if Dir.pwd != gem_dir
|
121
|
+
|
122
|
+
gem_path = "#{gem_dir}/pkg/#{gem}"
|
123
|
+
build_cmd = "cd #{gem_dir} && git add . && rake build"
|
124
|
+
build_result = DanarchyDeploy::Helpers.run_command(build_cmd, options)
|
125
|
+
|
126
|
+
if build_result[:stderr]
|
127
|
+
abort(' ! Gem build failed!')
|
128
|
+
elsif File.exist?(gem_path)
|
129
|
+
puts " |+ Gem built: #{gem_path}"
|
130
|
+
end
|
131
|
+
|
132
|
+
gem_path
|
133
|
+
end
|
134
|
+
|
135
|
+
def self.dev_gem_install(connector, gem, options)
|
136
|
+
puts "\n > Pushing gem: #{gem} to #{connector[:hostname]}"
|
137
|
+
push_cmd = _scp_push(connector, gem, options[:deploy_dir])
|
138
|
+
push_result = DanarchyDeploy::Helpers.run_command(push_cmd, options)
|
139
|
+
|
140
|
+
if push_result[:stderr]
|
141
|
+
abort(' ! Gem push failed!')
|
142
|
+
else
|
143
|
+
puts ' |+ Gem pushed!'
|
144
|
+
end
|
145
|
+
|
146
|
+
puts "\n > Installing gem: #{gem} on #{connector[:hostname]}"
|
147
|
+
install_cmd = _ssh_command(connector, "sudo gem install -f #{options[:deploy_dir]}/#{File.basename(gem)}")
|
148
|
+
install_result = DanarchyDeploy::Helpers.run_command(install_cmd, options)
|
149
|
+
|
150
|
+
if install_result[:stderr]
|
151
|
+
abort(' ! Gem install failed!')
|
152
|
+
else
|
153
|
+
puts ' |+ Gem installed!'
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def self.gem_clean(connector, options)
|
158
|
+
clean_cmd = _ssh_command(connector, 'sudo gem clean danarchy_deploy 2&>/dev/null')
|
159
|
+
system(clean_cmd)
|
160
|
+
end
|
161
|
+
|
162
|
+
def self.push_temmplates(connector, options)
|
163
|
+
template_dir = options[:deploy_dir] + '/templates'
|
164
|
+
puts "\n > Pushing templates: #{template_dir}"
|
165
|
+
push_cmd = _rsync_push(connector, template_dir, template_dir)
|
166
|
+
push_result = DanarchyDeploy::Helpers.run_command(push_cmd, options)
|
167
|
+
|
168
|
+
if push_result[:stderr]
|
169
|
+
abort(' ! Templates push failed!')
|
170
|
+
else
|
171
|
+
puts " |+ Templates pushed to '#{options[:working_dir]}'!"
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
80
175
|
def self.push_deployment(connector, options)
|
81
176
|
puts "\n > Pushing deployment: #{options[:deploy_file]}"
|
82
|
-
|
83
|
-
|
84
|
-
|
177
|
+
push_cmd = _rsync_push(connector, options[:working_dir], options[:working_dir])
|
178
|
+
push_result = DanarchyDeploy::Helpers.run_command(push_cmd, options)
|
179
|
+
|
85
180
|
if push_result[:stderr]
|
86
|
-
|
87
|
-
abort("STDERR:\n#{push_result[:stderr]}")
|
181
|
+
abort(' ! Deployment push failed!')
|
88
182
|
else
|
89
|
-
puts " |+ Deployment pushed!"
|
183
|
+
puts " |+ Deployment pushed to '#{options[:working_dir]}'!"
|
90
184
|
end
|
91
185
|
end
|
92
186
|
|
93
|
-
def self.remote_LocalDeploy(connector, options)
|
94
|
-
puts "\n > Running LocalDeploy on #{connector[:hostname]}\n
|
187
|
+
def self.remote_LocalDeploy(connector, gem_binary, options)
|
188
|
+
puts "\n > Running LocalDeploy on #{connector[:hostname]}.\n\n"
|
95
189
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
190
|
+
deploy_cmd = "sudo #{gem_binary} local "
|
191
|
+
deploy_cmd += '--first-run ' if options[:first_run]
|
192
|
+
deploy_cmd += '--ssh-verbose ' if options[:ssh_verbose]
|
193
|
+
deploy_cmd += '--vars-verbose ' if options[:vars_verbose]
|
194
|
+
deploy_cmd += '--pretend ' if options[:pretend]
|
195
|
+
deploy_cmd += '--json ' if options[:deploy_file].end_with?('.json')
|
196
|
+
deploy_cmd += '--yaml ' if options[:deploy_file].end_with?('.yaml')
|
197
|
+
deploy_cmd += options[:deploy_file]
|
103
198
|
|
104
|
-
|
199
|
+
deploy_command = _ssh_command(connector, deploy_cmd)
|
200
|
+
system(deploy_command)
|
105
201
|
end
|
106
202
|
|
107
203
|
def self.pull_deployment(connector, options)
|
108
204
|
puts "\n > Pulling deployment: #{options[:deploy_file]}"
|
109
|
-
|
205
|
+
pull_cmd = _scp_pull(connector, options[:deploy_file], options[:deploy_file])
|
206
|
+
pull_result = DanarchyDeploy::Helpers.run_command(pull_cmd, options)
|
110
207
|
|
111
208
|
if pull_result[:stderr]
|
112
|
-
|
113
|
-
abort("STDERR:\n#{pull_result[:stderr]}")
|
209
|
+
abort(' ! Deployment pull failed!')
|
114
210
|
else
|
115
211
|
puts " |+ Deployment pulled!"
|
116
212
|
end
|
117
213
|
end
|
118
214
|
|
119
|
-
def self.
|
215
|
+
def self.remote_cleanup(connector, options)
|
120
216
|
puts "\n > Cleaning up: #{options[:deploy_dir]}"
|
121
|
-
|
217
|
+
cleanup_cmd = _ssh_command(connector, "sudo rm -rfv #{options[:working_dir]}")
|
218
|
+
cleanup_result = DanarchyDeploy::Helpers.run_command(cleanup_cmd, options)
|
122
219
|
|
123
220
|
if cleanup_result[:stderr]
|
124
|
-
|
125
|
-
abort("STDERR:\n#{cleanup_result[:stderr]}")
|
221
|
+
abort(' ! Deployment cleanup failed!')
|
126
222
|
else
|
127
223
|
puts " |+ Deployment cleaned up!"
|
128
224
|
end
|
129
225
|
end
|
226
|
+
|
227
|
+
def self._locate_gem_binary(connector, options)
|
228
|
+
locate_cmd = _ssh_command(connector, 'sudo which danarchy_deploy')
|
229
|
+
locate_result = DanarchyDeploy::Helpers.run_command(locate_cmd, options)
|
230
|
+
|
231
|
+
if locate_result[:stderr]
|
232
|
+
abort(' ! Could not locate Ruby gem binary!')
|
233
|
+
else
|
234
|
+
puts ' |+ Gem binary located!'
|
235
|
+
end
|
236
|
+
|
237
|
+
locate_result[:stdout].chomp
|
238
|
+
end
|
239
|
+
|
240
|
+
def self._ssh_command(connector, command)
|
241
|
+
"ssh -i #{connector[:ssh_key]} " +
|
242
|
+
"#{connector[:ssh_user]}@#{connector[:ipv4]} " +
|
243
|
+
"-o ConnectTimeout=30 -o StrictHostKeyChecking=no '#{command}'"
|
244
|
+
end
|
245
|
+
|
246
|
+
def self._scp_push(connector, local, remote)
|
247
|
+
"scp -i #{connector[:ssh_key]} #{local} #{connector[:ssh_user]}@#{connector[:ipv4]}:#{remote}/"
|
248
|
+
end
|
249
|
+
|
250
|
+
def self._scp_pull(connector, remote, local)
|
251
|
+
"scp -i #{connector[:ssh_key]} #{connector[:ssh_user]}@#{connector[:ipv4]}:#{remote} #{local}"
|
252
|
+
end
|
253
|
+
|
254
|
+
def self._rsync_push(connector, local, remote)
|
255
|
+
"rsync --rsh 'ssh -i #{connector[:ssh_key]}' -Havzu --delete #{local}/ #{connector[:ssh_user]}@#{connector[:ipv4]}:#{remote}/"
|
256
|
+
end
|
257
|
+
|
258
|
+
def self._rsync_pull(connector, remote, local)
|
259
|
+
"rsync --rsh 'ssh -i #{connector[:ssh_key]}' -Havzu --delete #{connector[:ssh_user]}@#{connector[:ipv4]}:#{remote}/ #{local}/"
|
260
|
+
end
|
130
261
|
end
|
131
262
|
end
|