bb_deploy 0.0.1.4 → 0.0.1.6

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: 8241aef295ed6a9daab2ed280bf3d3c0fb3476d6
4
- data.tar.gz: ad6a59e169339ab06490f8fad2f11e30515d5eac
3
+ metadata.gz: 24f8664be9be11c1a6d49f2ef6226d341df9197e
4
+ data.tar.gz: 1582f4d9af9c9460274ca641ea5dc5f112e8528d
5
5
  SHA512:
6
- metadata.gz: 22acc844d134708557de46ebdbe6e037fecc2d4565e435f1982a3a54e79dab518c918fcce64b4ed1655c692c4a887916035f91e8bd5c4fde6a3e52871b1c7250
7
- data.tar.gz: 0fd2b196d9505f67b211504a812f8e52390877b72e8055928799c8622eb1e43c36ecd06a9d2be8e0db7d66fc373da49f49915a0dde816917668c657f7765ffe0
6
+ metadata.gz: 228180ff79df1fd22dc1b27f0eb5079ab54769b5e234f56e5b6fce6d4d4f09a487f1b07479d1bb5ce8be56167daf780805feda2b75f81d740bf3b9ca1efdcb1a
7
+ data.tar.gz: b22495d3fff7b3a7f81b029c5fb92459bb80f2bcea7605da20e024c475ca5e917ba948dd706f8745aaa751a61c1da05fb8afc922ac06371e25364cffb1721535
@@ -1,3 +1,4 @@
1
+ require 'yaml'
1
2
  require_relative './heroku'
2
3
 
3
4
  module BbDeploy
@@ -16,10 +17,11 @@ module BbDeploy
16
17
 
17
18
  def configure
18
19
  yield(configuration)
20
+ configuration
19
21
  end
20
22
 
21
- def configure_from_yaml(filepath)
22
- options = YAML.load_file(filepath)
23
+ def configure_from_yaml(file_path)
24
+ options = YAML.load(ERB.new(File.read(file_path)).result)
23
25
  configure do |config|
24
26
  %w(application_name application_urls deployment_channel engineering_channel).each do |key|
25
27
  config.send("#{key}=", options[key])
@@ -27,7 +29,7 @@ module BbDeploy
27
29
  end
28
30
  end
29
31
 
30
- def set_heroku_fields!(phase:)
32
+ def set_heroku_fields!(phase)
31
33
  configure do |config|
32
34
  config.logentries_token = BbDeploy::Heroku.get_variable(phase, 'DEPLOY_LOG_TOKEN').freeze
33
35
  config.slack_webhook_key = BbDeploy::Heroku.get_variable(phase, 'SLACK_WEBHOOK').freeze
@@ -1,3 +1,4 @@
1
+ require 'pp'
1
2
  require_relative './config'
2
3
  require_relative './task'
3
4
  require_relative './logger'
@@ -10,12 +11,17 @@ class BbDeploy::Deployer
10
11
 
11
12
  attr_reader :phase
12
13
 
13
- def initialize(phase:)
14
+ def initialize(phase)
14
15
  BbDeploy::Config.configure_from_yaml('config/deploy.yml')
15
- BbDeploy::Config.set_heroku_fields!(phase: phase)
16
+ BbDeploy::Config.set_heroku_fields!(phase)
16
17
  @phase = phase
17
18
  end
18
19
 
20
+ # Environment inquiry methods
21
+ %w(qa staging production).each do |phase|
22
+ define_method("#{phase}?") { @phase == phase }
23
+ end
24
+
19
25
  def deploy!
20
26
  BbDeploy::Git.check_git_status!
21
27
  check_access!
@@ -30,6 +36,14 @@ class BbDeploy::Deployer
30
36
 
31
37
  private
32
38
 
39
+ def dputs(*msgs)
40
+ asterisks = "*" * 80
41
+ puts asterisks
42
+ puts(*msgs.map(&:to_s))
43
+ puts asterisks
44
+ end
45
+
46
+
33
47
  def current_branch
