Skip to content

Instantly share code, notes, and snippets.

@jamesward
Created October 18, 2012 05:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesward/3910085 to your computer and use it in GitHub Desktop.
Save jamesward/3910085 to your computer and use it in GitHub Desktop.
NY Java SIG

Heroku Basics

Heroku is a Cloud Application Platform

  • Supports Java, Scala, Python, Node.js, Ruby, etc
  • Instant Deployment via Git or WAR files
  • Instant Scalability
  • Managed Infrastructure: Servers, Load Balancers, Databases, etc
  • Extended via Add-ons: http://addons.heroku.com

Heroku Basics

Deployment

  1. Copy git repo to Heroku:

     git push heroku master
    
  2. Heroku compiles code

  3. Heroku creates a "slug" file

  4. Heroku deploys "slug" onto a "dyno"

  5. Heroku starts the process

Terminology

http://heroku.com/how

User has 0 or more Applications

Application has 1 git repository

Application has 0 or more Processes

Process is defined in a Procfile

Process named "web" can listen on one port for HTTP

Process runs on 0 or more Dynos

Dynos are isolated (LXC) and managed execution environments

Application has 0 more more external resources - Heroku Add-ons

Buildpack receives a git push and produces a "slug"

Slug contains the non-system dependencies for all Processes

Dynos are ephemeral and stateless

HTTP(s) requests are randomly routed to the "web" Dynos

Pricing

http://www.heroku.com/pricing

$0.05 / dyno hour

750 free dyno hours per application per month

Deploy An App

  1. In Eclipse select File > New > Other...
  2. Expand the Heroku section, select Create Heroku App from Template, select Next
  3. Select Spring MVC & Tomcat application, select Finish

Open the App

  1. In Eclipse select Window > Show View > Other...
  2. Expand the Heroku section, select My Heroku Applications, select Ok
  3. Locate the newly created application in My Heroku Applications
  4. Right-click on the application and select Open

Run the App Locally

  1. In Eclipse select Run > Run Configurations...
  2. Double-click on Java Application
  3. Set the name to something like arcane-taiga-7336 webapp-runner (using the application's name)
  4. Set the Main class to webapp.runner.launch.Main
  5. In the Arguments tab add src/main/webapp as a Program argument
  6. Select Run
  7. Visit http://localhost:8080

About the App

  • BYOC via pom.xml
  • Define processes via the Procfile
  • Database configured via the DATABASE_URL environment variable

Deploy Changes

  1. Make a change to the application and test locally
  2. In Eclipse right-click on the project name in the Project Explorer
  3. Select Team > Commit...
  4. Enter a Commit message
  5. Select Commit
  6. Right-click on the project name in the Project Explorer
  7. Select Team > Push to Upstream
  8. View the application on Heroku in your browser

View Logs

  1. In Eclipse select the My Heroku Applications tab
  2. Right-click on the application and select View logs

Scale the App

This requires a verified account on Heroku: http://heroku.com/verify

  1. In Eclipse select the My Heroku Applications tab
  2. Right-click on the application and select Scale
  3. Enter the number of Dynos to scale the web process to
  4. Select Ok
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment