BogoToBogo
  • Home
  • About
  • Big Data
  • Machine Learning
  • AngularJS
  • Python
  • C++
  • go
  • DevOps
  • Kubernetes
  • Algorithms
  • More...
    • Qt 5
    • Linux
    • FFmpeg
    • Matlab
    • Django 1.8
    • Ruby On Rails
    • HTML5 & CSS

Deploy Rails 4.x App to Heroku 2020

RubyOnRails_logo




Bookmark and Share





bogotobogo.com site search:





Publishing / Deploying our app to Heroku

Deploying applications to Heroku generally means pushing an app to Heroku using Git.





Heroku account

Heroku provides simple service that can be used to host Ruby on Rails applications.

We'll be able to host our app on Heroku on their free-tier, and we need a Heroku account.

Head to https://www.heroku.com/, click "Sign Up" and create an account.

SignUpForFree.png

The starter documentation for Heroku is available at: quickstart.

RubyGetStarted.png



Local Machine Setup - Heroku Toolbelt

Now we need to download a Toolbelt from https://toolbelt.heroku.com/ and set it up on our computer.

It provides us access to the Heroku Command Line Interface (CLI), which can be used for managing and scaling our applications and add-ons. A key part of the toolbelt is the heroku local command, which can help in running our applications locally.

ToolbeltForUbuntu.png $ sudo wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh

It gives us the following:

  1. Heroku client - CLI tool for creating and managing Heroku apps.
  2. Foreman - an easy option for running our apps locally.
  3. Git - revision control and pushing to Heroku.

The install script will add our repository and key to our apt sources and then have apt install the heroku and foreman packages from it. The heroku command line client will be installed into /usr/local/heroku and /usr/local/heroku/bin will be added to our PATH.

$ which heroku
/usr/local/heroku/bin/heroku

Once installed, we'll have access to the heroku command from our command shell. Log in using the email address and password we used when creating your Heroku account:

$ heroku login
...
heroku-cli: Installing Toolbelt v4... done
For more information on Toolbelt v4: https://github.com/heroku/heroku-cli
heroku-cli: Adding dependencies... done
heroku-cli: Installing core plugins... done
Enter your Heroku credentials.
Email: pygoogle@aol.com
Password (typing will be hidden): 
Logged in as pygoogle@aol.com





Deploying our app

At this point, we can test using the cloned app repo from Heroku.

But we're going to use our own app we built: Facebook and Twitter Authentication using Omniauth oauth2. The repo is Rails4-PyGoogle.

In this step we will deploy the app to Heroku.

Create an app on Heroku, which prepares Heroku to receive our source code.

k@laptop:~/Rails4-PyGoogle$ git remote -v
origin	https://github.com/PyGoogle/Rails4-PyGoogle.git (fetch)
origin	https://github.com/PyGoogle/Rails4-PyGoogle.git (push)

k@laptop:~/Rails4-PyGoogle$ heroku create
Creating app... done, stack is cedar-14
https://agile-fjord-1135.herokuapp.com/ | https://git.heroku.com/agile-fjord-1135.git

k@laptop:~/Rails4-PyGoogle$ git remote -v
heroku	https://git.heroku.com/agile-fjord-1135.git (fetch)
heroku	https://git.heroku.com/agile-fjord-1135.git (push)
origin	https://github.com/PyGoogle/Rails4-PyGoogle.git (fetch)
origin	https://github.com/PyGoogle/Rails4-PyGoogle.git (push)

Note that the heroku create command added remote repository to our git.

Now, we want to deploy our code:

k@laptop:~/Rails4-PyGoogle$ git push heroku master
Counting objects: 277, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (252/252), done.
Writing objects: 100% (277/277), 390.23 KiB | 0 bytes/s, done.
Total 277 (delta 14), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.1.3
remote: -----> Installing dependencies using bundler 1.9.7
remote:        Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
...
remote: -----> Discovering process types
remote:        Procfile declares types     -> web
remote:        Default types for buildpack -> console, rake, worker
remote: 
remote: -----> Compressing... done, 32.7MB
remote: -----> Launching...
remote:        Released v5
remote:        https://agile-fjord-1135.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy.... done.
To https://git.heroku.com/agile-fjord-1135.git
 * [new branch]      master -> master

