DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Frameworks
  4. Deploying a Sinatra App to Heroku

Deploying a Sinatra App to Heroku

Andy Hawthorne user avatar by
Andy Hawthorne
·
Feb. 13, 13 · Interview
Like (0)
Save
Tweet
Share
3.59K Views

Join the DZone community and get the full member experience.

Join For Free

Heroku is a cloud application platform that is designed to take the worry out of server administration. You just build your app, push it to Heroku via Git, and relax. What about deploying a Sinatra app though? Let’s see…

If you followed along with my post about building a data driven app with Sinatra you might be ready to try a deployment. Since Sinatra is a Ruby app, deployment it not quite as straightforward as say, a PHP app, but it’s still not hard.

Getting started with Sinatra…

If you are coming to Sinatra from PHP, I wrote an article for Rubysource that shows you how to build a blog app with Sinatra.

You will need a (free) account at Heroku.

Assuming that you are happy with your app locally, the next thing to do is make sure you have a couple of files:

  • Gemfile
  • config.ru

The Gemfile I described in the post above includes references to all the Ruby gems used in the app:

source :rubygems
gem 'sinatra'
gem 'rdiscount'
gem 'data_mapper'
gem 'dm-migrations'
gem 'pony'
gem 'dm-postgres-adapter', :group => :production
gem 'dm-sqlite-adapter', :group => :development
group :production do
gem 'pg', '0.14.1'
end

You may not need some of these: rdiscount, and Pony for example. I’ll discuss those in a later post. Take note of the groups for production and development. Heroku doesn’t support Sqlite.

Sinatra is a Rack app, but Heroku has no problems with those. We just need a file to explain how we want our app to run:

In config.ru you need the following:

require './main'
run Sinatra::Application

You deploy to Heroku via Git, the source code management system. You can initialise a Git repository from the command line:

git init

Install the Heroku Gem

You will also need the Heroku gem:

gem install heroku

SSH Keys

You will need to create SSH keys. You can learn how to do that here

While you are on the command line, you will need to connect your keys to Heroku for secure communication between your computer at Heroku:

heroku keys:add

You’ll be asked to add the credentials that you created your Heroku account with.

Create the Heroku App

Back on the command line do:

heroku create nameofapp

Where nameofapp is what ever name you want for your app, bearing in mind that that Heroku will create your app with a url like this: nameofapp.herokuapp.com.

Then, assuming that you have committed your latest updates, you can do:

git push heroku master

You’ll see Heroku receive the push, compress files, install the Ruby gems needed, and then, with any luck, deploy your app.

All you need to do now, is continue to develop your app, commit, and the Git push to Heroku to deploy.

 



app Sinatra (software)

Published at DZone with permission of Andy Hawthorne, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Web Application Architecture: The Latest Guide
  • Top 10 Secure Coding Practices Every Developer Should Know
  • Data Mesh vs. Data Fabric: A Tale of Two New Data Paradigms
  • Public Cloud-to-Cloud Repatriation Trend

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: