Follow posts tagged #heroku in seconds.
Sign upHeroku versus Cloud Foundry from an Educator's Perspective
There are several useful comparisons between Heroku and Cloud Foundry, including this one and that one. I am going to add a brief educator’s perspective.
Why APaaS in the first place? To have a common reference platform for students to deploy to from day one. This eliminates the common last-minute deployment problems.
My specific requirement is to support the technology stacks I have chosen for pedagogical reasons for my web application and web services courses. (In both courses, we pay considerable attention to architecture.)
- Scala
- Play framework for web apps
- spray for RESTful web services
As a platform, Cloud Foundry is open-source, while Heroku is closed-source. Fair enough. But what are the relevant differences from my perspective?
- With Heroku, your application needs to have a main class as its entry point. You structure your application using Foreman and push the source to the cloud using git. Building, staging, and deployment then take place again in the cloud. If these steps work on your local machine using, say, Maven or sbt, they are very likely to work the same way on Heroku.
- With Cloud Foundry, your application must be packaged as a war to run on Tomcat 6, in the case of Java or Scala. The build process takes places on the local machine, you push a war to the cloud, and this hard-coded server staging logic is invoked. The problem is that you are stuck with the default blocking Java connector! Because spray requires the non-blocking (async) connector, this means that you cannot deploy spray to CloudFoundry.com for now. If you know a workaround, please let me know!
- Both have various useful add-ons, such as relational and NoSQL databases, message queues, etc.
- Heroku has a free tier, while Cloud Foundry has a free trial and it’s final pricing structure has not been announced yet.
For these reasons, I ended up choosing Heroku for this spring semester. I’m quite optimistic that it’s going to be fun.
SuperHeroku - Android Market
market.android.comAn application that my friend and I made. If you use Heroku, you must check this out
Flask, Backbone and Heroku
![]()
http://furious-leaf-5120.herokuapp.com/
Practice makes perfect. I should do more exercises like this.
Source code here: https://github.com/marksteve/bookmarks
Ruby on Rails 3.1, PostgreSQL and Heroku
My entire afternoon was devoted to using a postgresql database instead of a sqlite one on my sample app (from Rails 3 tutorial). I *must* write how the fuck you do this, it’s shamelessly hard for someone unaccustomed with DB handling. Installing it using MacPorts is pretty straightforward, but there are some necessary terminal incantations, it’s not just “sudo port install postgresql83”.
I did find (and, maybe, understand) how to properly put an app on heroku.com. With rails3, this is painful because of the assets pipeline - you need to tweak some configurations and I also needed to downgrade sprockets (2.0.2).
The almost-finished sample app is hosted under strong-wind-7904.herokuapp.com.
Errors uploading images from ASIHTTPRequest in iPhone to Rails 3 application hosted on Heroku
We just went through a painful debug session related to erratic timeouts and "Bad content body" errors when we try to upload images from an iPhone application to Rails 3 application hosted on Heroku.
The iPhone application uses ASIHTTPRequest, checking the Google Groups we found that the issues are related to Persistent Connections, the solution that worked for us was:
[request setShouldAttemptPersistentConnection:NO];
Instructions for migrating from shared database to dedicated database on Heroku
Before you start the migration please be aware of these facts:
- Heroku doesn’t migrate the data from the shared database to the dedicated database automatically.
- Heroku doesn’t assign the dedicated database as the primary database automatically.
- Heroku doesn’t remove the shared database even after you complete the migration. You have to remove it manually. Otherwise you will continue to incur charges(if any) for the shared database.
Instructions
Add the dedicated database to your application:
$ heroku addons:add heroku-postgresql:ronin -----> Adding heroku-postgresql to sushi... done, v69 ($200/mo) Attached as HEROKU_POSTGRESQL_RED -----> The database should be available in 5-15 minutes Use `heroku pg:wait` to track statusTrack the progress of the database creation:
$ heroku pg:wait Waiting for database HEROKU_POSTGRESQL_RED... doneGet the connection credentials of the newly created database
$ heroku pg:info === HEROKU_POSTGRESQL_BLACK Plan Ronin Status available Data Size 5.1 MB Tables 0 PG Version 9.0.5 Created 2011-10-10 17:59 UTC Conn Info "host=ec2-107-22-255-345.compute-1.amazonaws.com port=5432 dbname=dk2sf5va7dsalklkdsj3rd user=uy5gymvzvyast6ee sslmode=require password=pssajjhjhfa2yzx1q8g48dp1mo3a"VS1: Verification step 1: Note down the count of users in the current database
$ heroku console >> User.count => 1024 >> exitEnable the mainenance mode. This will prevent any further changes to the shared database.
$ heroku maintenance:onCreate a backup of the shared database. Note down the backup id.
$ heroku pgbackups:capture --expire SHARED_DATABASE (DATABASE_URL) ----backup---> b136 ?[0KCapturing... doneB - ?[0KStoring... doneVS2: Verification step 2: Check the count of users in the dedicated database. The database will throw an error in this step.
$ psql "host=ec2-107-22-255-345.compute-1.amazonaws.com port=5432 dbname=dk2sf5va7dsalklkdsj3rd user=uy5gymvzvyast6ee sslmode=require password=pssajjhjhfa2yzx1q8g48dp1mo3a" => select count(*) from users; ERROR: relation "users" does not exist LINE 1: select count(*) from users; => \qSeed the dedicated database from the the backup
$ heroku pgbackups:restore HEROKU_POSTGRESQL_RED b136 --confirm ?[0KRetrieving... donet | ?[0KRestoring... doneB \-VS3: Verification step 3: Count of users in the dedicated database should match the count returned in the step VS1
$ psql "host=ec2-107-22-255-345.compute-1.amazonaws.com port=5432 dbname=dk2sf5va7dsalklkdsj3rd user=uy5gymvzvyast6ee sslmode=require password=pssajjhjhfa2yzx1q8g48dp1mo3a" => select count(*) from users; count ------- 1024 (1 row) => \qMake the dedicated database as the primary database for your application
heroku pg:promote HEROKU_POSTGRESQL_REDVS4: Verification step 4: Count of users in the heroku console should match the count returned in step VS1
$ heroku console >> User.count => 1024 >> exitActivate the application
heroku maintenance:off --account thinkspeedDeactivate the paid shared database plan
Setting up a custom sub-domain for the staging environment on Heroku
Let us say you have configured a custom domain; http://www.foobar.com; for the production environment of your application on Heroku.
You followed the instructions here to create a staging environment. Now, you want to expose the staging environment on http://staging.foobar.com.
I had a similar problem today, and I didn’t find any step by step instructions for addressing the problem.
Pre-requisites
- Production and staging Heroku environments are called foobar-production and foobar-staging. Both environments have custom_domains add-on
- The foobar-production environment has the Zerigo add-on. The A(foobar.com) and CNAME(www.foobar.com) records are configured using Zerigo add-on
Add the staging sub domain to point to the staging environment
$ heroku domains:add staging.foobar.com --app foobar-staging
Configure the Zerigo add-on to point to the staging environment.
Clone the CNAME record for www.foobar.com. The record points to proxy.heroku.com. Change the sub-domain name to staging.
Wait for 10 minutes for the changes to propagate. Access the staging environment using http://staging.foobar.com.
Deploying to Heroku
App made, now it’s time to deploy. It’s easy once both git and heroku as well as a new app (via `heroku create`) are setup on the system. CD to the app directory and do in order:
git add .
git commit -m "message goes here"
git push heroku master
Then it’s time to prepare the database so I run:
heroku run rake db:migrate
This actually gives me a strange error:
rake aborted!
bad URI(is not URI?):
However, running `heroku logs` reveals:
/Users/grinch/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/net/http.rb:644:in `initialize': getaddrinfo: nodename nor servname provided, or not known (SocketError)
Well, that’s pretty obvious, I haven’t added the Redistogo add-on in this application’s deployment. Let’s do that quick with:
heroku addons:add redistogo:nano
Done! Let’s test it up by firing up `heroku run console` and popping in:
REDIS.set("answer", 42)
It responds with “ok” - we’re in business. When trying to migrate the database again, it works great. I try accessing the app’s URL and it’s live! Deploying Rails 3.1.0 to Heroku

I just finished setting up Ruby on Rails 3.1.0 on Heroku and wanted to share some small tips.
Heroku CedarI’ll cut right to the chase. When you deploy Ruby on Rails to Heroku, you’ll want to specify the Cedar stack. If you try and deploy to Heroku normally, you’ll get an error. To specify a stack, simply do it as follows (this should look relatively familiar if you’ve deployed to Heroku before)
heroku create --stack cedar
Oh my, so easy? Yeah.
Asset PipelineThis is a bit trickier. Honestly, I didn’t follow this guide at all, but I’ll refer you here because certainly they know more than I do and will likely keep it more updated than this post. Asset Pipeline Rails 3.1.0 on Heroku
SSH and different accounts in Heroku
In Heroku, if you have two different user accounts, you’ll need to use two different ssh keys to access applications in each account. The following commands can be used to switch between ssh keys quickly.
Check your currently loaded keys:
ssh-add -L
Remove that key from the agent with:
ssh-add -d <optional_key_file>
Add a new key (the one with your_new_email_address):
ssh-add /path/to/your/private/key/file
Another link related to this I found today (23/11/2011)
Heroku Scheduler を試す
heroku の Cron Add-on は Daily のみ無料で、Hourly にすると $3/月 の料金が掛かった。ところが、新たな Add-on である Heroku Scheduler がリリースされた。これは Every 10 minutes / Hourly / Daily が選択できる。しかも無料だ。これは試すしかあるまいと思い、Amazon の価格調査をするアプリを書くことにした。
ドキュメント には、Rake タスクや Ruby スクリプトを実行する例が載っている。なので、Rake タスクを書くことにした。内容は下記の通り。
# -*- coding: utf-8 -*-
require 'httpclient'
base_uri = 'https://xxxx-xxxx-9999.heroku.com'
desc "This task is called by the Heroku scheduler add-on"
task :update_price do
puts "Updating price..."
client = HTTPClient.new
client.set_auth("#{base_uri}/amazon/update_price", 'xxxxx', 'xxxxxxxx')
res = client.get("#{base_uri}/amazon/update_price")
puts res.status
puts "done."
end
URL を叩くだけのものになっている。Basic 認証を掛けているので、httpclient を使っている。取り敢えず動くようにはなったが、色々手直しが必要に思う。本体と合わせて直そうと思う。
Save Everything, Use RMSN
Hooray! I just released the Reading Message Server (RMSN). You put two and two and two together, I’m sure. But for clarity, it’s:
- A real time notifications server
- Built to power Reading.am
- As a drop in replacement for Pusher
- Named after the fantastic Shipping News
The rest is best read here: https://github.com/leppert/RMSN
Stationwagon + Rails
stationwagon.heroku.comI decided to write Stationwagon in Rails as part of my learning process. I used Devise for authentication and deployed the app with Heroku.