Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Supporting pub on heroku #6

merged 1 commit into from

5 participants


This pull request adds support for pub in the build process of Heroku.

As pub installs packages into the $HOME directory by default and since the $HOME folder in the build environment differs from the one in runtime, dart apps relying on pub would not work.

The packages need to be installed inside an separate folder in the cache folder and following the installation, the packages need to be copied to the build folder, maintaining the folder structure.

Additionally, in order to include and use packages residing within the dart-sdk, the whole dart-sdk folder needs to be moved into the build folder and pub needs to be called from that folder structure e.g. /app/dart-sdk/bin/pub install to maintain a correct symlink to the packages.

Custom build versions
Also included in this pull request is the ability to set an environmental variable called BUILD which takes a revision number from

This comes in handy when using libraries that are not working with the latest sdk version.

For more information, please feel free to contact me.

I hope this makes it easier for users to use dart on Heroku.



Holy commit batman! :)

Can you please squash the commits? Don't need the debug history...


@kohlikohl before sending pull requests, git rebase -i is your friend :-)

Matthias Knoll adding pub support to heroku buildpack
Signed-off-by: Matthias Knoll <>

@igrigorik @kevmoo Sorry guys, its als nice and shiny now.




Nice, thanks @kohlikohl - lgtm!

@sethladd.. quick sanity check?


Just tested this out, worked great for me.

@kohlikohl I'd suggest updating the test_app to include something from the dart sdk (logging, unittest, args) to show off the support for pub. Even better would be an updated test_app that uses some of the pub layout.

Great job!

@igrigorik igrigorik merged commit 7cdbbe2 into igrigorik:master


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 19, 2012
  1. adding pub support to heroku buildpack

    Matthias Knoll authored
    Signed-off-by: Matthias Knoll <>
This page is out of date. Refresh to see the latest.
Showing with 67 additions and 12 deletions.
  1. +23 −1
  2. +43 −10 bin/compile
  3. +1 −1  test-app/Procfile
@@ -2,6 +2,8 @@
This is a Heroku buildpack for [Dart](
+Installation of packages through [pub]( is supported.
## Getting Started
@@ -15,7 +17,12 @@ $> git push heroku master
-----> Heroku receiving push
-----> Fetching custom buildpack... done
-----> Dart app detected
------> Installing latest Dart VM
+-----> Installing Dart VM, build: latest
+-----> Copy Dart binaries to app root
+-----> Install packages
-----> Discovering process types
Procfile declares types -> web
-----> Compiled slug size is 10.5MB
@@ -24,6 +31,21 @@ $> git push heroku master
$> curl
+## Configuration
+You can specify the version of the dart-sdk that should be used by
+$> heroku config:set BUILD=<version number>
+A list of versions can be found [here](
+In order for the build version to come through in to the build pack you also need to set an experimental flag on Heroku
+$> heroku labs:enable user-env-compile
+More info on that can be found in [Heroku's Devcenter: Heroku Labs: user-env-compile](
See `test-app` directory for the world simplest Dart web app running on Heroku: [](
## License
53 bin/compile
@@ -10,21 +10,54 @@ mkdir -p "$1" "$2"
BUILD_DIR=$(cd "$1/" && pwd)
CACHE_DIR=$(cd "$2/" && pwd)
+# the directory in which the packages will be stored
+# this variable is used by pub to determine the package install location
+export PUB_CACHE
function message {
echo "$1"
+# if no build number is set, download latest
+if [ -z "$BUILD" ]; then
+ BUILD="latest"
+mkdir -p $PACKAGES_DIR
+message "-----> Installing Dart VM, build: $BUILD"
+curl -L $DART_SDK_URL -s -o - | tar xzf -
+message "-----> Copy Dart binaries to app root"
+cp -r $CACHE_DIR/dart-sdk $BUILD_DIR
+# we need to copy the sdk into the /app folder in order for the sdk libraries to be referenced correctly
+# reason being that the /tmp folder will be deleted after build, and /app resembles the location of the ready built app
+cp -r $CACHE_DIR/dart-sdk /app
+message "-----> Install packages"
+#start pub from the /app folder to have correct symlink paths
+/app/dart-sdk/bin/pub install
-#if [ ! -e "$CACHE_DIR/dart" ]; then
- message "-----> Installing latest Dart VM"
+# move packages from cache directory into build directory
- curl -L $DART_SDK_URL -s -o - | tar xzf -
-# message "-----> Using cached Dart VM"
-mkdir -p $BUILD_DIR/bin
-cp $CACHE_DIR/dart-sdk/bin/dart $BUILD_DIR/bin/dart
2  test-app/Procfile
@@ -1 +1 @@
-web: dart main.dart
+web: ./dart-sdk/bin/dart main.dart
Something went wrong with that request. Please try again.