The application is now deployed.

Now visit the app at the URL generated by its app name (https://agile-fjord-1135.herokuapp.com/). As a handy shortcut, we can open the website as follows:

k@laptop:~/Rails4-PyGoogle$ heroku open
Opening agile-fjord-1135... done
k@laptop:~/Rails4-PyGoogle$ Created new window in existing browser session.

Deployed but I got an error:

ApplicationError.png

On local, it's fine in dev env:

LocalRunOK.png

So, need to check the log:

k@laptop:~/Rails4-PyGoogle$ heroku logs
...
 /app/vendor/ruby-2.1.3/lib/ruby/2.1.0/open-uri.rb:36:in `initialize': No such file or directory @ rb_sysopen - /app/config/application_local.yml (Errno::ENOENT)
...

My case is special because the application_local was not pushed because .gitignore told so.

To fix the problem, I remove that line in .gitignore, and added and committed. Then, issued the following commands as we did earlier:

$ git push heroku master
$ heroku create

Now it seems to be working fine:

Heroku-deploy-working.png










Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization

YouTubeMy YouTube channel

Sponsor Open Source development activities and free contents for everyone.

Thank you.

- K Hong






Sponsor Open Source development activities and free contents for everyone.

Thank you.

- K Hong







Ruby on Rails



Ruby On Rails Home

Ruby - Input/Output, Objects, Load

Ruby - Condition (if), Operators (comparison/logical) & case statement

Ruby - loop, while, until, for, each, (..)

Ruby - Functions

Ruby - Exceptions (raise/rescue)

Ruby - Strings (single quote vs double quote, multiline string - EOM, concatenation, substring, include, index, strip, justification, chop, chomp, split)

Ruby - Class and Instance Variables

Ruby - Class and Instance Variables II

Ruby - Modules

Ruby - Iterator : each

Ruby - Symbols (:)

Ruby - Hashes (aka associative arrays, maps, or dictionaries)

Ruby - Arrays

Ruby - Enumerables

Ruby - Filess

Ruby - code blocks and yield

Rails - Embedded Ruby (ERb) and Rails html

Rails - Partial template

Rails - HTML Helpers (link_to, imag_tag, and form_for)

Layouts and Rendering I - yield, content_for, content_for?

Layouts and Rendering II - asset tag helpers, stylesheet_link_tag, javascript_include_tag

Rails Project

Rails - Hello World

Rails - MVC and ActionController

Rails - Parameters (hash, array, JSON, routing, and strong parameter)

Filters and controller actions - before_action, skip_before_action

The simplest app - Rails default page on a Shared Host

Redmine Install on a Shared Host

Git and BitBucket

Deploying Rails 4 to Heroku

Scaffold: A quickest way of building a blog with posts and comments

Databases and migration

Active Record

Microblog 1

Microblog 2

Microblog 3 (Users resource)

Microblog 4 (Microposts resource I)

Microblog 5 (Microposts resource II)

Simple_app I - rails html pages

Simple_app II - TDD (Home/Help page)

Simple_app III - TDD (About page)

Simple_app IV - TDD (Dynamic Pages)

Simple_app V - TDD (Dynamic Pages - Embedded Ruby)

Simple_app VI - TDD (Dynamic Pages - Embedded Ruby, Layouts)

App : Facebook and Twitter Authentication using Omniauth oauth2

Authentication and sending confirmation email using Devise

Adding custom fields to Devise User model and Customization

Devise Customization 2. views/users

Rails Heroku Deploy - Authentication and sending confirmation email using Devise

Deploying a Rails 4 app on CentOS 7 production server with Apache and Passenger I

Deploying a Rails 4 app on CentOS 7 production server with Apache and Passenger II

OOPS! Deploying a Rails 4 app on CentOS 7 production server with Apache and Passenger (Trouble shooting)











Contact

BogoToBogo
contactus@bogotobogo.com

Follow Bogotobogo

About Us

contactus@bogotobogo.com

YouTubeMy YouTube channel
Pacific Ave, San Francisco, CA 94115

Pacific Ave, San Francisco, CA 94115

Copyright © 2024, bogotobogo
Design: Web Master