Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bootchecking for rails applications #1124

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions lib/language_pack/helpers/rails_bootcheck.rb
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
12 changes: 11 additions & 1 deletion lib/language_pack/rails2.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "fileutils"
require "language_pack"
require "language_pack/rack"
require "language_pack/helpers/rails_bootcheck"

# Rails 2 Language Pack. This is for any Rails 2.x apps.
class LanguagePack::Rails2 < LanguagePack::Ruby
Expand All @@ -19,6 +20,7 @@ def self.use?
def initialize(*args)
super(*args)
@rails_runner = LanguagePack::Helpers::RailsRunner.new
@bootcheck = LanguagePack::Helpers::RailsBootcheck.new
end

def name
Expand All @@ -29,7 +31,7 @@ def default_env_vars
{
"RAILS_ENV" => "production",
"RACK_ENV" => "production"
}
}.merge(bootcheck_env_vars)
end

def default_config_vars
Expand Down Expand Up @@ -60,6 +62,7 @@ def compile
instrument "rails2.compile" do
install_plugins
super
@bootcheck.call
end
end

Expand Down Expand Up @@ -106,4 +109,11 @@ def setup_profiled(*args)
end
end

def bootcheck_env_vars
value = env("HEROKU_RAILS_BOOTCHECK_ENABLE")

return {} unless value || new_app?

{ "HEROKU_RAILS_BOOTCHECK_ENABLE" => value || "1" }
end
end