The Gluster Blog

Gluster blog stories provide high-level spotlights on our users all over the world

How Git, heroku, and your laptop work together to coordinate decentralized code, sites, and deployments.

Gluster
2012-05-07

My first time playing with heroku was very cool, but mystifying – it wasn’t clear how or why it was that I needed to run “git init”, and why I was “pushing” code to heroku.  As a java developer, I’m used to setting up a tomcat server, dropping a jar in some random folder, and then praying to see something on localhost:8080.  Heroku is much more elegant – it uses the same tested model for commiting code (git), as it does for committing deployments !

At first this seems confusing, because we associate git only as a tool for managing source code (some of us only use git in conjunction with github, and have never fathomed the idea that we can use git to send runnable code to the cloud).

So, I was forced to decouple my notion of “git” as a version control tool from “git” as a generic source code commisioning utility, when I decided I wanted to experiement with deploying a blog (using the excellent 5-minute toto blogging tool : http://www.rubyinside.com/deploy-blog-with-toto-and-heroku-2962.html), that others could help and collaborate on.

I quickly found that I didn’t fully understand heroku’s model.

So … Here is a visual explanation of the way it all works :   The commands are labelled edges.  The arrows represent the flow of information.  When you clone an app, you get its contents from github.  When you create a heroku app, you get a new app name and its associated meta-data from heroku, which is associated with your account (I assume there is a small shred of information stored locally on your machine regarding this, but it is trivial and can easily be re-retrieved from the heroku servers from any other machine, once reinstall the heroku toolbelt and it learns your heroku account credentials).  Thus, there is very little essential application “state” saved on your machine, in fact there is none.

The mystery about this all is simply that git doesn’t care how many repos you associate it with !  You can push to github and heroku at the same time.  Each repo is independent. 

 So : A web app that is deployed on heroku, but source-hosted at github, might be created and maintained in a way that looks like this – where the “circles” represent machines, and the “arrows” represent the flow of information :

Must-knows for using github, git, and heroku together:
1) Everyone knows this already, but just to be complete : “heroku create” is the normal “first step”.  You create an application.  This registers a new app with heroku.  
 Heroku returns back an application URL to your command line prompt.  If you already “have” an application, this step is unnecessary.  See the next step to understand why.

2) Once you create an app, you push code to the heroku server’s under the git branch of that app. 

Heroku uses git for code deployment.  So… what if your code is already on git ?


3) Git lets you have multiple repositories !  The “git push” command actually can take 2 arguments – a repo, and a branch.  Thus, when we deploy 

git push heroku master

We are actually pushing the master branch to heroku.  We can also push to git using :

git push origin master, if the origin of source is from git.

The punchline : You can easily reproduce your environment for pushing code to heroku, and pulling it from github, on multiple or any machines as follows –


1) use heroku to add your public keys : 


jaylinux@ubuntu:~$ heroku keys:add
Found the following SSH public keys:                                                                          
1) github_rsa.pub                                                                                             
2) id_rsa.pub                                                                                                 
Which would you like to use with your Heroku account? 2
2) git clone your project from the git repo. 


3) git add your (already existing) heroku app to your git configuration as a 2nd remote repository : 


git add remote heroku git@heroku.com:fierce-samurai-6972.git


4) Make some changes, push them to heroku : 


git push heroku master

5) Don’t forget to sync your changes with github so you don’t lose your work on github !

git push (or ‘git push origin master’, or ‘git push github master’) 


Some helpful commands 
To see all the apps you’ve created :
jaylinux@ubuntu:~/Development/$ heroku apps

quiet-warrior-557
fierce-samurai-6972
gentle-ice-2166
falling-autumn-9592
simple-rain-5194

To see all the details for an app you’re working on : 

jaylinux@ubuntu:~/Development/rudolfblog$ heroku info –app fierce-samurai-6972
=== fierce-samurai-6972
Addons:        Shared Database 5MB
Collaborators: mfenwick100@gmail.com
               sesanker0@gmail.com
Domain Name:   fierce-samurai-6972.heroku.com
Dynos:         1
Git URL:       git@heroku.com:fierce-samurai-6972.git
Owner:         jayunit100@gmail.com
Repo Size:     500k
Slug Size:     1M
Stack:         bamboo-mri-1.9.2
Web URL:       http://fierce-samurai-6972.heroku.com/
Workers:       0

BLOG

  • 06 Dec 2020
    Looking back at 2020 – with g...

    2020 has not been a year we would have been able to predict. With a worldwide pandemic and lives thrown out of gear, as we head into 2021, we are thankful that our community and project continued to receive new developers, users and make small gains. For that and a...

    Read more
  • 27 Apr 2020
    Update from the team

    It has been a while since we provided an update to the Gluster community. Across the world various nations, states and localities have put together sets of guidelines around shelter-in-place and quarantine. We request our community members to stay safe, to care for their loved ones, to continue to be...

    Read more
  • 03 Feb 2020
    Building a longer term focus for Gl...

    The initial rounds of conversation around the planning of content for release 8 has helped the project identify one key thing – the need to stagger out features and enhancements over multiple releases. Thus, while release 8 is unlikely to be feature heavy as previous releases, it will be the...

    Read more