First Deploy…

Hey friends this blog is about my first ever deployment of app on the Heroku , and how I did it. I also faced some major head scratchy problems while deploying app. And how I resolved them.

First question comes to our mind is that, what is Heroku? So Heroku is all we need to deploy our app. Its a most popular cloud platform where we can put our applications and all our work on their website and they give us the URL basically our apps internet address to see our app. Now the our app will display to everyone and anyone can view it on their computer by simply going to is web address.

Curious to know how to do that? Lets go we will see step by step how to do this:

First of all you need to develop or create the application. after building the app you need to save the app files backup on the bitbucket.org. Where create an account and save all our apps data as a new repository. Where they calls repository or repo to the backup file of app . It’s very useful for any future requirement if in case we lost our apps files. Don’t worry about it because we already taken backup of our apps all files.

Now we are ready to start with heroku, first signup to it and after successfully signup open our account. We will find the various languages to getting start with like Java, Ruby, Python, PHP an so on select the on on which we builded our app.

My app was build in Ruby language so I select the “Get started with Ruby guide”, now the guide with all codes and descriptions will open. Let’s follow one by one:

Intoduction:

This tutorial will have you deploying a Ruby app in minutes.

Hang on for a few more minutes to learn how it all works, so you can make the most out of Heroku.

The tutorial assumes that you have and if havn’t then do it first:

  • a free Heroku account.
  • Ruby 2.2.4 installed locally — see the installation guides for Ruby and Rails on OS X, Windows, andLinux.
  • Bundler installed locally — run gem install bundler.

Set up:

In this step you will install the Heroku Toolbelt. This provides you access to the Heroku Command Line Interface (CLI), which can be used for managing and scaling your applications and add-ons. A key part of the toolbelt is the heroku local command, which can help in running your applications locally. You will find the tag as same as following option for downloading the toolbelt -

Download Heroku Toolbelt for…

Once installed, you can use the heroku command from your command shell.

Log in using the email address and password you used when creating your Heroku account:

$heroku login
Enter your Heroku credentials.
Email: ruby@example.com
Password:
...

Note that you won’t see any password while entering it then after entering password simply press enter key. Also authenticating is required to allow both the heroku and git commands to operate.

Note that if you’re behind a firewall that requires use of a proxy to connect with external HTTP/HTTPS services, you can set the HTTP_PROXY or HTTPS_PROXY environment variables in your local development environment before running the heroku command.

Prepare the app:

In this step, you will prepare application that can be deployed. We need to save our latest changes and make commit to them in the gits repository and push the changes to the master branch of the repo.

Execute the following commands to clone the sample application:

$ cd our/project/directory 
$ git init
$ git add -A
$ git commit -m "final commit"
$ git status
On branch master
nothing to commit, working directory clean
(note if you are already on master branch)

When you have your project at a point that you want to share, you have to push it upstream on gits cloud. The command for this is simple: git push [remote-name] [branch-name]. If you want to push your master branch to your origin server , then you can run this to push any commits you’ve done back up to the server:

$ git push origin master

You now have a functioning git repository that contains a application.

Deploy the app:

n this step you will deploy the app to Heroku.

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

$ heroku create
Creating polar-inlet-4930... done, stack is cedar-14
http://polar-inlet-4930.herokuapp.com/ | https://git.heroku.com/polar-inlet-4930.git
Git remote heroku added

As git and Heroku works together so when you create an app, a git remote (called heroku) is also created and associated with your local git repository.

Heroku generates a random name (in this case polar-inlet-4930) for your app, or you can pass a parameter to specify your own app name.

Now deploy your code:

$ git push heroku master
Fetching repository, done.
Counting objects: 10, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 876 bytes | 0 bytes/s, done.
Total 6 (delta 4), reused 0 (delta 0)
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.2.4
remote: -----> Installing dependencies using 1.7.12
remote: Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
remote: Fetching gem metadata from https://rubygems.org/...........
remote: Fetching additional metadata from https://rubygems.org/..
remote: Using rake 10.4.2
....
remote: Bundle completed (38.43s)
remote: Cleaning up the bundler cache.
remote: -----> Preparing app for Rails asset pipeline
remote: Running: rake assets:precompile
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote: Default types for Ruby -> console, rake, worker
remote:
remote: -----> Compressing... done, 30.7MB
remote: -----> Launching... done, v16
remote: https://pacific-river-8854.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To git@heroku.com:polar-inlet-4930.git
2e435c5..035d5f5 master -> master

The application is now deployed.

Now visit the app at the URL generated by its app name. As a handy shortcut, you can open the website as follows:

$ heroku open

After completing this step we can check our app on the generated url by heroku. But there are still many steps are given in th heroku’s guide but don’t worry about them because for now our main aim is to deploy the app and we just did it.

But still you will find some errors while running the app on web. I also was stuck after this step of deployment and faced the errors again and again but finally I made it with help of one of my colleague. It was so simple just had to run simple command:

$ heroku run rake db:migrate
Running `rake db:migrate` attached to terminal... up, run.3559
Migrating to CreateWidgets (20140707111715)
== 20140707111715 CreateWidgets: migrating ====================================
-- create_table(:widgets)
-> 0.0244s
== 20140707111715 CreateWidgets: migrated (0.0247s) ===========================

This is for to run the migrations for the database. The issue was simple I had deployed the app but not created the database for app on the heroku;s server that’s why I was facing the same errors. Finally the app started working fine.

So these are the simple steps to deploy your app using Git and Heroku.

Hope you liked my blog if have any suggestions please tell me.

Thank you for reading.