hr_deploy 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b28b9132177e558b47d24cb7f9c82fcef1d8e868
4
- data.tar.gz: 67d784589f95f0f7aa318be470c41eafee993fe5
3
+ metadata.gz: 93edb710600a30c90ce512be9dae066d6cfb64f5
4
+ data.tar.gz: 9129a7c55e56c7fed6c3a269763c22ccc6a01ceb
5
5
  SHA512:
6
- metadata.gz: c6d9b7ada7ca554d8599255e6a25f4df5a970ca0eaa3d0559e89de8b3f8388ba641a67de98d72c2070a5d067dd637c31e31234ad95e1f744a24e736eb213cbd8
7
- data.tar.gz: 2cab2dbd608ace629c1d29bb7b6d7cd4bac6010025087ff372488a3a5c013874a81842c84afb41a58cfddc7e3d891f94728879c7f7c79f9b3da4dfbc2622fa9e
6
+ metadata.gz: d84c22c58a26875b651ef921ae5ac61c25e9e4791be78f523d0abf7ceb77f6089ad9a48a834302540b3f4bce6b316a577362e8391fd66699910cf62c867df29e
7
+ data.tar.gz: 8447cc2204afa97ee798a40201a7ee2efecb13688f199f0fca99e9776a5f98fd010cc763598c5e2a3e5d24923c1f7b1d04fb45b1fcaa927df01a03d49f1a357c
data/bin/hr_deploy CHANGED
@@ -29,10 +29,34 @@ def parse(opts)
29
29
  elsif opts == ['generate']
30
30
  { command: :generate }
31
31
 
32
- elsif opts.first == 'deploy' && (opts.length == 1 || opts.length == 2)
33
- # This will extract the name of the target to deploy to or nil if no target is specified
34
- target = opts[1, opts.length].first
35
- { command: :deploy, target: target }
32
+ elsif opts.first == 'deploy'
33
+ # Deploy command
34
+ # Possible combinations:
35
+ #
36
+ # (empty)
37
+ # (target)
38
+ # --no-confirm
39
+ # (target) --no-confirm
40
+ # --no-confirm target
41
+
42
+ deploy_options = opts[1, opts.length]
43
+
44
+ # 0 to 2 additional options to 'deploy' command
45
+ return nil unless deploy_options.length <= 2
46
+
47
+ confirm = true
48
+ confirm = false if deploy_options.delete('--no-confirm')
49
+
50
+ # After we have removed '--no-confirm', we either have one param (target) or nothing
51
+ return nil unless deploy_options.length <= 1
52
+
53
+ # 'nil' for no target (default target)
54
+ target = deploy_options.first
55
+
56
+ # Explicit target should not be a command argument
57
+ return nil if target && target.start_with?('--')
58
+
59
+ { command: :deploy, target: target, confirm: confirm }
36
60
 
37
61
  else
38
62
  nil
@@ -48,8 +72,12 @@ def react(command)
48
72
 
49
73
  elsif command[:command] == :generate || command[:command] == :deploy
50
74
  if inside_app?
51
- generate if command[:command] == :generate
52
- attempt_deploy(command[:target]) if command[:command] == :deploy
75
+ if command[:command] == :generate
76
+ generate
77
+ else
78
+ attempt_deploy(command[:target], command[:confirm])
79
+ end
80
+
53
81
  else
54
82
  puts 'You should be inside a Heroku app to run this command'
55
83
  exit 1
@@ -74,7 +102,7 @@ def generate
74
102
  end
75
103
  end
76
104
 
77
- def attempt_deploy(target_name)
105
+ def attempt_deploy(target_name, confirm)
78
106
 
79
107
  # These tools are needed for all deploys
80
108
  exit 1 unless tools_available?('heroku', 'git')
@@ -86,9 +114,11 @@ def attempt_deploy(target_name)
86
114
  targets = raw_targets.map { |raw_target| HR_Deploy::Target.new(raw_target) }
87
115
 
88
116
  if target_name
117
+ # Explicit target name given
118
+
89
119
  target = targets.find { |target| target.name == target_name }
90
120
  if target
91
- deploy(target)
121
+ deploy(target, confirm)
92
122
  else
