class Suspenders::Adapters::Heroku
Attributes
app_builder[R]
Public Class Methods
new(app_builder)
click to toggle source
# File lib/suspenders/adapters/heroku.rb, line 4 def initialize(app_builder) @app_builder = app_builder end
Public Instance Methods
create_heroku_pipeline()
click to toggle source
# File lib/suspenders/adapters/heroku.rb, line 63 def create_heroku_pipeline pipelines_plugin = `heroku plugins | grep pipelines` if pipelines_plugin.empty? puts "You need heroku pipelines plugin. Run: heroku plugins:install heroku-pipelines" exit 1 end heroku_app_name = app_builder.app_name.dasherize run_toolbelt_command( "pipelines:create #{heroku_app_name} \ -a #{heroku_app_name}-staging --stage staging", "staging", ) run_toolbelt_command( "pipelines:add #{heroku_app_name} \ -a #{heroku_app_name}-production --stage production", "production", ) end
create_heroku_pipelines_config_file()
click to toggle source
# File lib/suspenders/adapters/heroku.rb, line 59 def create_heroku_pipelines_config_file app_builder.template "app.json.erb", "app.json" end
create_production_heroku_app(flags)
click to toggle source
# File lib/suspenders/adapters/heroku.rb, line 35 def create_production_heroku_app(flags) app_name = heroku_app_name_for("production") run_toolbelt_command "create #{app_name} #{flags}", "production" end
create_staging_heroku_app(flags)
click to toggle source
# File lib/suspenders/adapters/heroku.rb, line 27 def create_staging_heroku_app(flags) rack_env = "RACK_ENV=staging" app_name = heroku_app_name_for("staging") run_toolbelt_command "create #{app_name} #{flags}", "staging" run_toolbelt_command "config:add #{rack_env}", "staging" end
provide_review_apps_setup_script()
click to toggle source
# File lib/suspenders/adapters/heroku.rb, line 50 def provide_review_apps_setup_script app_builder.template( "bin_setup_review_app.erb", "bin/setup_review_app", force: true, ) app_builder.run "chmod a+x bin/setup_review_app" end
set_heroku_rails_secrets()
click to toggle source
# File lib/suspenders/adapters/heroku.rb, line 41 def set_heroku_rails_secrets %w(staging production).each do |environment| run_toolbelt_command( "config:add SECRET_KEY_BASE=#{generate_secret}", environment, ) end end
set_heroku_remotes()
click to toggle source
# File lib/suspenders/adapters/heroku.rb, line 8 def set_heroku_remotes remotes = <<-SHELL.strip_heredoc #{command_to_join_heroku_app('staging')} #{command_to_join_heroku_app('production')} git config heroku.remote staging SHELL app_builder.append_file "bin/setup", remotes end
set_heroku_serve_static_files()
click to toggle source
# File lib/suspenders/adapters/heroku.rb, line 84 def set_heroku_serve_static_files %w(staging production).each do |environment| run_toolbelt_command( "config:add RAILS_SERVE_STATIC_FILES=true", environment, ) end end
set_up_heroku_specific_gems()
click to toggle source
# File lib/suspenders/adapters/heroku.rb, line 19 def set_up_heroku_specific_gems app_builder.inject_into_file( "Gemfile", %{\n\s\sgem "rails_stdout_logging"}, after: /group :staging, :production do/, ) end
Private Instance Methods
command_to_join_heroku_app(environment)
click to toggle source
# File lib/suspenders/adapters/heroku.rb, line 97 def command_to_join_heroku_app(environment) heroku_app_name = heroku_app_name_for(environment) <<-SHELL if heroku join --app #{heroku_app_name} &> /dev/null; then git remote add #{environment} git@heroku.com:#{heroku_app_name}.git || true printf 'You are a collaborator on the "#{heroku_app_name}" Heroku app\n' else printf 'Ask for access to the "#{heroku_app_name}" Heroku app\n' fi SHELL end
generate_secret()
click to toggle source
# File lib/suspenders/adapters/heroku.rb, line 114 def generate_secret SecureRandom.hex(64) end
heroku_app_name_for(environment)
click to toggle source
# File lib/suspenders/adapters/heroku.rb, line 110 def heroku_app_name_for(environment) "#{app_builder.app_name.dasherize}-#{environment}" end
run_toolbelt_command(command, environment)
click to toggle source
# File lib/suspenders/adapters/heroku.rb, line 118 def run_toolbelt_command(command, environment) app_builder.run( "heroku #{command} --remote #{environment}", ) end