34
48
  BbDeploy::Git.current_branch(started_on_master?)
35
49
  end
@@ -37,7 +51,7 @@ class BbDeploy::Deployer
37
51
  def do_deploy
38
52
  branch = current_branch
39
53
 
40
- chat_broadcast("'#{ENV['USER']}' is deploying the #{BbDeploy::Config.application_name} branch '#{branch}' to '#{phase}' ...", phase: phase, notify_eng_hub: true)
54
+ chat_broadcast(":alert: '#{ENV['USER']}' is deploying the #{BbDeploy::Config.application_name} branch '#{branch}' to '#{phase}' :alert:", phase: phase, notify_eng_hub: true)
41
55
 
42
56
  do_heroku_deploy!
43
57
 
@@ -49,7 +63,7 @@ class BbDeploy::Deployer
49
63
  puts "You must now resolve any conflicts in the merge and then `git push origin master` ..."
50
64
  end
51
65
 
52
- chat_broadcast("(successful) Deployment of the #{BbDeploy::Config.application_name} branch '#{branch}' to '#{phase}' completed!", phase: phase, notify_eng_hub: true)
66
+ chat_broadcast(":alertgreen: Deployment of the #{BbDeploy::Config.application_name} branch '#{branch}' to '#{phase}' completed! :alertgreen:", phase: phase, notify_eng_hub: true)
53
67
  end
54
68
 
55
69
  def logger
@@ -57,7 +71,7 @@ class BbDeploy::Deployer
57
71
  end
58
72
 
59
73
  def check_access!
60
- if BbDeploy::Heroku.has_access?(phase)
74
+ unless BbDeploy::Heroku.has_access?(phase)
61
75
  exit_with_message("You do not have access to the #{BbDeploy::Config.application_name} #{phase} application!")
62
76
  end
63
77
  end
@@ -69,7 +83,6 @@ class BbDeploy::Deployer
69
83
 
70
84
  def do_heroku_deploy! # rubocop:disable all
71
85
  run_migrations = run_migrations?
72
- stay_in_maint_mode = false
73
86
 
74
87
  exit(0) if run_migrations && !BbDeploy::Task.ask("There are new migrations to run. If you proceed,\n\n*** YOU WILL INCUR SITE DOWNTIME!!! ***\n\nDo you wish to proceed?")
75
88
 
@@ -81,15 +94,7 @@ class BbDeploy::Deployer
81
94
 
82
95
  push_release!
83
96
 
84
- if run_migrations
85
- started_at = Time.current
86
- run_migrations!
87
- time_spent = Time.zone.at(Time.current - started_at).getutc.strftime("%H:%M:%S")
88
- # The only time started_on_master is non-nil is when creating a new staging branch
89
- if started_on_master?
90
- chat_broadcast("Yo, @jake - the #{BbDeploy::Config.application_name} branch '#{current_branch}' contains migrations that take #{time_spent} to run", phase: phase, notify_eng_hub: true)
91
- end
92
- end
97
+ run_migrations! if run_migrations
93
98
 
94
99
  if enter_maint_mode
95
100
  if stay_in_maint_mode
@@ -100,18 +105,26 @@ class BbDeploy::Deployer
100
105
  end
101
106
  end
102
107
 
108
+ def run_migrations!
109
+ started_at = Time.current
110
+
111
+ chat_broadcast("Running migrations from #{BbDeploy::Config.application_name} branch '#{current_branch}' in #{phase} ...", phase: phase)
112
+ logger.with_consolidated_logging { BbDeploy::Heroku.migrate_db!(phase) }
113
+ chat_broadcast("Successfully ran migrations from #{BbDeploy::Config.application_name} branch '#{current_branch}' in #{phase}.", phase: phase)
114
+
115
+ time_spent = Time.zone.at(Time.current - started_at).getutc.strftime("%H:%M:%S")
116
+ # The only time started_on_master is non-nil is when creating a new staging branch
117
+ if started_on_master?
118
+ chat_broadcast("Yo, @jake - the #{BbDeploy::Config.application_name} branch '#{current_branch}' contains migrations that take #{time_spent} to run", phase: phase, notify_eng_hub: true)
119
+ end
120
+ end
121
+
103
122
  def push_release!