93
123
  puts "No such target: #{target_name}"
94
124
  exit 1
@@ -106,7 +136,7 @@ def attempt_deploy(target_name)
106
136
  exit 1
107
137
  else
108
138
  # Deploy default target
109
- deploy(default_targets.first)
139
+ deploy(default_targets.first, confirm)
110
140
  end
111
141
  end
112
142
  else
@@ -119,12 +149,12 @@ def attempt_deploy(target_name)
119
149
  end
120
150
  end
121
151
 
122
- def deploy(target)
152
+ def deploy(target, confirm)
123
153
  # Some targets need 'curl' to disable/enable New Relic pinger
124
154
  exit 1 if target.requires_curl? && !tools_available?('curl')
125
155
 
126
156
  # Actual deployment
127
- deployer = HR_Deploy::Deployer.new(target)
157
+ deployer = HR_Deploy::Deployer.new(target, confirm)
128
158
  deployer.deploy
129
159
  end
130
160
 
@@ -175,10 +205,19 @@ generate Generate a config file which specifies targets to deploy to.
175
205
 
176
206
  deploy [target] Deploy to [target]. If no [target] is specified, deploy
177
207
  to default target specified in config.
208
+ This command supports the following options:
209
+
210
+ --no-confirm Skip confirmations while deploying.
211
+ This does not affect the initial
212
+ confirmation that triggers the deploy itself.
213
+ Default behavior is to confirm actions.
178
214
 
179
215
  version Show gem version.
180
216
 
181
217
  help Show help.
218
+
219
+ Verbose documentation is at:
220
+ https://github.com/enthrops/hr_deploy/blob/master/README.md
182
221
  eos
183
222
 
184
223
  puts help_string
@@ -2,14 +2,18 @@ module HR_Deploy
2
2
 
3
3
  class Deployer
4
4
 
5
+ DEBUG = false
6
+
5
7
  attr_reader :target
6
8
  attr_reader :pinging_interaction
7
9
  attr_reader :perform_db_backup
10
+ attr_reader :confirm
8
11
 
9
- def initialize(target)
12
+ def initialize(target, confirm)
10
13
  @target = target
11
14
  @pinging_interaction = target.requires_pinging_interaction?
12
15
  @perform_db_backup = target.backup_db?
16
+ @confirm = confirm
13
17
  end
14
18
 
15
19
  def deploy
@@ -50,7 +54,7 @@ module HR_Deploy
50
54
  puts 'Waiting 10 seconds for application to go live...'
51
55
  sleep 10
52
56
  puts 'Opening application...'
53
- system("heroku open --remote #{target.name}")
57
+ execute_system_command("heroku open --remote #{target.name}")
54
58
  puts
55
59
 
56
60
  puts "Deploy completed in #{(Time.now - start_time).round} seconds"
@@ -200,46 +204,61 @@ module HR_Deploy
200
204
  end
201
205
 
202
206
  def continue?(stage)
203
- answered = false
204
207
 
205
- until answered
206
-
207
- case stage
208
- when :disabling_pinger
209
- print 'Pinger disabled? (Yes / No) > '
210
- when :enabling_maintenance
211
- print 'Maintenance mode enabled? (Yes / No) > '
212
- when :backing_up_db
213
- print 'Database backed up? (Yes / No) > '
214
- when :pushing_code
215
- print 'Code pushed successfully? (Yes / No) > '
216
- when :migrating_db
217
- print 'Database migrated? (Yes / No) > '
218
- when :restarting
219
- print 'Restarted? (Yes / No) > '
220
- when :enabling_pinger
221
- print 'Pinger enabled? (Yes / No) > '
222
- when :disabling_maintenance
223
- print 'Maintenance mode disabled? (Yes / No) > '
224
- else
225
- raise 'Unknown stage'
226
- end
208
+ if confirm
209
+ # User wants confirmations
210
+
211
+ answered = false
212
+ until answered
213
+
214
+ case stage
215
+ when :disabling_pinger
216
+ print 'Pinger disabled? (Yes / No) > '
217
+ when :enabling_maintenance
218
+ print 'Maintenance mode enabled? (Yes / No) > '
219
+ when :backing_up_db
220
+ print 'Database backed up? (Yes / No) > '
221
+ when :pushing_code
222
+ print 'Code pushed successfully? (Yes / No) > '
223
+ when :migrating_db
224
+ print 'Database migrated? (Yes / No) > '
225
+ when :restarting
226
+ print 'Restarted? (Yes / No) > '
227
+ when :enabling_pinger
228
+ print 'Pinger enabled? (Yes / No) > '
229
+ when :disabling_maintenance
230
+ print 'Maintenance mode disabled? (Yes / No) > '
231
+ else
232
+ raise 'Unknown stage'
233
+ end
227
234
 
