bb_deploy 0.0.0.4 → 0.0.1.1

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: 2e3ab6a10e9c48f895924a60da529cf39c50d515
4
- data.tar.gz: 0d308635d39f89225e1d519c2cda81cfd23c94d8
3
+ metadata.gz: 4265cc5173996544b0df461c34d76fa8dc525d39
4
+ data.tar.gz: be98bb1650d4a2c678a9e09d72ea22ae7a41a2eb
5
5
  SHA512:
6
- metadata.gz: ebe7d62cefd67cd9842b8fdedf4fb3b6d2841efece4256156726abf6b509cf84ac4b4e3c18d0be605a201559674235bfea289178d4e8c2379050feae7e8a740b
7
- data.tar.gz: 0e95d557849838c29f84020d4f9ebd5fc4bd1f5af56ca749c1673621249e4f9dc89a571b16db5b2f9365439b7a52ccc039781f0cf66c108149cf15d72df0727f
6
+ metadata.gz: f4cd670da569b6c8954023da9fd7d374a4cc56cd903ed82167422a8bc6d3021c9b26da8302a0dcb00b11094405dc25a39c5863bfbb3f1b017edf745a3acd9141
7
+ data.tar.gz: e25c4afd11033f7f7c6002497a14ffd76c6260b0e1021f98e49cb5b27fbe57975108a0ebbed5d5b30e365206461ec99688116bcb0ae3a16147435cda9c515b8e
data/LICENSE ADDED
@@ -0,0 +1,7 @@
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 ADDED
@@ -0,0 +1,14 @@
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
+ - Copy the following code to a file `config/deploy.rb` in your Rails app, and set the fields as appropriate: http://bit.ly/2cdRzAo
8
+
9
+ - Add the following line to your application's Rakefile:
10
+ `require File.expand_path('../config/deploy', __FILE__)`
11
+
12
+ - Make sure that your machine has all the necessary Git/Heroku keys, and that your endpoints are set up correctly.
13
+
14
+ - 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,6 +1,3 @@
1
- require 'yaml'
2
- require_relative './heroku'
3
-
4
1
  module BbDeploy
5
2
  class Config
6
3
  attr_accessor :application_name,
@@ -17,23 +14,6 @@ module BbDeploy
17
14
 
18
15
  def configure
19
16
  yield(configuration)
20
- configuration
21
- end
22
-
23
- def configure_from_yaml(file_path)
24
- options = YAML.load(ERB.new(File.read(file_path)).result)
25
- configure do |config|
26
- %w(application_name application_urls deployment_channel engineering_channel).each do |key|
27
- config.send("#{key}=", options[key])
28
- end
29
- end
30
- end
31
-
32
- def set_heroku_fields!(phase)
33
- configure do |config|
34
- config.logentries_token = BbDeploy::Heroku.get_variable(phase, 'DEPLOY_LOG_TOKEN').freeze
35
- config.slack_webhook_key = BbDeploy::Heroku.get_variable(phase, 'SLACK_WEBHOOK').freeze
36
- end
37
17
  end
38
18
 
39
19
  def method_missing(method, *args)
@@ -1,4 +1,3 @@
1
- require 'pp'
2
1
  require_relative './config'
3
2
  require_relative './task'
4
3
  require_relative './logger'
@@ -11,17 +10,11 @@ class BbDeploy::Deployer
11
10
 
12
11
  attr_reader :phase
13
12
 
14
- def initialize(phase)
15
- BbDeploy::Config.configure_from_yaml('config/deploy.yml')
16
- BbDeploy::Config.set_heroku_fields!(phase)
13
+ def initialize(phase:)
14
+ BbDeploy::Config.set_dynamic_fields!(phase: phase)
17
15
  @phase = phase
18
16
  end
19
17
 
20
- # Environment inquiry methods
21
- %w(qa staging production).each do |phase|
22
- define_method("#{phase}?") { @phase == phase }
23
- end
24
-
25
18
  def deploy!
26
19
  BbDeploy::Git.check_git_status!
27
20
  check_access!
@@ -36,18 +29,6 @@ class BbDeploy::Deployer
36
29
 
37
30
  private
38
31
 
39
- def notify_eng_hub?
40
- BbDeploy::Config.application_name == "Clarity"
41
- end
42
-
43
- def dputs(*msgs)
44
- asterisks = "*" * 80
45
- puts asterisks
46
- puts(*msgs.map(&:to_s))
47
- puts asterisks
48
- end
49
-
50
-
51
32
  def current_branch
52
33
  BbDeploy::Git.current_branch(started_on_master?)
53
34
  end
@@ -55,7 +36,7 @@ class BbDeploy::Deployer
55
36
  def do_deploy