104
123
  puts "Deploying ..."
105
124
  chat_broadcast("Pushing #{BbDeploy::Config.application_name} branch '#{current_branch}' to #{phase} ...", phase: phase)
106
125
  logger.with_consolidated_logging { puts(BbDeploy::Git.push_to_phase(phase)) }
107
126
  end
108
127
 
109
- def run_migrations!
110
- chat_broadcast("Running migrations from #{BbDeploy::Config.application_name} branch '#{current_branch}' in #{phase} ...", phase: phase)
111
- logger.with_consolidated_logging { BbDeploy::Heroku.migrate_db! }
112
- chat_broadcast("Successfully ran migrations from #{BbDeploy::Config.application_name} branch '#{current_branch}' in #{phase}.", phase: phase)
113
- end
114
-
115
128
  def open_in_browser
116
129
  sleep 2 # because removing maint mode takes a couple seconds to propagate
117
130
  host_and_path =
@@ -140,7 +153,7 @@ class BbDeploy::Deployer
140
153
 
141
154
  def staging_checks
142
155
  if BbDeploy::Git.on_master?
143
- do_it = BbDeploy::Task.ask("You are on master. Do you want to create a ***NEW*** release branch from the HEAD of master and deploy it to #{BbDeploy::Config.application_name} #{phase}?\n\n(If, instead, you want to ***REDEPLOY*** a release branch you ***PREVIOUSLY*** created, checkout that branch and rerun this script.)")
156
+ do_it = BbDeploy::Task.ask("You are on master. Do you want to create a ***NEW*** release branch from the HEAD of master and deploy it to #{BbDeploy::Config.application_name} #{phase}?")
144
157
 
145
158
  if do_it
146
159
  date = Time.zone.today.to_s(:db).tr('-', '_')
@@ -154,7 +167,7 @@ class BbDeploy::Deployer
154
167
  exit_with_message("There already exists a remote release branch named #{new_branch}!")
155
168
  end
156
169
 
157
- # puts `git checkout -lb #{new_branch} && git push origin #{new_branch} -u`
170
+ BbDeploy::Git.push_release_branch!
158
171
 
159
172
  started_on_master!
160
173
  end
data/lib/bb_deploy/git.rb CHANGED
@@ -16,14 +16,17 @@ module BbDeploy::Git
16
16
  end
17
17
 
18
18
  def push_to_phase(phase)
19
- puts "git push #{phase} HEAD:master --force"
20
- # `git push #{phase} HEAD:master --force`
19
+ `git push #{phase} HEAD:master --force`
21
20
  end
22
21
 
23
22
  def on_master?
24
23
  current_branch == 'master'
25
24
  end
26
25
 
26
+ def push_release_branch!
27
+ puts `git checkout -lb #{new_branch} && git push origin #{new_branch} -u`
28
+ end
29
+
27
30
  def on_a_release_branch?
28
31
  current_branch.start_with?('release_')
29
32
  end
@@ -5,7 +5,8 @@ module BbDeploy::Heroku
5
5
  def get_variable(phase, var_name)
6
6
  @heroku_env_vars ||= {}
7
7
  return @heroku_env_vars[var_name] if @heroku_env_vars[var_name]
8
- if token = heroku_run("heroku config:get #{var_name} --remote #{phase}").present?
8
+ token = heroku_run("heroku config:get #{var_name} --remote #{phase}")
9
+ if token.present?
9
10
  token = token.chomp
10
11
  @heroku_env_vars[var_name] = token.split.last
11
12
  end
@@ -13,11 +14,12 @@ module BbDeploy::Heroku
13
14
  end
14
15
 
15
16
  def last_release_sha(phase)
16
- heroku_run("heroku releases --remote #{phase} | grep Deploy | head -n 1 | awk '{print $3}'")
17
+ heroku_run("heroku releases -n 25 --remote #{phase} | grep Deploy | head -n 1 | awk '{print $3}'")
17
18
  end
18
19
 
19
20
  def has_access?(phase)
20
- heroku_run("heroku info --remote #{phase} 2>&1") =~ /You do not have access/i
21
+ heroku_info = heroku_run("heroku info --remote #{phase} 2>&1")
22
+ !(heroku_info =~ /You do not have access/i || heroku_info =~ /Enter your Heroku credentials./)
21
23
  end
22
24
 
23
25
  def migrate_db!(phase)
@@ -33,9 +35,8 @@ module BbDeploy::Heroku
33
35
 
34
36
  def heroku_run(*cmds)
35
37
  # Heroku Toolbelt uses Ruby 1.9, which requires clearing the RUBYOPT var ...
36
- puts "Running\n#{cmds}"
37
- puts *cmds.map { |cmd| cmd =~ /heroku/ ? "export RUBYOPT='' && #{cmd}" : cmd }
38
- # BbDeploy::Task.run(*cmds.map { |cmd| cmd =~ /heroku/ ? "export RUBYOPT='' && #{cmd}" : cmd })
38
+ puts "Running: #{cmds.map(&:inspect).join(", ")}"
39
+ BbDeploy::Task.run(*cmds.map { |cmd| cmd =~ /heroku/ ? "export RUBYOPT='' && #{cmd}" : cmd })
39
40
  end
40
41
  end
41
42
  end
@@ -45,23 +45,21 @@ module BbDeploy::Logger
45
45
  attachment = [
46
46
  {
47
47
  fallback: "Deploying to #{phase}",
48
- color: "good",
48
+ color: " ",
49
49
  fields: [
50
50
  {
51
51
  title: "Details",
52
- # Work the cuteness back in at some point ...
53
- value: msg.gsub("(successful)", ":rocket:"), # .gsub("(hisham)", ":hisham:").gsub("(jusx)", ":jusx:")
52
+ value: msg,
54
53
  short: false
55
54
  }
56
55
  ]
57
56
  }
58
57
  ]
59
58
 
60
- puts "[ *Deploying to #{phase}* ]"
61
- # slack.ping("*Deploying to #{phase}*", attachments: attachment, channel: BbDeploy::Config.deployment_channel)
62
- # slack.ping("*Deploying to #{phase}*", attachments: attachment, channel: BbDeploy::Config.engineering_channel) if notify_eng_hub
63
- # @consolidated_logger ||= ConsolidatedLogger::Logentries.new(phase)
64
- # @consolidated_logger.logger.info("DEPLOY--#{msg}")
59
+ slack.ping("*Deploying to #{phase}*", attachments: attachment, channel: BbDeploy::Config.deployment_channel)
60
+ slack.ping("*Deploying to #{phase}*", attachments: attachment, channel: BbDeploy::Config.engineering_channel) if notify_eng_hub
61
+ @consolidated_logger ||= ConsolidatedLogger::Logentries.new(phase)
62
+ @consolidated_logger.logger.info("DEPLOY--#{msg}")
65
63
  end
66
64
 
67
65
  def slack
@@ -0,0 +1,12 @@
1
+ require 'bb_deploy'
2
+ # require 'rails'
3
+
4
+ module BbDeploy
5
+ class Railtie < Rails::Railtie
6
+ railtie_name :bb_deploy
7
+
8
+ rake_tasks do
9
+ load "tasks/deploy.rake"
10
+ end
11
+ end
12
+ end
@@ -6,7 +6,6 @@ module BbDeploy::Task
6
6
  result = cmds.map do |cmd|
