Class: Code42Template::Adapters::Heroku
- Inherits:
-
Object
- Object
- Code42Template::Adapters::Heroku
- Defined in:
- lib/code42template/adapters/heroku.rb
Constant Summary collapse
- HEROKU_BUILDPACK_URLS =
%w( heroku/nodejs heroku/ruby https://github.com/febeling/webpack-rails-buildpack.git )
Instance Method Summary collapse
- #configure_heroku_buildpacks ⇒ Object
- #create_deploy_script ⇒ Object
- #create_heroku_apps(flags) ⇒ Object
- #create_heroku_pipeline ⇒ Object
- #create_production_heroku_app(flags) ⇒ Object
- #create_review_apps_setup_script ⇒ Object
- #create_staging_heroku_app(flags) ⇒ Object
-
#initialize(app_builder) ⇒ Heroku
constructor
A new instance of Heroku.
- #set_heroku_application_host ⇒ Object
- #set_heroku_rails_environment ⇒ Object
- #set_heroku_rails_secrets ⇒ Object
- #set_heroku_remotes ⇒ Object
- #set_heroku_serve_static_files ⇒ Object
- #update_readme_with_deploy ⇒ Object
Constructor Details
#initialize(app_builder) ⇒ Heroku
Returns a new instance of Heroku.
10 11 12 |
# File 'lib/code42template/adapters/heroku.rb', line 10 def initialize(app_builder) @app_builder = app_builder end |
Instance Method Details
#configure_heroku_buildpacks ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/code42template/adapters/heroku.rb', line 109 def configure_heroku_buildpacks %w(staging production).each do |environment| app_name = heroku_app_name_for(environment) run_toolbelt_command("buildpacks:clear -a #{app_name}", environment) HEROKU_BUILDPACK_URLS.each do |buildpack_url| run_toolbelt_command( "buildpacks:add #{buildpack_url} -a #{app_name}", environment ) end end end |
#create_deploy_script ⇒ Object
19 20 21 22 |
# File 'lib/code42template/adapters/heroku.rb', line 19 def create_deploy_script @app_builder.copy_file "bin_deploy", "bin/deploy" @app_builder.run "chmod a+x bin/deploy" end |
#create_heroku_apps(flags) ⇒ Object
14 15 16 17 |
# File 'lib/code42template/adapters/heroku.rb', line 14 def create_heroku_apps(flags) create_staging_heroku_app(flags) create_production_heroku_app(flags) end |
#create_heroku_pipeline ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/code42template/adapters/heroku.rb', line 95 def create_heroku_pipeline 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_production_heroku_app(flags) ⇒ Object
65 66 67 68 69 |
# File 'lib/code42template/adapters/heroku.rb', line 65 def create_production_heroku_app(flags) app_name = heroku_app_name_for('production') run_toolbelt_command "create #{app_name} #{flags}", "production" end |
#create_review_apps_setup_script ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/code42template/adapters/heroku.rb', line 86 def create_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 |
#create_staging_heroku_app(flags) ⇒ Object
59 60 61 62 63 |
# File 'lib/code42template/adapters/heroku.rb', line 59 def create_staging_heroku_app(flags) app_name = heroku_app_name_for('staging') run_toolbelt_command "create #{app_name} #{flags}", "staging" end |
#set_heroku_application_host ⇒ Object
133 134 135 136 137 138 139 140 |
# File 'lib/code42template/adapters/heroku.rb', line 133 def set_heroku_application_host %w(staging production).each do |environment| run_toolbelt_command( "config:add APPLICATION_HOST=#{heroku_app_name}-#{environment}.herokuapp.com", environment, ) end end |
#set_heroku_rails_environment ⇒ Object
80 81 82 83 84 |
# File 'lib/code42template/adapters/heroku.rb', line 80 def set_heroku_rails_environment %w(staging production).each do |environment| run_toolbelt_command("config:add RAILS_ENV=production", environment) end end |
#set_heroku_rails_secrets ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/code42template/adapters/heroku.rb', line 71 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 ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/code42template/adapters/heroku.rb', line 48 def set_heroku_remotes remotes = <<~SHELL #{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 ⇒ Object
124 125 126 127 128 129 130 131 |
# File 'lib/code42template/adapters/heroku.rb', line 124 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 |
#update_readme_with_deploy ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/code42template/adapters/heroku.rb', line 24 def update_readme_with_deploy instructions = <<~MARKDOWN ## Deploying If you have previously run the `./bin/setup` script, you can deploy to staging and production with: $ ./bin/deploy staging $ ./bin/deploy production We currently use the following buildpacks: - heroku/nodejs - heroku/ruby - https://github.com/febeling/webpack-rails-buildpack.git Please be sure to configure these buildpacks in the same sequence presented here in both staging and production, or else the deploy will not work. MARKDOWN @app_builder.append_file "README.md", instructions end |