Gems You Shouldn't Leave Development Without

24
Gems You Should Never Leave Development Without David Underwood

description

Learn about some of the things you should be thinking about before you deploy your new Ruby/Rails project to production.

Transcript of Gems You Shouldn't Leave Development Without

Page 1: Gems You Shouldn't Leave Development Without

Gems You Should Never Leave Development WithoutDavid Underwood

Page 2: Gems You Shouldn't Leave Development Without

Before We Start

Page 3: Gems You Shouldn't Leave Development Without

Development Gems!

Page 4: Gems You Shouldn't Leave Development Without

quiet_assetsMakes assets shut the hell up in development

Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2014-07-21 22:38:53 -0400

Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2014-07-21 22:38:53 -0400

Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2014-07-21 22:38:53 -0400

Started GET "/assets/jquery.ui.mouse.js?body=1" for 127.0.0.1 at 2014-07-21 22:38:53 -0400

Started GET "/assets/jquery.ui.sortable.js?body=1" for 127.0.0.1 at 2014-07-21 22:38:53 -0400

Started GET "/assets/jquery.ui.widget.js?body=1" for 127.0.0.1 at 2014-07-21 22:38:53 -0400

Started GET "/assets/jquery.ui.core.js?body=1" for 127.0.0.1 at 2014-07-21 22:38:53 -0400

Started GET "/assets/turbolinks.js?body=1" for 127.0.0.1 at 2014-07-21 22:38:53 -0400

Started GET "/assets/bootstrap/tab.js?body=1" for 127.0.0.1 at 2014-07-21 22:38:53 -0400

Started GET "/assets/bootstrap/alert.js?body=1" for 127.0.0.1 at 2014-07-21 22:38:53 -0400

Started GET "/assets/cocoon.js?body=1" for 127.0.0.1 at 2014-07-21 22:38:53 -0400

Started GET "/assets/tinymce/preinit.js?body=1" for 127.0.0.1 at 2014-07-21 22:38:53 -0400

Page 5: Gems You Shouldn't Leave Development Without

better_errorsAdds a much better error page for development.

Also a REPL if you add binding_of_caller too!

Page 6: Gems You Shouldn't Leave Development Without
Page 7: Gems You Shouldn't Leave Development Without

pry + pry-debuggerPry is a great alternative to IRB.

Pry-debugger adds your favourite debug commands:

» step

» next

» continue

» finish

Allows you to set breakpoints too.

Page 8: Gems You Shouldn't Leave Development Without

OK, Let's Talk Production

Page 9: Gems You Shouldn't Leave Development Without

Environment Management

Page 10: Gems You Shouldn't Leave Development Without

figaro# Gemfilegem 'figaro'

# config/application.ymlpusher_app_id: "2954"pusher_key: "7381a978f7dd7f9a1117"pusher_secret: "abdc3b896a0ffb85d373"

production: pusher_app_id: "5112" pusher_key: "ad69caf9a44dcac1fb28" pusher_secret: "83ca7aa160fedaf3b350"

# AnywhereFigaro.env.pusher_key

Page 11: Gems You Shouldn't Leave Development Without

dotenv# Gemfilegem 'dotenv'

# config.rurequire 'dotenv'Dotenv.load

# .envPUSHER_APP_ID=2954PUSHER_KEY=7381a978f7dd7f9a1117PUSHER_SECRET=abdc3b896a0ffb85d373

# AnywhereENV['PUSHER_KEY']

Page 12: Gems You Shouldn't Leave Development Without

Error Reporting

Page 13: Gems You Shouldn't Leave Development Without

exception_notification# Gemfilegem 'exception_notification'

# config/environments/production.rbWhatever::Application.config.middleware.use ExceptionNotification::Rack, email: { email_prefix: "[Oh Shiii] ", sender_address: %{"notifier" <[email protected]>}, exception_recipients: %w{[email protected]} }

Page 14: Gems You Shouldn't Leave Development Without

Exception Notification Services» Airbrake

» Errbit

» Honeybadger

» Rollbar

» Lots more

Ruby Toolbox has a great list: https://www.ruby-toolbox.com/categories/exception_notification

Page 15: Gems You Shouldn't Leave Development Without

Application Server

Page 16: Gems You Shouldn't Leave Development Without

What's Available?» WEBrick

» Thin

» Unicorn

» Passenger

» Puma

Go with Unicorn unless you have a reason not to

Don't use WEBrick in production

Page 17: Gems You Shouldn't Leave Development Without

Anything Else?How About... Middleware!

Page 18: Gems You Shouldn't Leave Development Without

rack-canonical-hostRedirect all requests to a specific host. Can also be used to force SSL. Great for custom domains on Heroku

# Gemfilegem 'rack-canonical-host'

# config.ru (Rails example)require ::File.expand_path('../config/environment', __FILE__)

use Rack::CanonicalHost, ENV['CANONICAL_HOST'], force_ssl: truerun YourRailsApp::Application

Page 19: Gems You Shouldn't Leave Development Without

rack-attackConnection whitelists, blacklists, and throttling. Stops misbehaving clients from even hitting your app code

# Gemfilegem 'rack-attack'

# config/application.rbconfig.middleware.use Rack::Attack

# config/initializers/rack-attack.rbclass Rack::Attack # your custom configuration...end

Page 20: Gems You Shouldn't Leave Development Without

rack-google-analyticsAdds an analytics code to every page of your app

# Gemfilegem 'rack-google-analytics'

# config.ruuse Rack::GoogleAnalytics, tracker: 'UA-xxxxxx-x'

Page 21: Gems You Shouldn't Leave Development Without

Heroku

Page 22: Gems You Shouldn't Leave Development Without

rails_12factorTells Rails to serve assets. This is usually delegated to the routing webserver (e.g. nginx or apache)

Redirects logs to stdout rather than logfiles

Stops Heroku complaining every time you deploy

# Gemfileruby '2.0'gem 'rails_12factor'

Page 23: Gems You Shouldn't Leave Development Without

Personal Favourites?

Page 24: Gems You Shouldn't Leave Development Without

Thanks!