56
37
  branch = current_branch
57
38
 
58
- chat_broadcast(":alert: '#{ENV['USER']}' is deploying the #{BbDeploy::Config.application_name} branch '#{branch}' to '#{phase}' :alert:", phase: phase, notify_eng_hub: notify_eng_hub?)
39
+ chat_broadcast("'#{ENV['USER']}' is deploying the #{BbDeploy::Config.application_name} branch '#{branch}' to '#{phase}' ...", phase: phase, notify_eng_hub: true)
59
40
 
60
41
  do_heroku_deploy!
61
42
 
@@ -67,7 +48,7 @@ class BbDeploy::Deployer
67
48
  puts "You must now resolve any conflicts in the merge and then `git push origin master` ..."
68
49
  end
69
50
 
70
- chat_broadcast(":alertgreen: Deployment of the #{BbDeploy::Config.application_name} branch '#{branch}' to '#{phase}' completed! :alertgreen:", phase: phase, notify_eng_hub: notify_eng_hub?)
51
+ chat_broadcast("(successful) Deployment of the #{BbDeploy::Config.application_name} branch '#{branch}' to '#{phase}' completed!", phase: phase, notify_eng_hub: true)
71
52
  end
72
53
 
73
54
  def logger
@@ -75,7 +56,7 @@ class BbDeploy::Deployer
75
56
  end
76
57
 
77
58
  def check_access!
78
- unless BbDeploy::Heroku.has_access?(phase)
59
+ if BbDeploy::Heroku.has_access?(phase)
79
60
  exit_with_message("You do not have access to the #{BbDeploy::Config.application_name} #{phase} application!")
80
61
  end
81
62
  end
@@ -87,6 +68,7 @@ class BbDeploy::Deployer
87
68
 
88
69
  def do_heroku_deploy! # rubocop:disable all
89
70
  run_migrations = run_migrations?
71
+ stay_in_maint_mode = false
90
72
 
91
73
  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?")
92
74
 
@@ -98,7 +80,15 @@ class BbDeploy::Deployer
98
80
 
99
81
  push_release!
100
82
 
101
- run_migrations! if run_migrations
83
+ if run_migrations
84
+ started_at = Time.current
85
+ run_migrations!
86
+ time_spent = Time.zone.at(Time.current - started_at).getutc.strftime("%H:%M:%S")
87
+ # The only time started_on_master is non-nil is when creating a new staging branch
88
+ if started_on_master?
89
+ 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)
90
+ end
91
+ end
102
92
 
103
93
  if enter_maint_mode
104
94
  if stay_in_maint_mode
@@ -109,35 +99,26 @@ class BbDeploy::Deployer
109
99
  end
110
100
  end
111
101
 
112
- def run_migrations!
113
- started_at = Time.current
114
-
115
- chat_broadcast("Running migrations from #{BbDeploy::Config.application_name} branch '#{current_branch}' in #{phase} ...", phase: phase)
116
- logger.with_consolidated_logging { BbDeploy::Heroku.migrate_db!(phase) }
117
- chat_broadcast("Successfully ran migrations from #{BbDeploy::Config.application_name} branch '#{current_branch}' in #{phase}.", phase: phase)
118
-
119
- time_spent = Time.zone.at(Time.current - started_at).getutc.strftime("%H:%M:%S")
120
- # The only time started_on_master is non-nil is when creating a new staging branch
121
- if started_on_master?
122
- 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: notify_eng_hub?)
123
- end
124
- end
125
-
126
102
  def push_release!
127
103
  puts "Deploying ..."
128
104
  chat_broadcast("Pushing #{BbDeploy::Config.application_name} branch '#{current_branch}' to #{phase} ...", phase: phase)
129
105
  logger.with_consolidated_logging { puts(BbDeploy::Git.push_to_phase(phase)) }
130
106
  end
131
107
 
108
+ def run_migrations!
109
+ chat_broadcast("Running migrations from #{BbDeploy::Config.application_name} branch '#{current_branch}' in #{phase} ...", phase: phase)
110
+ logger.with_consolidated_logging { BbDeploy::Heroku.migrate_db! }
111
+ chat_broadcast("Successfully ran migrations from #{BbDeploy::Config.application_name} branch '#{current_branch}' in #{phase}.", phase: phase)
112
+ end
113
+
132
114
  def open_in_browser
133
115
  sleep 2 # because removing maint mode takes a couple seconds to propagate
134
116
  host_and_path =
135
117
  case phase
136
- when 'qa'; BbDeploy::Config.application_urls['qa']
137
- when 'staging'; BbDeploy::Config.application_urls['staging']
138
- when 'production'; BbDeploy::Config.application_urls['production']
118
+ when 'qa'; BbDeploy::Config.application_urls[:qa]
119
+ when 'staging'; BbDeploy::Config.application_urls[:staging]
120
+ when 'production'; BbDeploy::Config.application_urls[:production]
139
121
  end
140
-
141
122
  puts "Opening the site for inspection ..."
142
123
  BbDeploy::Task.run("open https://#{host_and_path}")
143
124
  end
@@ -157,21 +138,21 @@ class BbDeploy::Deployer
157
138
 
158
139
  def staging_checks
159
140
  if BbDeploy::Git.on_master?
160
- 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}?")
141
+ 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.)")
161
142
 
162
143
  if do_it
163
144
  date = Time.zone.today.to_s(:db).tr('-', '_')
164
- new_release_branch = "release_#{date}"
145
+ new_branch = "release_#{date}"
165
146
 
166
- if BbDeploy::Git.local_release(new_release_branch).present?
167
- exit_with_message("There already exists a local release branch named #{new_release_branch}!")
147
+ if BbDeploy::Git.local_release(new_branch).present?
148
+ exit_with_message("There already exists a local release branch named #{new_branch}!")
168
149
  end
169
150
 
170
- if BbDeploy::Git.remote_release(new_release_branch).present?
171
- exit_with_message("There already exists a remote release branch named #{new_release_branch}!")
151
+ if BbDeploy::Git.remote_release(new_branch).present?
152
+ exit_with_message("There already exists a remote release branch named #{new_branch}!")
172
153
  end
173
154
 
174
- BbDeploy::Git.push_release_branch!(new_release_branch)
155
+ # puts `git checkout -lb #{new_branch} && git push origin #{new_branch} -u`
175
156
 
176
157
  started_on_master!
177
158
  end
data/lib/bb_deploy/git.rb CHANGED
@@ -23,10 +23,6 @@ module BbDeploy::Git
23
23
  current_branch == 'master'
24
24
  end
25
25
 
26
- def push_release_branch!
27
- puts `git checkout -lb #{new_branch} && git push origin #{new_branch} -u`
28
- end
29
-
30
26
  def on_a_release_branch?
31
27
  current_branch.start_with?('release_')
32
28
  end
@@ -1,25 +1,18 @@
1
- require_relative './task'
2
-
3
1
  module BbDeploy::Heroku
4
2
  class << self
5
- def get_variable(phase, var_name)
6
- @heroku_env_vars ||= {}
7
- return @heroku_env_vars[var_name] if @heroku_env_vars[var_name]
8
- token = heroku_run("heroku config:get #{var_name} --remote #{phase}")
9
- if token.present?
10
- token = token.chomp
11
- @heroku_env_vars[var_name] = token.split.last
3
+ def set_dynamic_fields!(phase:)
4
+ BbDeploy::Config.configure do |config|
5
+ config.logentries_token = get_heroku_variable(phase, 'DEPLOY_LOG_TOKEN').freeze
6
+ config.slack_webhook_key = get_heroku_variable(phase, 'SLACK_WEBHOOK').freeze
12
7
  end
13
- @heroku_env_vars[var_name]
14
8
  end
15
9
 
16
10
  def last_release_sha(phase)
17
- heroku_run("heroku releases -n 25 --remote #{phase} | grep Deploy | head -n 1 | awk '{print $3}'")
11
+ heroku_run("heroku releases --remote #{phase} | grep Deploy | head -n 1 | awk '{print $3}'")
18
12
  end
19
13
 
20
14
  def has_access?(phase)
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./)
15
+ heroku_run("heroku info --remote #{phase} 2>&1") =~ /You do not have access/i
23
16
  end
24
17
 
25
18
  def migrate_db!(phase)
@@ -35,8 +28,8 @@ module BbDeploy::Heroku
35
28
 
36
29
  def heroku_run(*cmds)
37
30
  # Heroku Toolbelt uses Ruby 1.9, which requires clearing the RUBYOPT var ...
38
- puts "Running: #{cmds.map(&:inspect).join(", ")}"
39
- BbDeploy::Task.run(*cmds.map { |cmd| cmd =~ /heroku/ ? "export RUBYOPT='' && #{cmd}" : cmd })
31
+ puts "Running\n#{cmds}"
32
+ run(*cmds.map { |cmd| cmd =~ /heroku/ ? "export RUBYOPT='' && #{cmd}" : cmd })
40
33
  end
41
34
  end
42
35
  end
@@ -1,5 +1,5 @@
1
+ require 'slack-notifier'
1
2
  require 'le'
2
- require 'logger'
3
3
 
4
4
  # Helper file for Logging/Slack notifications
