Skip to content

Instantly share code, notes, and snippets.

@craigmcnamara
Last active March 26, 2021 19:43
Show Gist options
  • Save craigmcnamara/4ab2ff65a4876b361890c4a4c09a52e1 to your computer and use it in GitHub Desktop.
Save craigmcnamara/4ab2ff65a4876b361890c4a4c09a52e1 to your computer and use it in GitHub Desktop.
A container config debugger in Ruby and Sinatra
# 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