Heroku and Play Next Week in Chicago and New York

Next week I’ll be in Chicago and New York for a few presentation about Heroku, Play Framework, and running Java apps on the cloud.

Hope to see you there!

Run Revel Apps on Heroku

UPDATE: There have been some updates to my Revel Heroku Buildpack that make it work better and with newer versions of Revel. Check out the details.

Revel is a Play-like web framework for Go. I’m new to the Go programming language but I’ve heard good things. So I thought I’d take Revel for a spin and get it working on Heroku. Luckily there is already a Go Buildpack and a great article on how to use it.

To get Revel working on Heroku I had to make a few changes to Revel and create a modified buildpack. But it all works! Lets walk through the steps you can follow to deploy Revel apps on Heroku.

First lets get a simple Revel app working locally.
Step 1) Install Go
Step 2) Install Mercurial
Step 3) Install Git
Step 4) Create a new directory that will contain everything:

mkdir ~/go

Step 5) This new “go” directory will be your “GOPATH” so set that environment variable:

export GOPATH=~/go

Step 6) In the newly created “go” directory, get the original Revel source and my changes:

go get github.com/robfig/revel
go get github.com/jamesward/revel

Step 7) Build the “revel” command:

go build -o bin/revel github.com/jamesward/revel/cmd

Step 8) Grab my “hellorevel” sample app:

go get github.com/jamesward/hellorevel

Step 9) Start the local Revel server:

bin/revel run github.com/jamesward/hellorevel

Step 10) In your browser navigate to: http://localhost:9000

You should see a “hello, Revel” message. Lets walk through this simple app so you can get an idea of how it works.

The request you just made is mapped to code through the “conf/routes” file which contains:

# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
GET     /                                       Application.Index

This tells Revel to handle HTTP GET requests to “/” with the “Application.Index” controller.

The “Application.Index” function is defined in the “app/controllers/app.go” file and contains:

package controllers
import (
type Application struct {
func (c Application) Index() rev.Result {
    message := "hello, Revel"
    return c.Render(message)

The “Index()” function creates a “message” string of “hello, Revel” and then returns the rendered template which received the “message” as a parameter.

The “app/views/Application/Index.html” template is used to get the HTML for the “Application.Index()” controller and contains:

<!DOCTYPE html>

This uses Go templates and uses the “message” parameter.

Feel free to make changes to the template and controller to see how Revel auto-recompiles the source.

Ok, now that you have the application running locally, lets deploy it on Heroku.

Step 1) Signup for a free Heroku account
Step 2) Install the Heroku Toolbelt
Step 3) Login to Heroku from the command line (this should also setup your SSH keys if you haven’t done so already):

heroku login

Step 4) Enter the directory for the “hellorevel” app and create a new application on Heroku which will use the Revel Buildpack:

cd ~/go/src/github.com/jamesward/hellorevel
heroku create --buildpack https://github.com/jamesward/heroku-buildpack-go-revel.git

Step 5) Upload the app to Heroku using Git:

git push heroku master

This will upload the application source, pull in all of the dependencies, and then deploy the application on Heroku. That process will look something like this:

jamesw@T420s:~/go/src/github.com/jamesward/hellorevel$ git push heroku master
Counting objects: 25, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (19/19), done.
Writing objects: 100% (25/25), 2.46 KiB, done.
Total 25 (delta 2), reused 0 (delta 0)
-----> Heroku receiving push
-----> Fetching custom git buildpack... done
-----> Revel app detected
-----> Installing Go 1.0.3... done
       Installing Virtualenv...running virtualenv done
       Installing Mercurial... done
-----> Copying src to .go/src/pkg/_app
-----> Getting and building Revel
-----> Discovering process types
       Procfile declares types -> (none)
       Default types for Revel -> web
-----> Compiled slug size: 31.0MB
-----> Launching... done, v4
       http://polar-cove-5542.herokuapp.com deployed to Heroku
To git@heroku.com:polar-cove-5542.git
 * [new branch]      master -> master

Step 6) Check out your Revel app on the cloud by running:

heroku open

That’s it! Deployment of Revel apps couldn’t be easier! Let me know if you have any questions or feedback on this. Thanks!

Heroku & Play Framework at JavaOne 2012

This year at JavaOne I’ll be presenting two session and participating in one BOF:

BOF4149 – Web Framework Smackdown 2012 – Monday @ 8:30pm

Much has changed since the first Web framework smackdown, at JavaOne 2005. Or has it? The 2012 edition of this popular panel discussion surveys the current landscape of Web UI frameworks for the Java platform. The 2005 edition featured JSF, Webwork, Struts, Tapestry, and Wicket. The 2012 edition features representatives of the current crop of frameworks, with a special emphasis on frameworks that leverage HTML5 and thin-server architecture. Java Champion Markus Eisele leads the lively discussion with panelists James Ward (Play), Graeme Rocher (Grails), Edward Burns (JSF) and Santiago Pericasgeertsen (Avatar).