5
5
  module BbDeploy::Logger
@@ -39,7 +39,7 @@ module BbDeploy::Logger
39
39
  # Logs originating here will be found in the BB
40
40
  # Logentries account in the "Ruby Log" for each phase
41
41
  def logger
42
- @logger ||= BbDeploy::Config.logentries_token.present? ? Le.new(BbDeploy::Config.logentries_token) : Logger.new($stdout)
42
+ @logger ||= Le.new(BbDeploy::Config.logentries_token)
43
43
  end
44
44
  end
45
45
  end
@@ -48,11 +48,12 @@ module BbDeploy::Logger
48
48
  attachment = [
49
49
  {
50
50
  fallback: "Deploying to #{phase}",
51
- color: " ",
51
+ color: "good",
52
52
  fields: [
53
53
  {
54
54
  title: "Details",
55
- value: msg,
55
+ # Work the cuteness back in at some point ...
56
+ value: msg.gsub("(successful)", ":rocket:"), # .gsub("(hisham)", ":hisham:").gsub("(jusx)", ":jusx:")
56
57
  short: false
57
58
  }
58
59
  ]
@@ -1,3 +1,5 @@
1
+ require 'highline'
2
+
1
3
  module BbDeploy::Task
2
4
  class << self
3
5
  def run(*cmds)
@@ -6,6 +8,7 @@ module BbDeploy::Task
6
8
  result = cmds.map do |cmd|
7
9
  cmd_s = "==> \`#{cmd}\`"
8
10
  if dry_run
11
+ # rubocop:disable Rails/Output
9
12
  puts "DRY RUN ONLY"
10
13
  puts cmd_s
11
14
  else
@@ -21,7 +24,6 @@ module BbDeploy::Task
21
24
  msg = "\e[31m#{msg}\e[0m"
22
25
  msg.sub!(/'#{required_response}'/, "\e[47m'#{required_response}'\e[49m")
23
26
  end
24
- puts
25
27
  HighLine.new.ask(msg) =~ /\A#{required_response}\Z/i
26
28
  end
27
29
 
@@ -29,6 +31,7 @@ module BbDeploy::Task
29
31
 
30
32
  def with_timing(what)
31
33
  start = Time.current
34
+ # rubocop:disable Rails/Output
32
35
  puts
33
36
  puts "Commencing #{what} ..."
34
37
  result = yield
@@ -1,17 +1,15 @@
1
- require_relative '../bb_deploy'
2
-
3
1
  namespace :heroku do
4
2
  namespace :deploy do
5
3
  task qa: :environment do
6
- BbDeploy::Deployer.new('qa').deploy!
4
+ BbDeploy::Deployer.new(phase: 'qa').deploy!
7
5
  end
8
6
 
9
7
  task staging: :environment do
10
- BbDeploy::Deployer.new('staging').deploy!
8
+ BbDeploy::Deployer.new(phase: 'staging').deploy!
11
9
  end
12
10
 
13
11
  task production: :environment do
14
- BbDeploy::Deployer.new('production').deploy!
12
+ BbDeploy::Deployer.new(phase: 'production').deploy!
15
13
  end
16
14
  end
17
15
  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.0.4
4
+ version: 0.0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter van Wesep
@@ -9,76 +9,20 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2016-09-01 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rake
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: highline
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: le
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: slack-notifier
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
12
+ dependencies: []
69
13
  description:
70
14
  email: peter@brightbytes.net
71
15
  executables: []
72
16
  extensions: []
73
17
  extra_rdoc_files: []
74
18
  files:
75
- - lib/bb_deploy.rb
19
+ - LICENSE
20
+ - README.md
76
21
  - lib/bb_deploy/config.rb
77
22
  - lib/bb_deploy/deployer.rb
78
23
  - lib/bb_deploy/git.rb
79
24
  - lib/bb_deploy/heroku.rb
80
25
  - lib/bb_deploy/logger.rb
81
- - lib/bb_deploy/railtie.rb
82
26
  - lib/bb_deploy/task.rb
83
27
  - lib/tasks/deploy.rake
84
28
  homepage:
@@ -101,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
45
  version: '0'
102
46
  requirements: []
103
47
  rubyforge_project:
104
- rubygems_version: 2.5.1
48
+ rubygems_version: 2.2.2
105
49
  signing_key:
106
50
  specification_version: 4
107
51
  summary: Shared gem for deploying BrightBytes repositories
@@ -1,12 +0,0 @@
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
data/lib/bb_deploy.rb DELETED
@@ -1,4 +0,0 @@
1
- module BbDeploy
2
- require 'bb_deploy/railtie' if defined?(Rails)
3
- require 'bb_deploy/deployer'
4
- end