Module: BbDeploy::Heroku

Defined in:
lib/bb_deploy/heroku.rb

Class Method Summary collapse

Class Method Details

.get_variable(phase, var_name) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/bb_deploy/heroku.rb', line 5

def get_variable(phase, var_name)
  @heroku_env_vars ||= {}
  return @heroku_env_vars[var_name] if @heroku_env_vars[var_name]
  token = heroku_run("heroku config:get #{var_name} --remote #{phase}")
  if token.present?
    token = token.chomp
    @heroku_env_vars[var_name] = token.split.last
  end
  @heroku_env_vars[var_name]
end

.has_access?(phase) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/bb_deploy/heroku.rb', line 20

def has_access?(phase)
  heroku_info = heroku_run("heroku info --remote #{phase} 2>&1")
  !(heroku_info =~ /You do not have access/i || heroku_info =~ /Enter your Heroku credentials./)
end

.heroku_run(*cmds) ⇒ Object



36
37
38
39
40
# File 'lib/bb_deploy/heroku.rb', line 36

def heroku_run(*cmds)
  # Heroku Toolbelt uses Ruby 1.9, which requires clearing the RUBYOPT var ...
  puts "Running: #{cmds.map(&:inspect).join(", ")}"
  BbDeploy::Task.run(*cmds.map { |cmd| cmd =~ /heroku/ ? "export RUBYOPT='' && #{cmd}" : cmd })
end

.last_release_sha(phase) ⇒ Object



16
17
18
# File 'lib/bb_deploy/heroku.rb', line 16

def last_release_sha(phase)
  heroku_run("heroku releases -n 25 --remote #{phase} | grep Deploy | head -n 1 | awk '{print $3}'")
end

.migrate_db!(phase) ⇒ Object



25
26
27
28
29
30
# File 'lib/bb_deploy/heroku.rb', line 25

def migrate_db!(phase)
  heroku_run(
    "heroku run --size=PX rake db:migrate --remote #{phase}",
    "heroku restart --remote #{phase}" # necessary to not have the web server gag
  )
end

.toggle_maintenance(mode:, phase:) ⇒ Object



32
33
34
# File 'lib/bb_deploy/heroku.rb', line 32

def toggle_maintenance(mode:, phase:)
  Rake::Task["heroku:maint:#{mode}:#{phase}"].invoke
end