module BbDeploy::Heroku

Public Class Methods

get_variable(phase, var_name) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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:) click to toggle source
# File lib/bb_deploy/heroku.rb, line 32
def toggle_maintenance(mode:, phase:)
  Rake::Task["heroku:maint:#{mode}:#{phase}"].invoke
end