danarchy_deploy 0.1.4 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -0
  3. data/Gemfile.lock +9 -20
  4. data/README.md +10 -9
  5. data/Rakefile +0 -4
  6. data/bin/danarchy_deploy +24 -10
  7. data/danarchy_deploy.gemspec +4 -3
  8. data/lib/danarchy_deploy.rb +186 -55
  9. data/lib/danarchy_deploy/applicator.rb +39 -0
  10. data/lib/danarchy_deploy/applicator/nginx.rb +86 -0
  11. data/lib/danarchy_deploy/applicator/phpfpm.rb +84 -0
  12. data/lib/danarchy_deploy/applicator/redmine.rb +40 -0
  13. data/lib/danarchy_deploy/applicator/ssl.rb +14 -0
  14. data/lib/danarchy_deploy/applicator/wordpress.rb +146 -0
  15. data/lib/danarchy_deploy/applicator/wordpress/wpcli.rb +67 -0
  16. data/lib/danarchy_deploy/applicator/wordpress/wpcli_install.sh +36 -0
  17. data/lib/danarchy_deploy/applicator/wordpress/wpconfig.rb +49 -0
  18. data/lib/danarchy_deploy/archiver.rb +9 -7
  19. data/lib/danarchy_deploy/archiver/svn.rb +17 -0
  20. data/lib/danarchy_deploy/hash_deep_merge.rb +9 -0
  21. data/lib/danarchy_deploy/helpers.rb +42 -10
  22. data/lib/danarchy_deploy/services.rb +12 -25
  23. data/lib/danarchy_deploy/services/init.rb +52 -0
  24. data/lib/danarchy_deploy/services/init/openrc.rb +72 -0
  25. data/lib/danarchy_deploy/services/init/systemd.rb +69 -0
  26. data/lib/danarchy_deploy/services/mongodb.rb +162 -0
  27. data/lib/danarchy_deploy/services/mysql.rb +58 -0
  28. data/lib/danarchy_deploy/services/mysql/new_server.rb +72 -0
  29. data/lib/danarchy_deploy/services/mysql/privileges.rb +35 -0
  30. data/lib/danarchy_deploy/system.rb +86 -0
  31. data/lib/danarchy_deploy/system/centos.rb +17 -0
  32. data/lib/danarchy_deploy/system/debian.rb +61 -0
  33. data/lib/danarchy_deploy/system/gentoo.rb +66 -0
  34. data/lib/danarchy_deploy/system/opensuse.rb +22 -0
  35. data/lib/danarchy_deploy/templater.rb +53 -13
  36. data/lib/danarchy_deploy/users.rb +28 -18
  37. data/lib/danarchy_deploy/version.rb +1 -1
  38. data/templates/deploy_template.json +3 -3
  39. metadata +34 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 72f8c64cc9d06b2de3e6a0a39a11e603a9d229dc
4
- data.tar.gz: a5dd31b8f6cc4fefbaf7793d7f980e215b225585
2
+ SHA256:
3
+ metadata.gz: 9792fba2a8998890e49926fb51a20670a139b8f028f772eda429a4664b6090c9
4
+ data.tar.gz: 1dca75853aad2879cfe30bf7c8f15688c3fef4e81dbcb79b993afc5f8815645b
5
5
  SHA512:
6
- metadata.gz: 35ee05356fb984dc88bb7cf9eb382bb865474e5f584b77ee666af80b09b109f79929145f6795c9a038a401a35b61cd8ea8d7411451589a047d4009ddd28e5ecf
7
- data.tar.gz: 8c8f5149c845fa1e2e8a9ba73adf8fedda30fc7f8c72f479199528a94b8e4e0b6f2d0de0a1ea982abdda7f30536a5f348b0b5f180343f1eece20226b8be43509
6
+ metadata.gz: 0b95c8e2bfeb5d1356edb6dd330533228f5a2a3961ec5caa66c6925bd48f6ed02a0eaeb73ea91772cb129d9adabc90e7dfbe0a33d164371e75f80e6cb0486eb0
7
+ data.tar.gz: 8f6aba47acd3bb2c71c2b0d20dac76e0bf340055209cd0908c23b46980ea2c4c70b4bc5793f24be71508787ab303b568fa915cddba93c8241e5f66be9f675f9f
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ *~
1
2
  /.bundle/
2
3
  /.yardoc
3
4
  /_yardoc/
@@ -1,37 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danarchy_deploy (0.1.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
- diff-lcs (1.3)
12
- rake (10.5.0)
13
- rspec (3.7.0)
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.16)
21
+ bundler (~> 2.1)
32
22
  danarchy_deploy!
33
- rake (~> 10.0)
34
- rspec (~> 3.0)
23
+ rake (~> 13.0)
35
24
 
36
25
  BUNDLED WITH
37
- 1.16.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
- $ sudo gem install danarchy_deploy
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
- $ danarchy_deploy -h
32
- Usage: sudo /usr/local/bin/danarchy_deploy (local|remote) --json /path/to/deployment.json [options]
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
- --ssh-verbose Verbose SSH stdout/stderr output.
39
- --version Print /usr/local/bin/danarchy_deploy version.
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
@@ -1,6 +1,2 @@
1
1
  require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
2
  task :default => :spec
@@ -5,12 +5,13 @@ require 'date'
5
5
  require 'optparse'
6
6
 
7
7
  deployment = nil
8
- options = { couchdb: "/home/#{ENV['SUDO_USER']}/.danarchy/danarchy_deploy/danarchy_deploy.json",
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
- first_run: false }
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)
@@ -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.16"
34
- spec.add_development_dependency "rake", "~> 10.0"
35
- spec.add_development_dependency "rspec", "~> 3.0"
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
@@ -1,13 +1,14 @@
1
- require_relative 'danarchy_deploy/version'
2
-
3
1
  module DanarchyDeploy
4
- require_relative './danarchy_deploy/archiver'
5
- require_relative './danarchy_deploy/groups'
6
- require_relative './danarchy_deploy/helpers'
7
- require_relative './danarchy_deploy/installer'
8
- require_relative './danarchy_deploy/users'
9
- require_relative './danarchy_deploy/services'
10
- require_relative './danarchy_deploy/templater'
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(', ')) if deployment[:packages]
21
+ printf("%12s %0s\n", 'Packages:', deployment[:packages].join(', ')) if deployment[:packages]
21
22
 
22
- deployment = DanarchyDeploy::Installer.new(deployment, options)
23
- deployment = DanarchyDeploy::Services.new(deployment, options) if deployment[:services]
24
- deployment = DanarchyDeploy::Groups.new(deployment, options) if deployment[:groups]
25
- deployment = DanarchyDeploy::Users.new(deployment, options) if deployment[:users]
26
- deployment = DanarchyDeploy::Services.init(deployment, options) if deployment[: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
- File.write(options[:deploy_file],
31
- JSON.pretty_generate(deployment)) if options[:deploy_file].end_with?('.json')
32
- File.write(options[:deploy_file], deployment.to_yaml) if options[:deploy_file].end_with?('.yaml')
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
- install_gem(connector, options)
47
- push_deployment(connector, options)
48
- deploy_result = remote_LocalDeploy(connector, options)
52
+ remote_mkdir(connector, options)
49
53
 
50
- if deploy_result[:stderr]
51
- puts ' ! Deployment failed!'
52
- abort("STDERR:\n#{deploy_result[:stderr]}")
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
- puts deploy_result[:stdout]
59
+ gem_install(connector, options)
55
60
  end
56
61
 
57
- pull_deployment(connector, options)
58
- remote_Cleanup(connector, options)
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.install_gem(connector, options)
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
- install_result = DanarchyDeploy::Helpers.run_command("ssh -i #{connector[:ssh_key]} #{connector[:ssh_user]}@#{connector[:ipv4]} -o ConnectTimeout=30 'sudo gem install -f danarchy_deploy && test -d #{options[:working_dir]} || sudo mkdir -vp #{options[:working_dir]} && sudo chown -Rc #{connector[:ssh_user]}:#{connector[:ssh_user]} #{options[:working_dir]}'", options)
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
- puts ' ! Gem install failed!'
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
- # Add ssh-keygen function, then update
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
- push_result = DanarchyDeploy::Helpers.run_command("rsync --rsh 'ssh -i #{connector[:ssh_key]}' -Havzu --delete #{options[:working_dir]}/ #{connector[:ssh_user]}@#{connector[:ipv4]}:#{options[:working_dir]}/", options)
83
- # push_result = DanarchyDeploy::Helpers.run_command("scp -i #{connector[:ssh_key]} #{options[:deploy_file]} #{connector[:ssh_user]}@#{connector[:ipv4]}:#{options[:deploy_dir]}/#{connector[:hostname]}/", options)
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
- puts ' ! Deployment push failed!'
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\tOutput will return at the end of deployment."
187
+ def self.remote_LocalDeploy(connector, gem_binary, options)
188
+ puts "\n > Running LocalDeploy on #{connector[:hostname]}.\n\n"
95
189
 
96
- deployment = "ssh -i #{connector[:ssh_key]} #{connector[:ssh_user]}@#{connector[:ipv4]} 'sudo danarchy_deploy local "
97
- deployment += '--first-run ' if options[:first_run]
98
- deployment += '--ssh-verbose ' if options[:ssh_verbose]
99
- deployment += '--pretend ' if options[:pretend]
100
- deployment += '--json ' if options[:deploy_file].end_with?('.json')
101
- deployment += '--yaml ' if options[:deploy_file].end_with?('.yaml')
102
- deployment += options[:deploy_file] + '\''
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
- DanarchyDeploy::Helpers.run_command(deployment, options)
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
- pull_result = DanarchyDeploy::Helpers.run_command("scp -i #{connector[:ssh_key]} #{connector[:ssh_user]}@#{connector[:ipv4]}:#{options[:deploy_file]} #{options[:deploy_file]}", options)
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
- puts ' ! Deployment pull failed!'
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.remote_Cleanup(connector, options)
215
+ def self.remote_cleanup(connector, options)
120
216
  puts "\n > Cleaning up: #{options[:deploy_dir]}"
121
- cleanup_result = DanarchyDeploy::Helpers.run_command("ssh -i #{connector[:ssh_key]} #{connector[:ssh_user]}@#{connector[:ipv4]} 'sudo rm -rfv #{options[:working_dir]}'", options)
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
- puts ' ! Deployment cleanup failed!'
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