Thursday, November 29, 2012

Go for Dart on Heroku

‹prev | My Chain | next›

I had originally intended to keep working through Dart for Hipsters errata today, but… Ooh! Shiny!

Today's shiny object distracting me from doing the right thing is the Heroku Buildpack for Dart. The new support for The Pub is what really caught my eye. With my Dart Comics sample app running on the server with a pub dependency, how am I expected to resist? Really, I am not that strong a person.

I start by installing the Ruby gem for heroku. I know there's the toolbelt and all, but I loathe installing system packages and, oddly, I do not have access to a VM at the moment. So I add heroku to my Gemfile:
source 'http://rubygems.org'

group :deployment do
  gem 'heroku'
end

group :development do
  gem 'guard'
  gem 'guard-shell'
end
And do a bundle install:
➜  dart-comics git:(master) ✗ bundle install
Fetching gem metadata from http://rubygems.org/...........
...
Installing heroku (2.33.2)
Using bundler (1.1.4)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
Post-install message from heroku:
 !    The `heroku` gem has been deprecated and replaced with the Heroku Toolbelt.
 !    Download and install from: https://toolbelt.heroku.com
 !    For API access, see: https://github.com/heroku/heroku.rb
Yeah, yeah, yeah. Deprecated. Got it.

Next, I add my application to heroku:
➜  dart-comics git:(master) ✗ heroku create dart-comics
Creating dart-comics... done, stack is cedar
http://dart-comics.herokuapp.com/ | git@heroku.com:dart-comics.git
Git remote heroku added
Following along with the instructions for the Dart buildpack, I configure heroku for Dart:
➜  dart-comics git:(master) ✗ heroku config:add BUILDPACK_URL=https://github.com/igrigorik/heroku-buildpack-dart.git
Setting config vars and restarting dart-comics... done, v3
BUILDPACK_URL: https://github.com/igrigorik/heroku-buildpack-dart.git
And I push my application:
➜  dart-comics git:(master) ✗ git push heroku master
...

-----> Heroku receiving push  
-----> Fetching custom git buildpack... done
-----> Dart app detected
-----> Installing Dart VM, build: latest
-----> Copy Dart binaries to app root
-----> Install packages
Resolving dependencies...
Downloading dirty 0.0.1...
Downloading uuid 0.0.8...
Dependencies installed!
-----> Discovering process types
       Procfile declares types -> (none)
-----> Compiled slug size: 6.2MB
-----> Launching... done, v5  
       http://dart-comics.herokuapp.com deployed to Heroku

To git@heroku.com:dart-comics.git
 * [new branch]      master -> master
The coolest bit in there is that my pubspec.yaml dependencies have, indeed been found and installed (dart-dirty and dart-uuid). I do see that omitted my procfile, which means that my web application has not been started. So I add the following Procfile:
web: ./dart-sdk/bin/dart app.dart
I grabbed the path to dart from the buildpack sample and the app.dart is the location of my server. With that, I redeploy:
➜  dart-comics git:(master) ✗ git push heroku master
...
-----> Heroku receiving push  
-----> Fetching custom git buildpack... done
-----> Dart app detected
-----> Installing Dart VM, build: latest
-----> Copy Dart binaries to app root
-----> Install packages
Resolving dependencies...
Dependencies installed!
-----> Discovering process types
       Procfile declares types -> web
-----> Compiled slug size: 6.2MB
-----> Launching... done, v6
       http://dart-comics.herokuapp.com deployed to Heroku
That looks better. Except that when I try to access the site, I am greeted with the Heroku error page.

Eventually, I realize that I am always listening to port 8000, so I alter the code to check the environment variable:
import 'dart:io';
import 'dart:json';

import 'package:dirty/dirty.dart';
import 'package:uuid/uuid.dart';

main() {
  HttpServer app = new HttpServer();
  // ...

  print("Starting on ${Platform.environment['PORT']}");
  var port = Platform.environment['PORT'] == null ? 8000 : int.parse(Platform.environment['PORT']);
  app.listen('0.0.0.0', port);
  print('Server started on port: ${port}');
}
But I still have no luck. What's weird is that I can manually run the web server:
➜  dart-comics git:(master) ✗ heroku run ./dart-sdk/bin/dart app.dart
Running `./dart-sdk/bin/dart app.dart` attached to terminal... up, run.8359
Starting on 59017
Server started on port: 5901
But the same command in the Profile fails. And the logs are of no help. All they tell me is that the server process is not running:
2012-11-30T04:55:24+00:00 heroku[api]: Release v10 created by heroku@eeecomputes.com
2012-11-30T04:55:24+00:00 heroku[api]: Deploy a49850f by heroku@eeecomputes.com
2012-11-30T04:55:55+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path=/
Frustrated, I call it a night here. Hopefully I can figure out what I am doing wrong in the morning.

Update: Figured it out. Needed to add a dyno from the command line:
➜  dart-comics git:(master) ✗ heroku ps:scale web=1
Scaling web processes... done, now running 1
With that, I have my web process:
➜  dart-comics git:(master) ✗ heroku ps            
=== web: `./dart-sdk/bin/dart app.dart`
web.1: up 2012/11/30 00:11:32 (~ 9s ago)

Day #584

No comments:

Post a Comment