CON3845 – Introduction to the Play Framework – Tuesday @ 8:30am

The Play Framework is a lightweight, stateless Web framework for Java and Scala applications. It’s built on Java NIO, so it’s highly scalable. This session gives you an introduction to building Web applications with the Play Framework. You will learn how to set up routes and create controllers and views, plus how to deploy Play Framework applications in the cloud.

CON3842 – Client/Server Applications with HTML5 and Java – Thursday @ 11am

The Web application landscape is rapidly shifting back to a client/server architecture. This time around, the client is JavaScript, HTML, and Cascading Style Sheets in the browser. The tools and deployment techniques for these types of applications are abundant and fragmented. This session shows you how to pull together jQuery, LESS, and Twitter Bootstrap to build the client. The server can be anything that talks HTTP, but this session uses JAX-RS. You will also learn how to deploy client/server Web applications in the cloud with a content delivery network (CDN) for the client and a PaaS for the server.

I hope to see you there!

Atlanta Presentation: Practicing Continuous Delivery

Tomorrow I’ll be presenting Practicing Continuous Delivery on the Cloud at the Atlanta No Fluff Just Stuff conference. Here is the session description:

This session will teach you best practices and patterns for doing Continuous Delivery / Continuous Deployment in Cloud environments. You will learn how to handle schema migrations, maintain dev/prod parity, manage configuration and scaling. This session will use Heroku as an example platform but the patterns could be implemented anywhere.

This has become my favorite sessions to present. So if you are going to be at Atlanta NFJS, then I hope to see you there!

Heroku at JavaZone 2012

I’m really looking forward to being back at JavaZone in Oslo this September! I’ll be speaking about Running Java, Play! and Scala Apps on the Cloud. This session will teach you how to get started deploying Java and Scala apps on Heroku. I’ll be around for the whole conference, so if anyone wants to grab a drink, deploy some apps, or write some code with me, then let me know. See you there!

Dreamforce 2012: Java Apps on Heroku & Force.com

Dreamforce 2012 is going to be a fantastic event! And not just because Red Hot Chili Peppers, Colin Powell, and Richard Branson will be there. I’ll also be there talking about Building Java Apps on Heroku and Force.com. Here is the description for my session:

In this session you will learn how to build Social Enterprise applications using Salesforce, Heroku, and Java. Through live coding and demonstrations you will learn how to instantly deploy and scale Java apps on the cloud with Heroku. You will also learn how to integrate those applications with Salesforce and Force.com through REST.

Sounds pretty exciting when put next the celebrities, right? Hope to see you there!

Getting Started with Clojure on Heroku

Last week I introduced the Den of Clojure to Heroku. I really enjoyed learning more about Clojure and experiencing super simple Clojure deployment on Heroku. For those who haven’t yet deployed Clojure on Heroku, lets walk through 8 quick steps to get you started:

  1. Install the Heroku Toolbelt and Leiningen
  2. Login to Heroku from the command line:
    heroku login

    If this is your first time logging into Heroku from the command line then you will be led through some steps to associate an SSH key with your Heroku account.

  3. Create a new Leiningen build definition by creating a file named project.clj containing:
    (defproject hello-clojure-noir "0.1.0-SNAPSHOT"
      :main web
      :dependencies [[org.clojure/clojure "1.4.0"]
                     [noir "1.2.1"]])

    As you can see from the dependencies, this simple app uses the Noir web framework.

  4. Create a simple Noir app by creating a file named src/web.clj containing:
    (ns web
      (:use noir.core)
      (:require [noir.server :as server]))
    (defpage "/" [] "hello, world")
    (server/start (Integer/parseInt (or (System/getenv "PORT") "8080")))

    This very basic web app returns “hello, world” for requests to “/”. It starts the server using either the port defined by an environment variable named “PORT” or a default of 8080.

  5. Test this app locally by running:
    lein run

    Then visit http://localhost:8080 in your browser and verify that you see “hello, world”.

  6. To upload this application to Heroku you will first need to create a Git repository, add the files to it, and commit them:
    git init
    git add project.clj src
    git commit -m init
  7. Now create a new application on Heroku:
    heroku create

    This creates an HTTP and a Git endpoint for your application. The Git endpoint will be added to your Git configuration as a “remote” named “heroku”.

  8. Upload your Git repository to the Git repository for your application on Heroku:
    git push heroku master

    This will kick off the Leiningen build process on Heroku. The build will download the dependencies for the app then compile the app and put everything into a “slug” that will be deployed onto a Dyno. Once the process is complete you can open the HTTP endpoint for your app in your browser:

    heroku open

    You should now see “hello, world” coming from the Cloud!

The source for this example is on GitHub.

To learn more about Clojure on Heroku, check out the Heroku Dev Center. Let me know how it goes!