forked from heroku/heroku-buildpack-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bootchecking for rails applications
Adds "RailsBootcheck" to the Rails buildpack. RailsBootcheck attempts to load your rails application and will fail the the build of your application if it is unable to load. This can help prevent scenarios where you can accidentally ship a version of your application that cannot boot properly. Which will lead to errors as the application is released and traffic is routed to it. You can opt-in to this feature via the `HEROKU_RAILS_BOOTCHECK_ENABLE` variable, new rails applications will have this variable set by default. You can opt-out of this feature via the `HEROKU_RAILS_BOOTCHECK_DISABLE` variable. Closes heroku#1120
- Loading branch information
Showing
2 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
class LanguagePack::Helpers::RailsBootcheck | ||
include LanguagePack::ShellHelpers | ||
|
||
def initialize(timeout = 65) | ||
@timeout = timeout | ||
end | ||
|
||
def call | ||
return unless opted_in? && !opted_out? | ||
|
||
topic("Bootchecking rails application") | ||
|
||
process = ProcessSpawn.new( | ||
"rails runner 'puts Rails.env'", | ||
user_env: true, | ||
timeout: @timeout, | ||
file: "./.heroku/ruby/compile/rails_bootcheck.txt" | ||
) | ||
|
||
if process.timeout? | ||
failure("timeout", process.output) | ||
elsif !process.success? | ||
failure("failure", process.output) | ||
end | ||
end | ||
|
||
private | ||
|
||
def failure(type, output) | ||
message = String.new("Bootchecking rails application #{type}\n") | ||
message << "set HEROKU_RAILS_BOOTCHECK_DISABLE=1 to disable this feature\n" | ||
|
||
if !output.empty? | ||
message << "\n" | ||
message << output | ||
end | ||
|
||
error(message) | ||
end | ||
|
||
def opted_in? | ||
env("HEROKU_RAILS_BOOTCHECK_ENABLE") | ||
end | ||
|
||
def opted_out? | ||
env("HEROKU_RAILS_BOOTCHECK_DISABLE") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters