I'm a big fan of Ruby On Rails since 2012. It's an amazing framework that allows developers to build fantastic apps. And if few years ago there was a hype over RoR, now it's a proven by time tool.
Lately, I've been experimenting with Ruby On Rails and Heroku. It's a cloud platform (PaaS) for web applications. I think that Heroku is a great tool for startups and SaaS software development and I'd like to share with you some things I learned about Heroku.
1. Heroku and Rails Applications
Great platform for great applications
2. What is Heroku?
Heroku is a cloud platform that lets build, deliver, monitor and scale
web applications.
Developer-centric / App-centric / Production-centric
Ruby Python PHP Node.js Java Go Scala Clojure
3. Why use Heroku?
8 Billion Requests per Day 5+ Million Apps Created 150+ Add-on Services
Easy to start, easy to use Scalability out of the box Manageable expenses
4. Getting started
Install Heroku Toolbelt
It’s a cross-platform Command Line Interface
Prepare your app:
Create Heroku application: `heroku create` command
Define a Procfile: let Heroku know, how to run the app
Fix app dependencies: a few additional line in your Gemfile
Run app locally: `heroku local web` command
Deploy to Heroku cloud:
`git push heroku master` command
Full guide at Heroku Dev Center
5. Procfile
A Procfile is a mechanism for declaring what commands are run on the Heroku
platform.
Example of Procfile
web: bundle exec puma -C config/puma.rb
worker: bundle exec rake jobs:work
Tip: Use Puma web server for your apps on Heroku.
6. The Twelve-Factor App
The twelve-factor app a methodology for building software-as-a-service apps.
I. Codebase
One codebase tracked in revision control, many
deploys
II. Dependencies
Explicitly declare and isolate dependencies
III. Config
Store config in the environment
IV. Backing Services
Treat backing services as attached resources
V. Build, release, run
Strictly separate build and run stages
VI. Processes
Execute the app as one or more stateless
processes
VII. Port binding
Export services via port binding
VIII. Concurrency
Scale out via the process model
IX. Disposability
Maximize robustness with fast startup and
graceful shutdown
X. Dev/prod parity
Keep development, staging, and production as
similar as possible
XI. Logs
Treat logs as event streams
XII. Admin processes
Run admin/management tasks as one-off
processes
7. Deployment
Heroku supports 3 major ways to deploy your application to the cloud:
Heroku Git
Deploy the application with a simple command: `git push heroku master`
GitHub
Connect GitHub repository to your Heroku app. Whenever somebody pushes
to GitHub, apps will be updated.
DropBox
Connect Dropbox folder. Initiate deploys from Heroku Dashboard.
8. Dynos limitations
Free dyno is great for development and testing:
It goes to sleep after 30 minutes of inactivity. Should sleep at least 6 hours a day.
Hobby dyno is great small projects:
It costs $7 per month, never sleeps, but not scalable.
If you want more - use professional dynos.
Price starts from $25 per month. Full set of features: scalability, metrics, fast
builds, etc.
Tip: Use `heroku-deflater` gem on production to enable compression and other
optimizations.
9. What’s next?
Getting Started with Ruby on Heroku
Getting Started with Rails 4.x on Heroku
How Heroku Works
Heroku Dev Center: Reference