228
- answer = $stdin.gets.chomp
235
+ answer = $stdin.gets.chomp
229
236
 
230
- if answer == 'Yes' || answer == 'yes'
231
- answered = true
232
- puts
233
- yield
234
- elsif answer == 'No' || answer == 'no'
235
- puts
236
- abort_deploy(nil, stage)
237
- else
238
- puts 'Unknown answer'
239
- puts
237
+ if answer == 'Yes' || answer == 'yes'
238
+ answered = true
239
+ puts
240
+ yield
241
+ elsif answer == 'No' || answer == 'no'
242
+ puts
243
+ abort_deploy(nil, stage)
244
+ else
245
+ puts 'Unknown answer'
246
+ puts
247
+ end
240
248
  end
249
+
250
+ else
251
+ # User does not want confirmations, continue
252
+ yield
241
253
  end
254
+ end
242
255
 
256
+ def execute_system_command(cmd)
257
+ if DEBUG
258
+ puts "Executing command: #{cmd}"
259
+ else
260
+ system(cmd)
261
+ end
243
262
  end
244
263
 
245
264
  def check_connectivity
@@ -319,49 +338,49 @@ module HR_Deploy
319
338
 
320
339
  def disable_pinging
321
340
  puts 'Disabling availability pinger...'
322
- system("curl #{target.disable_pinger_url}")
341
+ execute_system_command("curl #{target.disable_pinger_url}")
323
342
  puts
324
343
  end
325
344
 
326
345
  def enable_maintenance
327
346
  puts 'Enabling maintenance mode...'
328
- system("heroku maintenance:on --remote #{target.name}")
347
+ execute_system_command("heroku maintenance:on --remote #{target.name}")
329
348
  puts
330
349
  end
331
350
 
332
351
  def backup_db
333
352
  puts 'Backing up database...'
334
- system("heroku pgbackups:capture --expire --remote #{target.name}")
353
+ execute_system_command("heroku pgbackups:capture --expire --remote #{target.name}")
335
354
  puts
336
355
  end
337
356
 
338
357
  def push_code
339
358
  puts 'Pushing code...'
340
- system("git push #{target.name} master")
359
+ execute_system_command("git push #{target.name} master")
341
360
  puts
342
361
  end
343
362
 
344
363
  def migrate_db
345
364
  puts 'Migrating database...'
346
- system("heroku run rake db:migrate --remote #{target.name}")
365
+ execute_system_command("heroku run rake db:migrate --remote #{target.name}")
347
366
  puts
348
367
  end
349
368
 
350
369
  def restart
351
370
  puts 'Restarting...'
352
- system("heroku restart --remote #{target.name}")
371
+ execute_system_command("heroku restart --remote #{target.name}")
353
372
  puts
354
373
  end
355
374
 
356
375
  def enable_pinging
357
376
  puts 'Enabling availability pinger...'
358
- system("curl #{target.enable_pinger_url}")
377
+ execute_system_command("curl #{target.enable_pinger_url}")
359
378
  puts
360
379
  end
361
380
 
362
381
  def disable_maintenance
363
382
  puts 'Disabling maintenance mode...'
364
- system("heroku maintenance:off --remote #{target.name}")
383
+ execute_system_command("heroku maintenance:off --remote #{target.name}")
365
384
  puts
366
385
  end
367
386
  end
@@ -1,3 +1,3 @@
1
1
  module HR_Deploy
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hr_deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Gubitskiy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-25 00:00:00.000000000 Z
11
+ date: 2013-06-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Easily deploy your Rails apps to Heroku with one command, automatically
14
14
  taking care of things such as checking current Heroku status, enabling maintenance