7
7
  cmd_s = "==> \`#{cmd}\`"
8
8
  if dry_run
9
- # rubocop:disable Rails/Output
10
9
  puts "DRY RUN ONLY"
11
10
  puts cmd_s
12
11
  else
@@ -22,6 +21,7 @@ module BbDeploy::Task
22
21
  msg = "\e[31m#{msg}\e[0m"
23
22
  msg.sub!(/'#{required_response}'/, "\e[47m'#{required_response}'\e[49m")
24
23
  end
24
+ puts
25
25
  HighLine.new.ask(msg) =~ /\A#{required_response}\Z/i
26
26
  end
27
27
 
@@ -29,7 +29,6 @@ module BbDeploy::Task
29
29
 
30
30
  def with_timing(what)
31
31
  start = Time.current
32
- # rubocop:disable Rails/Output
33
32
  puts
34
33
  puts "Commencing #{what} ..."
35
34
  result = yield
data/lib/bb_deploy.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'pry'
2
+
3
+ module BbDeploy
4
+ binding.pry
5
+ require 'bb_deploy/railtie' if defined?(Rails)
6
+ require 'bb_deploy/deployer'
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bb_deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.4
4
+ version: 0.0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter van Wesep
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: highline
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -72,15 +86,14 @@ executables: []
72
86
  extensions: []
73
87
  extra_rdoc_files: []
74
88
  files:
75
- - LICENSE
76
- - README.md
89
+ - lib/bb_deploy.rb
77
90
  - lib/bb_deploy/config.rb
78
91
  - lib/bb_deploy/deployer.rb
79
92
  - lib/bb_deploy/git.rb
80
93
  - lib/bb_deploy/heroku.rb
81
94
  - lib/bb_deploy/logger.rb
95
+ - lib/bb_deploy/railtie.rb
82
96
  - lib/bb_deploy/task.rb
83
- - lib/tasks/deploy.rake
84
97
  homepage:
85
98
  licenses:
86
99
  - MIT
@@ -101,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
114
  version: '0'
102
115
  requirements: []
103
116
  rubyforge_project:
104
- rubygems_version: 2.2.2
117
+ rubygems_version: 2.5.1
105
118
  signing_key:
106
119
  specification_version: 4
107
120
  summary: Shared gem for deploying BrightBytes repositories
data/LICENSE DELETED
@@ -1,7 +0,0 @@
1
- Copyright (c) 2016 BRIGHTBYTES, INC.
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md DELETED
@@ -1,13 +0,0 @@
1
- # BB Deploy
2
- ----------
3
- This is a gem for deploying Rails services to Heroku via Rake task. In order to use it, the app you are trying to deploy should be set up as follows:
4
-
5
- - Add the `bb_deploy` gem to your Gemfile
6
-
7
- - Add `config/deploy.yml` to your application: http://bit.ly/2bUKVhY
8
-
9
- - Add this line to your Rakefile: load "#{Gem::Specification.find_by_name('bb_deploy').gem_dir}/lib/tasks/deploy.rake"
10
-
11
- - Make sure that your machine has all the necessary Git/Heroku keys, and that your endpoints are set up correctly.
12
-
13
- - That's it! You will now be able to deploy your app by typing `bundle exec rake heroku:deploy:<qa|staging|production>` in the root dir of your app.
@@ -1,17 +0,0 @@
1
- require_relative '../../bb_deploy'
2
-
3
- namespace :heroku do
4
- namespace :deploy do
5
- task qa: :environment do
6
- BbDeploy::Deployer.new(phase: 'qa').deploy!
7
- end
8
-
9
- task staging: :environment do
10
- BbDeploy::Deployer.new(phase: 'staging').deploy!
11
- end
12
-
13
- task production: :environment do
14
- BbDeploy::Deployer.new(phase: 'production').deploy!
15
- end
16
- end
17
- end