Last active
March 26, 2021 19:43
-
-
Save craigmcnamara/4ab2ff65a4876b361890c4a4c09a52e1 to your computer and use it in GitHub Desktop.
A container config debugger in Ruby and Sinatra
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
# A utility app to debug the Docker on AWS. | |
# | |
require 'sinatra' | |
require 'active_record' | |
require 'redis' | |
configure do | |
use Rack::CommonLogger, $STDOUT | |
end | |
get '/db' do | |
# Uses DATABASE_URL by default | |
ActiveRecord::Base.establish_connection | |
$db = ActiveRecord::Base.connection | |
erb :db | |
end | |
# Careful, this exposes secrets by dumping the env | |
# get '/env' do | |
# erb :env | |
# end | |
get '/redis' do | |
redis = Redis.new(url: ENV['REDIS_URL']) | |
redis.echo('Redis is OK') | |
end | |
get '/error' do | |
raise 'Boom' | |
end | |
get '/ruby-version' do | |
ENV['RUBY_VERSION'] | |
end | |
# Catchall route | |
get '/*' do | |
'Pong' | |
end | |
__END__ | |
@@ db | |
DB Connection Test | |
<%= $db.execute('SELECT COUNT(*) pages').first %> | |
@@ env | |
<table> | |
<% ENV.each do |k, v| %> | |
<tr> | |
<td><%= k %></td> | |
<td><%= v %></td> | |
</tr> | |
<% end %> | |
</table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment