Skip to content

Step 13 deploy to heroku

opensas edited this page Sep 20, 2011 · 21 revisions

Step 13 - deploy to heroku

Purpose: in this step we will see how to deploy you app to heroku's cloud computing platform.

cd ~/devel/apps
git clone git@github.com:opensas/play-demo.git
git checkout origin/13-deploy_to_heroku

Creating an account at heroku

Creating an account at heroku is really easy. Go to Heroku homepage and click on signup to create a new account and then enter a valid email address.

setup heroku command line tools

follow these instructions to add heroku tools on linux.

On ubuntu, execute the following command to add heroku's repository

sudo apt-add-repository 'deb http://toolbelt.herokuapp.com/ubuntu ./'
curl http://toolbelt.herokuapp.com/apt/release.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install heroku-toolbelt

You might have to install curl first

sudo apt-get install curl

Now check that the client was successfully installed

heroku version
heroku-gem/2.8.0

heroku update
-----> Updating to latest client... done

authenticate with heroku

At the command line, issue the following commands

heroku login
Enter your Heroku credentials.
Email: open@gmail.com
Password:

Here you have to enter your heroku password, do not confuse it with you private key password.

If you don't have any private/public key in ~/.ssh, it will create a new pair of keys

Could not find an existing public key.
Would you like to generate one? [Yn] Y
Generating new SSH public key.
Uploading ssh public key /home/sas/.ssh/id_rsa.pub

prepare your app for heroku - initialize the git repo

In order to work with heroku, first you have to create a git file.

You will have to install git on you development station. In ubuntu is as easy as sudo apt-get install git. Have a look at github documentation for linux and windows instructions.

First of all, make sure you are at the root of your application. Then create a .gitignore file. Here you have a handy play .gitignore template

.gitignore

# Extracted from https://github.com/ulrich/macaron-factory/blob/master/.gitignore
# Ignore all dotfiles...
.*
# except for .gitignore
!.gitignore

# Ignore Play! working directory #
db
eclipse
log
logs
precompiled
tmp
test-result
eclipse
server.pid

Now run the app in production mode to test it

play run --%production

And then create the git repo and issue an initial commit

git init
git add .
git commit -m init
[master (root-commit) 93e6f9d] init
 16 files changed, 391 insertions(+), 0 deletions(-)
 create mode 100644 .gitignore
 create mode 100644 app/controllers/Application.java
 create mode 100644 app/views/Application/index.html
 create mode 100644 app/views/errors/404.html
 create mode 100644 app/views/errors/500.html
 create mode 100644 app/views/main.html
 create mode 100644 conf/application.conf
 create mode 100644 conf/dependencies.yml
 create mode 100644 conf/messages
 create mode 100644 conf/routes
 create mode 100644 public/images/favicon.png
 create mode 100644 public/javascripts/jquery-1.5.2.min.js
 create mode 100644 public/stylesheets/main.css
 create mode 100644 test/Application.test.html
 create mode 100644 test/ApplicationTest.java
 create mode 100644 test/BasicTest.java
 create mode 100644 test/data.yml

Create a new app on Heroku:

Now we'll create the new app on heroku

heroku create -s cedar
Creating afternoon-dusk-4670... done, stack is cedar
http://afternoon-dusk-4670.herokuapp.com/ | git@heroku.com:afternoon-dusk-4670.git
Git remote heroku added

Heroku will automatically pick a name for you application in this case it was afternoon-dusk-4670.

And will issue our initial deploy:

git push heroku master

That's it! A deploy to heroku is just a git push away...

When pushing to git, you'll have to enter you password to the private key created in ~/.ssh, do not confuse with your heroku key.

Always before deploying you have to commit your changes on the master branch

Now you can point your browser to http://afternoon-dusk-4670.herokuapp.com or just issue heroku open to let heroku do that for you.

Changing the application name

It's highly probable that you won't like afternoon-dusk-4670, so navigate to https://api.heroku.com/myapps, click on afternoon-dusk-4670, and change it's name to play-demo-test. The following message will appear:

afternoon-dusk-4670 renamed to play-demo-test.
Existing git checkouts must be updated.

Follow these instructions:

git remote rm heroku
git remote add heroku git@heroku.com:play-demo-test.git

Now you can check you app at http://play-demo-test.herokuapp.com

Trouble shooting heroku

We'll have to make a couple of changes so that our app con work flawlessly on heroku. For that purpose we'll first see a few commands that will let us deal with heroku.

heroku info
=== play-demo-test
Web URL:        http://play-demo-test.herokuapp.com/
Git Repo:       git@heroku.com:play-demo-test.git
Dynos:          0
Workers:        0
Repo size:      42M
Slug size:      26M
Stack:          cedar
Data size:      (empty)
Addons:         Basic Logging, Basic Release Management, Shared Database 5MB
Owner:          opensas@gmail.com

More info at

http://devcenter.heroku.com/articles/play

http://toolbelt.herokuapp.com/linux/readme

http://www.jamesward.com/2011/08/29/getting-started-with-play-framework-on-heroku


Now we are going to Step 14 - deploy to gae.